本文整理汇总了PHP中CMap::length方法的典型用法代码示例。如果您正苦于以下问题:PHP CMap::length方法的具体用法?PHP CMap::length怎么用?PHP CMap::length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMap
的用法示例。
在下文中一共展示了CMap::length方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLength
public function testLength()
{
$map = CMap::make();
$map["one"] = "a";
$map["two"] = "b";
$map["three"] = "c";
$this->assertTrue(CMap::length($map) == 3);
}
示例2: requestField
protected static function requestField($map, $fieldName, CInputFilter $inputFilter, &$success)
{
$success = true;
// Account for the fact that, with PHP, GET and POST (and cookie) fields arrive having "." replaced with "_"
// in their names.
$fieldName = CString::replace($fieldName, ".", "_");
$value;
$hasField = false;
if (CMap::hasKey($map, $fieldName)) {
$value = $map[$fieldName];
if (isset($value)) {
if (!is_cstring($value) && !is_cmap($value)) {
// Should not happen in the known versions of PHP.
assert('false', vs(isset($this), get_defined_vars()));
$success = false;
return $inputFilter->defaultValue();
}
if (!self::$ms_treatEmptyRequestValuesAsAbsent) {
$hasField = true;
} else {
if (is_cstring($value)) {
$hasField = !CString::isEmpty($value);
} else {
$hasField = !CMap::isEmpty($value) && !(CMap::length($value) == 1 && CMap::hasKey($value, 0) && is_cstring($value[0]) && CString::isEmpty($value[0]));
}
}
}
}
if (!$hasField) {
$success = false;
return $inputFilter->defaultValue();
}
$inputFilterOrFilterCollection;
if ($inputFilter->expectedType() != CInputFilter::CARRAY && $inputFilter->expectedType() != CInputFilter::CMAP) {
$inputFilterOrFilterCollection = $inputFilter;
} else {
$inputFilterOrFilterCollection = $inputFilter->collectionInputFilters();
}
// Recursively convert any PHP array that has sequential keys and for which CArray type is expected into a
// CArray, while leaving PHP arrays for which CMap type is expected untouched.
$value = self::recurseValueBeforeFiltering($value, $inputFilterOrFilterCollection, $success, 0);
if (!$success) {
return $inputFilter->defaultValue();
}
return $inputFilter->filter($value, $success);
}
示例3: leaveNode
public function leaveNode(PhpParser\Node $node)
{
if ($node instanceof PhpParser\Node\Stmt\Class_ || $node instanceof PhpParser\Node\Stmt\Trait_) {
$this->m_numEnteredClassesOrTraits--;
} else {
if ($node instanceof PhpParser\Node\Stmt\Interface_) {
$this->m_numEnteredInterfaces--;
} else {
if ($node instanceof PhpParser\Node\Stmt\ClassMethod) {
$numEnteredMethods = $this->m_numEnteredMethods;
$this->m_numEnteredMethods--;
if (!($this->m_numEnteredClassesOrTraits == 1 && $this->m_numEnteredInterfaces == 0 && $numEnteredMethods == 1 && $this->m_numEnteredClosures == 0 && $this->m_numEnteredFunctions == 0)) {
return;
}
$method = $node;
if (CString::equalsCi($method->name, "__get") && CMap::length($method->params) >= 1) {
$statements = CMap::make();
$len = CArray::length($this->m_propsToWrap);
for ($i = 0; $i < $len; $i++) {
$propName = $this->m_propsToWrap[$i];
$subCondition = new PhpParser\Node\Expr\BooleanNot(new PhpParser\Node\Expr\FuncCall(new PhpParser\Node\Name(self::$ms_isFwCallFuncName)));
$subIf;
if (!$method->byRef) {
$return0 = new PhpParser\Node\Stmt\Return_(new PhpParser\Node\Expr\PropertyFetch(new PhpParser\Node\Expr\Variable("this"), $propName));
$return1 = new PhpParser\Node\Stmt\Return_(new PhpParser\Node\Expr\FuncCall(new PhpParser\Node\Name(self::$ms_toOopFuncName), [new PhpParser\Node\Expr\PropertyFetch(new PhpParser\Node\Expr\Variable("this"), $propName)]));
$else = new PhpParser\Node\Stmt\Else_([$return1]);
$subIf = new PhpParser\Node\Stmt\If_($subCondition, ["stmts" => [$return0], "else" => $else]);
} else {
$subStatements0 = CMap::make();
$return = new PhpParser\Node\Stmt\Return_(new PhpParser\Node\Expr\PropertyFetch(new PhpParser\Node\Expr\Variable("this"), $propName));
CMap::insertValue($subStatements0, $return);
$subStatements1 = CMap::make();
$assignment = new PhpParser\Node\Expr\Assign(new PhpParser\Node\Expr\ArrayDimFetch(new PhpParser\Node\Expr\Variable("GLOBALS"), new PhpParser\Node\Scalar\String(self::$ms_byRefGVarName)), new PhpParser\Node\Expr\FuncCall(new PhpParser\Node\Name(self::$ms_toOopFuncName), [new PhpParser\Node\Expr\PropertyFetch(new PhpParser\Node\Expr\Variable("this"), $propName)]));
CMap::insertValue($subStatements1, $assignment);
$return = new PhpParser\Node\Stmt\Return_(new PhpParser\Node\Expr\ArrayDimFetch(new PhpParser\Node\Expr\Variable("GLOBALS"), new PhpParser\Node\Scalar\String(self::$ms_byRefGVarName)));
CMap::insertValue($subStatements1, $return);
$else = new PhpParser\Node\Stmt\Else_($subStatements1);
$subIf = new PhpParser\Node\Stmt\If_($subCondition, ["stmts" => $subStatements0, "else" => $else]);
}
$condition = new PhpParser\Node\Expr\BinaryOp\Identical(new PhpParser\Node\Expr\Variable($method->params[0]->name), new PhpParser\Node\Scalar\String($propName));
$if = new PhpParser\Node\Stmt\If_($condition, ["stmts" => [$subIf]]);
CMap::insertValue($statements, $if);
}
if (isset($method->stmts)) {
foreach ($method->stmts as $stmt) {
CMap::insertValue($statements, $stmt);
}
}
$method->stmts = $statements;
return $method;
} else {
if (CString::equalsCi($method->name, "__set") && CMap::length($method->params) >= 2) {
$statements = CMap::make();
$len = CArray::length($this->m_propsToWrap);
for ($i = 0; $i < $len; $i++) {
$propName = $this->m_propsToWrap[$i];
$subCondition = new PhpParser\Node\Expr\BooleanNot(new PhpParser\Node\Expr\FuncCall(new PhpParser\Node\Name(self::$ms_isFwCallFuncName)));
$assignment0 = new PhpParser\Node\Expr\Assign(new PhpParser\Node\Expr\PropertyFetch(new PhpParser\Node\Expr\Variable("this"), $propName), new PhpParser\Node\Expr\Variable($method->params[1]->name));
$assignment1 = new PhpParser\Node\Expr\Assign(new PhpParser\Node\Expr\PropertyFetch(new PhpParser\Node\Expr\Variable("this"), $propName), new PhpParser\Node\Expr\FuncCall(new PhpParser\Node\Name(self::$ms_fromOopFuncName), [new PhpParser\Node\Expr\Variable($method->params[1]->name)]));
$else = new PhpParser\Node\Stmt\Else_([$assignment1]);
$subIf = new PhpParser\Node\Stmt\If_($subCondition, ["stmts" => [$assignment0], "else" => $else]);
$condition = new PhpParser\Node\Expr\BinaryOp\Identical(new PhpParser\Node\Expr\Variable($method->params[0]->name), new PhpParser\Node\Scalar\String($propName));
$if = new PhpParser\Node\Stmt\If_($condition, ["stmts" => [$subIf]]);
CMap::insertValue($statements, $if);
}
if (isset($method->stmts)) {
foreach ($method->stmts as $stmt) {
CMap::insertValue($statements, $stmt);
}
}
$method->stmts = $statements;
return $method;
}
}
} else {
if ($node instanceof PhpParser\Node\Expr\Closure) {
$this->m_numEnteredClosures--;
} else {
if ($node instanceof PhpParser\Node\Stmt\Function_) {
$this->m_numEnteredFunctions--;
}
}
}
}
}
}