/** * Magic method (do not call directly). * @param string method name * @param array arguments * @return mixed * @throws \MemberAccessException * @throws FtpException */ public function __call($name, $args) { $name = strtolower($name); $silent = strncmp($name, 'try', 3) === 0; $func = $silent ? substr($name, 3) : $name; static $aliases = array('sslconnect' => 'ssl_connect', 'getoption' => 'get_option', 'setoption' => 'set_option', 'nbcontinue' => 'nb_continue', 'nbfget' => 'nb_fget', 'nbfput' => 'nb_fput', 'nbget' => 'nb_get', 'nbput' => 'nb_put'); $func = 'ftp_' . (isset($aliases[$func]) ? $aliases[$func] : $func); if (!function_exists($func)) { return parent::__call($name, $args); } /*Nette\*/ Tools::tryError(); if ($func === 'ftp_connect' || $func === 'ftp_ssl_connect') { $this->state = array($name => $args); $this->resource = call_user_func_array($func, $args); $res = NULL; } elseif (!is_resource($this->resource)) { /*Nette\*/ Tools::catchError($msg); throw new FtpException("Not connected to FTP server. Call connect() or ssl_connect() first."); } else { if ($func === 'ftp_login' || $func === 'ftp_pasv') { $this->state[$name] = $args; } array_unshift($args, $this->resource); $res = call_user_func_array($func, $args); if ($func === 'ftp_chdir' || $func === 'ftp_cdup') { $this->state['chdir'] = array(ftp_pwd($this->resource)); } } if (Tools::catchError($msg) && !$silent) { throw new FtpException($msg); } return $res; }
public function __call($sMethodName, $aVars) { if (stristr($sMethodName, 'get')) { // we have a getter we return $this return new static(); } elseif (!stristr($sMethodName, 'set')) { return parent::__call($sMethodName, $aVars); } return null; }
/** * Shortcut for handling configuration parameters */ public function __call($name, $arguments) { if (preg_match('/^(?<op>(get)|(set))_(?<arg>.+)$/', $name, $matches)) { $field = $matches['arg']; Deprecation::notice('3.1', "Call DynamicCache::config()->{$field} directly"); if ($matches['op'] === 'set') { return DynamicCache::config()->{$field} = $arguments[0]; } else { return DynamicCache::config()->{$field}; } } return parent::__call($name, $arguments); }
/** * Wildcard method for applying all the possible conditions * @param sting $method The method name * @param array $args The arguments * @return DisplayLogicCriteria */ public function __call($method, $args) { if (in_array($method, $this->config()->comparisons)) { $val = isset($args[0]) ? $args[0] : null; if (substr($method, 0, 2) == "is") { $operator = substr($method, 2); } else { $operator = ucwords($method); } $this->addCriterion(DisplayLogicCriterion::create($this->master, $operator, $val, $this)); return $this; } return parent::__call($method, $args); }
/** * Magic method to allow getting/setting of properties * * @return mixed */ public function __call($method, $arguments) { $action = substr($method, 0, 3); if (in_array($action, array('get', 'set'))) { $property = strtolower(substr($method, 3)); $allowedProperties = array('id', 'test', 'yep', 'nope', 'load', 'callback', 'complete'); if (in_array($property, $allowedProperties)) { if ($action === 'get') { return $this->{$property}; } else { $this->{$property} = $arguments[0]; return null; } } } return parent::__call($method, $arguments); }
/** * Call a template run-time helper. Do not call directly. * @param string helper name * @param array arguments * @return mixed */ public function __call($name, $args) { $lname = strtolower($name); if (!isset($this->helpers[$lname])) { foreach ($this->helperLoaders as $loader) { $helper = $loader->invoke($lname); if ($helper) { $this->registerHelper($lname, $helper); return $this->helpers[$lname]->invokeArgs($args); } } return parent::__call($name, $args); } return $this->helpers[$lname]->invokeArgs($args); }
/** * Method overloading * * Supports dynamic methods: * - delete() - deletes current model from the database, returns boolean true * or false. Upon succesfull deletion the exists property is set to false, * and the modified property to true - no data is deleted from the model * though. * * Ties in the validator methods. * * Also calls all the mixins (see the Object class). * If an unknown method is called, an exception is thrown. * * @param string $method * @param string $arguments * @return mixed */ public function __call($method, $arguments) { if ($method === 'delete' && $this->exists === true) { $result = $this->connection->delete($this->table, 'id=' . $this->data['id']); if ($result !== false) { $this->exists = false; $this->modified = true; $result = true; } return $result; } elseif (substr($method, 0, 9) === 'validate_') { if (method_exists('ModelValidator', $method)) { array_unshift($arguments, $this); return call_user_func_array(array('ModelValidator', $method), $arguments); } } else { return parent::__call($method, $arguments); } }
/** * Call to undefined method. * * @param string method name * @param array arguments * @return mixed * @throws MemberAccessException */ public function __call($name, $args) { $function = 'image' . $name; if (function_exists($function)) { foreach ($args as $key => $value) { if ($value instanceof self) { $args[$key] = $value->getImageResource(); } elseif (is_array($value) && isset($value['red'])) { // rgb $args[$key] = imagecolorallocatealpha($this->getImageResource(), $value['red'], $value['green'], $value['blue'], $value['alpha']); } } array_unshift($args, $this->getImageResource()); $res = call_user_func_array($function, $args); return is_resource($res) && get_resource_type($res) === 'gd' ? $this->setImageResource($res) : $res; } return parent::__call($name, $args); }
/** * Execute a controller action by it's name. * * Function is also capable of checking is a behavior has been mixed successfully using is[Behavior] * function. If the behavior exists the function will return TRUE, otherwise FALSE. * * @param string $method Method name * @param array $args Array containing all the arguments for the original call * @see execute() */ public function __call($method, $args) { if (!isset($this->_mixed_methods[$method])) { //Handle action alias method if (in_array($method, $this->getActions())) { //Get the data $data = !empty($args) ? $args[0] : array(); //Create a context object if (!$data instanceof CommandContextInterface) { $context = $this->getCommandContext(); //Store the parameters in the context $context->param = $data; //Automatic set the data in the request if an associative array is passed if (is_array($data) && !is_numeric(key($data))) { $context->request->data->add($data); } $context->result = false; } else { $context = $data; } //Execute the action return $this->execute($method, $context); } //Check if a behavior is mixed $parts = StringInflector::explode($method); if ($parts[0] == 'is' && isset($parts[1])) { if (!isset($this->_mixed_methods[$method])) { return false; } } } return parent::__call($method, $args); }
/** * Search the behaviors to see if this table behaves as. * * Function is also capable of checking is a behavior has been mixed successfully using is[Behavior] function. * If the behavior exists the function will return TRUE, otherwise FALSE. * * @param string $method The function name * @param array $arguments The function arguments * @throws \BadMethodCallException If method could not be found * @return mixed The result of the function */ public function __call($method, $arguments) { // If the method is of the form is[Bahavior] handle it. $parts = StringInflector::explode($method); if ($parts[0] == 'is' && isset($parts[1])) { if (!$this->hasBehavior(strtolower($parts[1]))) { return false; } } return parent::__call($method, $arguments); }
/** * Supports a simple form of Fluent Interfaces. Allows you to assign variables to the view by using the variable * name as the method name. If the method name is a setter method the setter will be called instead. * * For example : $view->data(array('foo' => 'bar'))->title('name')->render() * * @param string $method Method name * @param array $args Array containing all the arguments for the original call * @return ViewAbstract * * @see http://martinfowler.com/bliki/FluentInterface.html */ public function __call($method, $args) { if (!$this->isMixedMethod($method)) { //If one argument is passed we assume a setter method is being called if (count($args) == 1) { if (!method_exists($this, 'set' . ucfirst($method))) { $this->{$method} = $args[0]; return $this; } else { return $this->{'set' . ucfirst($method)}($args[0]); } } //Check if a behavior is mixed $parts = StringInflector::explode($method); if ($parts[0] == 'is' && isset($parts[1])) { return false; } } return parent::__call($method, $args); }
/** * Handle postTo* methods. * * @param string $method * @param array $arguments */ function __call($method, $arguments) { if (text($method)->startsWith('get')) { // a get*($parameters) method? if (empty($this->id)) { throw new \Exception('Can\'t fetch a connection without an id'); } if (count($arguments) > 0) { $parameters = $arguments[0]; } else { $parameters = array(); } $connection = lcfirst(substr($method, 3)); $connections = $this->getKnownConnections(array('id' => $this->id)); if (isset($connections[$connection]['class'])) { $class = $connections[$connection]['class']; } else { $class = '\\Sledgehammer\\GraphObject'; } if (isset($connections[$connection]['permission']) && $connections[$connection]['permission'] !== 'denied' && in_array($connections[$connection]['permission'], Facebook::getInstance()->getPermissions()) === false) { notice('Connection "' . $connection . '" requires the "' . $connections[$connection]['permission'] . '" permission', 'Current permissions: ' . quoted_human_implode(' and ', Facebook::getInstance()->getPermissions())); } $objects = array(); $response = Facebook::all($this->id . '/' . $connection, $parameters); foreach ($response as $data) { $objects[] = new $class($data); } if (empty($arguments['fields'])) { foreach ($objects as $object) { $object->_state = 'partial'; } } return new Collection($objects); } if (text($method)->startsWith('postTo')) { // a postTo*($data) method? if (empty($this->id)) { throw new \Exception('Can\'t post to a connection without an id'); } if (count($arguments) > 0) { $parameters = $arguments[0]; } else { notice('Missing argument 1 for ' . $method . '()'); $parameters = array(); } $response = Facebook::post($this->id . '/' . lcfirst(substr($method, 6)), $parameters); return new GraphObject($response['id']); } else { return parent::__call($method, $arguments); } }
/** * Call template functions * * This method will not throw a \BadMethodCallException. Instead if the method is not callable it will return null * * @param string $method The function name * @param array $arguments The function arguments * @return mixed|null Return NULL If method could not be found */ public function __call($method, $arguments) { $functions = $this->getFunctions(); if (!isset($functions[$method])) { if (is_callable(array($this, $method))) { $result = parent::__call($method, $arguments); } else { $result = null; } } else { $result = call_user_func_array($functions[$method], $arguments); } return $result; }
/** * Implement dynamic getters * * @param string $method Method name * @param array $args Array containing all the arguments for the original call * @return string|false Returns FALSE if the manifest doesn't exist */ public final function __call($method, $args) { if (count($args) == 0 && substr($method, 0, 2) == 'get') { $key = strtolower(substr($method, 3)); return $this->{$key}; } return parent::__call($method, $args); }
/** * Call a template run-time helper. Do not call directly. * @param string helper name * @param array arguments * @return mixed */ public function __call($name, $args) { $lname = strtolower($name); if (!isset($this->helpers[$lname])) { foreach ($this->helperLoaders as $loader) { $helper = call_user_func($loader, $lname); if ($helper) { $this->registerHelper($lname, $helper); return call_user_func_array($helper, $args); } } return parent::__call($name, $args); } return call_user_func_array($this->helpers[$lname], $args); }
/** * Execute a controller action by it's name. * * Function is also capable of checking is a behavior has been mixed successfully using is[Behavior] function. If * the behavior exists the function will return TRUE, otherwise FALSE. * * @param string $method Method name * @param array $args Array containing all the arguments for the original call * @return mixed * @see execute() */ public function __call($method, $args) { //Handle action alias method if (in_array($method, $this->getActions())) { //Get the data $data = !empty($args) ? $args[0] : array(); //Create a context object if (!$data instanceof CommandInterface) { $context = $this->getContext(); //Store the parameters in the context $context->param = $data; //Force the result to false before executing $context->result = false; } else { $context = $data; } //Execute the action return $this->execute($method, $context); } if (!$this->isMixedMethod($method)) { //Check if a behavior is mixed $parts = StringInflector::explode($method); if ($parts[0] == 'is' && isset($parts[1])) { return false; } } return parent::__call($method, $args); }
/** * Supports a simple form Fluent Interfaces. Allows you to set states by using the state name as the method name. * * For example : $model->sort('name')->limit(10)->getRowset(); * * @param string $method Method name * @param array $args Array containing all the arguments for the original call * @return ModelAbstract * * @see http://martinfowler.com/bliki/FluentInterface.html */ public function __call($method, $args) { if ($this->getState()->has($method)) { $this->getState()->set($method, $args[0]); return $this; } return parent::__call($method, $args); }
/** * Call a template run-time filter. Do not call directly. * @param string filter name * @param array arguments * @return mixed */ public function __call($name, $args) { $lname = strtolower($name); if (!isset($this->filters[$lname])) { $args2 = $args; array_unshift($args2, $lname); foreach ($this->filters[NULL] as $filter) { $res = call_user_func_array(Helpers::checkCallback($filter), $args2); if ($res !== NULL) { return $res; } elseif (isset($this->filters[$lname])) { return call_user_func_array(Helpers::checkCallback($this->filters[$lname]), $args); } } return parent::__call($name, $args); } return call_user_func_array(Helpers::checkCallback($this->filters[$lname]), $args); }