Beispiel #1
0
 /**
  * Inserts a value into a map under the next integer key.
  *
  * This method could serve as a more eloquent alternative when dealing with interfaces that are using the PHP's
  * associative array in the role of a regular array.
  *
  * The new value is inserted under the integer key that is greater by one compared to the greatest integer key
  * already in the map or under `0` if there were no integer keys.
  *
  * @param  mixed $value The value to be inserted.
  *
  * @return void
  */
 public function insertValue($value)
 {
     CMap::insertValue($this->m_map, $value);
 }
Beispiel #2
0
 /**
  * Adds the email address and, optionally, the name of a "blind carbon copy" recipient who should receive a copy of
  * a message so that this recipient is not visible to any other recipients.
  *
  * @param  string $address The email address of the recipient.
  * @param  string $name **OPTIONAL.** The name of the recipient.
  *
  * @return void
  */
 public function addBcc($address, $name = null)
 {
     assert('is_cstring($address) && (!isset($name) || is_cstring($name))', vs(isset($this), get_defined_vars()));
     if (!isset($this->m_bcc)) {
         $this->m_bcc = CMap::make();
     }
     if (!isset($name)) {
         CMap::insertValue($this->m_bcc, $address);
     } else {
         $this->m_bcc[$address] = $name;
     }
 }
Beispiel #3
0
 public function leaveNode(PhpParser\Node $node)
 {
     if ($node->hasAttribute("_insertGetMMethodAfterMe") || $node->hasAttribute("_insertSetMMethodAfterMe")) {
         $statements = [$node];
         if ($node->hasAttribute("_insertGetMMethodAfterMe")) {
             $subStatements = 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)));
                 $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]);
                 $condition = new PhpParser\Node\Expr\BinaryOp\Identical(new PhpParser\Node\Expr\Variable("name"), new PhpParser\Node\Scalar\String($propName));
                 $if = new PhpParser\Node\Stmt\If_($condition, ["stmts" => [$subIf]]);
                 CMap::insertValue($subStatements, $if);
             }
             $method = new PhpParser\Node\Stmt\ClassMethod("__get", ["type" => PhpParser\Node\Stmt\Class_::MODIFIER_PUBLIC, "byRef" => true, "params" => [new PhpParser\Node\Param("name")], "stmts" => $subStatements]);
             CMap::insertValue($statements, $method);
         }
         if ($node->hasAttribute("_insertSetMMethodAfterMe")) {
             $subStatements = 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("value"));
                 $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("value")]));
                 $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("name"), new PhpParser\Node\Scalar\String($propName));
                 $if = new PhpParser\Node\Stmt\If_($condition, ["stmts" => [$subIf]]);
                 CMap::insertValue($subStatements, $if);
             }
             $method = new PhpParser\Node\Stmt\ClassMethod("__set", ["type" => PhpParser\Node\Stmt\Class_::MODIFIER_PUBLIC, "params" => [new PhpParser\Node\Param("name"), new PhpParser\Node\Param("value")], "stmts" => $subStatements]);
             CMap::insertValue($statements, $method);
         }
         return $statements;
     }
 }
Beispiel #4
0
 public function testInsertValue()
 {
     $map = ["one" => "a", "two" => "b", "three" => "c"];
     CMap::insertValue($map, "d");
     $this->assertTrue(CMap::equals($map, ["one" => "a", "two" => "b", "three" => "c", 0 => "d"]));
 }