/** * Call a method of the scope and output it * * @param *string $name the name of the method * @param *array $args arguments that were passed * * @return mixed */ public function __call($name, $args) { Argument::i()->test(1, 'string')->test(2, 'array'); //if the scope is null if (is_null($this->scope)) { //just call the parent return parent::__call($name, $args); } //get the results from the method call $results = $this->getResults($name, $args); //set temp variables $name = $this->name; $scope = $this->scope; //reset globals $this->name = null; $this->scope = null; //if there's a property name if ($name) { //output that $scope->inspect($name); //and return the results return $results; } //at this point we should output the results $class = get_class($scope); $output = sprintf(self::INSPECT, $class . '->' . $name); $this->output($output)->output($results); //and return the results return $results; }
/** * Try to see if this method is a PHP defined array function * * @param *string * @param *array * * @return mixed */ public function __call($name, $args) { 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; } } return parent::__call($name, $args); }
/** * Processes set, post, put, delete, get, etc. * * @param string * @param array * @return mixed */ public function __call($name, $args) { //if it starts with set if (strpos($name, 'set') === 0) { //determine the separator $separator = '_'; if (isset($args[1]) && is_scalar($args[1])) { $separator = (string) $args[1]; } //get the key $key = $this->getKey('set', $name, $separator); //just set it, we will validate on send $this->data[$key] = $args[0]; return $this; } //get the path equivilent $path = $this->getKey('', $name, '/'); if (isset($this->routes[$path])) { $meta = $this->routes[$path]; if (is_string($meta)) { $meta = $this->routes[$meta]; } $path = $this->getRoute($meta['route'], $args); return $this->send($meta['method'], $path, $meta); } //default actions test switch (true) { case strpos($name, 'get') === 0: $path = $this->getPath('get', $name, $args); return $this->send(self::METHOD_GET, $path); case strpos($name, 'create') === 0: $path = $this->getPath('create', $name, $args); return $this->send(self::METHOD_POST, $path); case strpos($name, 'post') === 0: $path = $this->getPath('post', $name, $args); return $this->send(self::METHOD_POST, $path); case strpos($name, 'update') === 0: $path = $this->getPath('update', $name, $args); return $this->send(self::METHOD_POST, $path); case strpos($name, 'put') === 0: $path = $this->getPath('put', $name, $args); return $this->send(self::METHOD_PUT, $path); case strpos($name, 'remove') === 0: $path = $this->getPath('remove', $name, $args); return $this->send(self::METHOD_DELETE, $path); case strpos($name, 'delete') === 0: $path = $this->getPath('delete', $name, $args); return $this->send(self::METHOD_DELETE, $path); } //if it's a factory method match if (count($args) === 0) { //add this to the path $this->paths[] = $this->getKey('', $name, '/'); return $this; } //let the parent handle the rest return parent::__call($name, $args); }