当前位置: 首页>>代码示例>>PHP>>正文


PHP CMap::length方法代码示例

本文整理汇总了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);
 }
开发者ID:nunodotferreira,项目名称:Phred,代码行数:8,代码来源:CMapTest.php

示例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);
 }
开发者ID:nunodotferreira,项目名称:Phred,代码行数:46,代码来源:CRequest.php

示例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--;
                     }
                 }
             }
         }
     }
 }
开发者ID:nunodotferreira,项目名称:Phred,代码行数:86,代码来源:CSystem.php


注:本文中的CMap::length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。