Пример #1
0
 /**
  * Dermines if the missing method is actually a PHP call.
  * If so, call it.
  *
  * @param *string $name Name of method
  * @param *array  $args Arguments to pass
  *
  * @return mixed
  */
 public function __call($name, $args)
 {
     Eden_String_Argument::i()->test(1, 'string')->test(2, 'array');
     $name = $this->getMethod($name);
     //if no type
     if (!isset(self::$_methods[$name])) {
         //we don't process anything else
         //call the parent
         return parent::__call($name, $args);
     }
     //case different types
     switch (self::$_methods[$name]) {
         case self::PRE:
             //if pre, we add it first into the args
             array_unshift($args, $this->data);
             break;
         case self::POST:
             //if post, we add it last into the args
             array_push($args, $this->data);
             break;
         case self::REFERENCE:
             //if reference, we add it first
             //into the args and call it
             call_user_func_array($name, array_merge(array(&$this->data), $args));
             return $this;
     }
     //call the method
     $result = call_user_func_array($name, $args);
     //if the result is a string
     if (is_string($result)) {
         //if this class is a string type
         if ($this instanceof Eden_String_Index) {
             //set value
             $this->data = $result;
             return $this;
         }
         //return string class
         return Eden_String_Index::i($result);
     }
     //if the result is an array
     if (is_array($result) && class_exists('Eden_Array_Index')) {
         //if this class is a array type
         if ($this instanceof Eden_Array_Index) {
             //set value
             $this->data = $result;
             return $this;
         }
         //return array class
         return Eden_Array_Index::i($result);
     }
     return $result;
 }
Пример #2
0
 /**
  * Dermines if the missing method is actually a PHP call.
  * If so, call it.
  *
  * @param *string $name Name of method
  * @param *array  $args Arguments to pass
  *
  * @return mixed
  */
 public function __call($name, $args)
 {
     Eden_Array_Argument::i()->test(1, 'string')->test(2, 'array');
     //if the method starts with get
     if (strpos($name, 'get') === 0) {
         //getUserName('-')
         $separator = '_';
         if (isset($args[0]) && is_scalar($args[0])) {
             $separator = (string) $args[0];
         }
         $key = preg_replace("/([A-Z0-9])/", $separator . "\$1", $name);
         //get rid of get
         $key = strtolower(substr($key, 3 + strlen($separator)));
         if (isset($this->data[$key])) {
             return $this->data[$key];
         }
         return null;
     } else {
         if (strpos($name, 'set') === 0) {
             //setUserName('Chris', '-')
             $separator = '_';
             if (isset($args[1]) && is_scalar($args[1])) {
                 $separator = (string) $args[1];
             }
             $key = preg_replace("/([A-Z0-9])/", $separator . "\$1", $name);
             //get rid of set
             $key = strtolower(substr($key, 3 + strlen($separator)));
             $this->__set($key, isset($args[0]) ? $args[0] : null);
             return $this;
         }
     }
     $name = $this->getMethod($name);
     //if no type
     if (!isset(self::$_methods[$name])) {
         //we don't process anything else
         //call the parent
         return parent::__call($name, $args);
     }
     //case different types
     switch (self::$_methods[$name]) {
         case self::PRE:
             //if pre, we add it first into the args
             array_unshift($args, $this->data);
             break;
         case self::POST:
             //if post, we add it last into the args
             array_push($args, $this->data);
             break;
         case self::REFERENCE:
             //if reference, we add it first
             //into the args and call it
             $result = call_user_func_array($name, array_merge(array(&$this->data), $args));
             if ($name === 'array_shift' || $name === 'array_pop') {
                 return $result;
             }
             return $this;
     }
     //call the method
     $result = call_user_func_array($name, $args);
     //if the result is a string
     if (is_string($result) && class_exists('Eden_String_Index')) {
         //if this class is a string type
         if ($this instanceof Eden_String_Index) {
             //set value
             $this->data = $result;
             return $this;
         }
         //return string class
         return Eden_String_Index::i($result);
     }
     //if the result is an array
     if (is_array($result)) {
         //if this class is a array type
         if ($this instanceof Eden_Array_Index) {
             //set value
             $this->data = $result;
             return $this;
         }
         //return array class
         return Eden_Array_Index::i($result);
     }
     return $result;
 }