__call() public method

Magic caller; allows to use the name of model state keys as methods to set their values.
public __call ( string $name, mixed $arguments ) : static
$name string The state variable key
$arguments mixed The state variable contents
return static
Exemplo n.º 1
0
 public function __call($method, $args)
 {
     if (isset($this->methods[$method])) {
         $func = $this->methods[$method];
         // Let's pass an instance of ourself, so we can manipulate other closures
         array_unshift($args, $this);
         return call_user_func_array($func, $args);
     }
     return parent::__call($method, $args);
 }
Exemplo n.º 2
0
 /**
  * Magic caller. It works like the magic setter and returns ourselves for chaining. If no arguments are passed we'll
  * only look for a scope filter.
  *
  * @param   string $name
  * @param   mixed  $arguments
  *
  * @return  static
  */
 public function __call($name, $arguments)
 {
     // If no arguments are provided try mapping to the scopeSomething() method
     if (empty($arguments)) {
         $methodName = 'scope' . ucfirst($name);
         if (method_exists($this, $methodName)) {
             $this->{$methodName}();
             return $this;
         }
     }
     // Implements getNew($relationName)
     if ($name == 'getNew' && count($arguments)) {
         return $this->relationManager->getNew($arguments[0]);
     }
     // Magically map relations to methods, e.g. $this->foobar will return the "foobar" relations' contents
     if ($this->relationManager->isMagicMethod($name)) {
         return call_user_func_array(array($this->relationManager, $name), $arguments);
     }
     // Otherwise call the parent
     return parent::__call($name, $arguments);
 }