/** * Static call forwarder * * @param string $func method name * @param array $args passed arguments * @return */ public static function __callStatic($func, $args) { $instance = static::instance(); if (method_exists($instance, $func)) { return call_fuel_func_array(array($instance, $func), $args); } throw new \BadMethodCallException('Call to undefined method: ' . get_called_class() . '::' . $func); }
public static function run($task, $args = array()) { $task = strtolower($task); // Make sure something is set if (empty($task) or $task === 'help') { static::help(); return; } $module = false; list($module, $task) = array_pad(explode('::', $task), 2, null); if ($task === null) { $task = $module; $module = false; } if ($module) { try { \Module::load($module); $path = \Module::exists($module); \Finder::instance()->add_path($path); } catch (\FuelException $e) { throw new Exception(sprintf('Module "%s" does not exist.', $module)); } } // Just call and run() or did they have a specific method in mind? list($task, $method) = array_pad(explode(':', $task), 2, 'run'); // Find the task if (!($file = \Finder::search('tasks', $task))) { $files = \Finder::instance()->list_files('tasks'); $possibilities = array(); foreach ($files as $file) { $possible_task = pathinfo($file, \PATHINFO_FILENAME); $difference = levenshtein($possible_task, $task); $possibilities[$difference] = $possible_task; } ksort($possibilities); if ($possibilities and current($possibilities) <= 5) { throw new Exception(sprintf('Task "%s" does not exist. Did you mean "%s"?', $task, current($possibilities))); } else { throw new Exception(sprintf('Task "%s" does not exist.', $task)); } return; } require_once $file; $task = '\\Fuel\\Tasks\\' . ucfirst($task); $new_task = new $task(); // The help option has been called, so call help instead if ((\Cli::option('help') or $method == 'help') and is_callable(array($new_task, 'help'))) { $method = 'help'; } else { // if the task has an init method, call it now is_callable($task . '::_init') and $task::_init(); } if ($return = call_fuel_func_array(array($new_task, $method), $args)) { \Cli::write($return); } }
public function test_debug_dump_by_call_fuel_func_array() { // Set to browser mode. \Fuel::$is_cli = false; $expected = '<div class="fuelphp-dump" style="font-size: 13px;background: #EEE !important; border:1px solid #666; color: #000 !important; padding:10px;"><h1 style="border-bottom: 1px solid #CCC; padding: 0 0 5px 0; margin: 0 0 5px 0; font: bold 120% sans-serif;">COREPATH/base.php @ line: 462</h1><pre style="overflow:auto;font-size:100%;"><strong>Variable #1:</strong>' . "\n" . '<i></i> <strong></strong> (Integer): 1' . "\n\n\n" . '<strong>Variable #2:</strong>' . "\n" . '<i></i> <strong></strong> (Integer): 2' . "\n\n\n" . '<strong>Variable #3:</strong>' . "\n" . '<i></i> <strong></strong> (Integer): 3' . "\n\n\n" . '</pre></div>'; ob_start(); call_fuel_func_array('\\Debug::dump', array(1, 2, 3)); $output = ob_get_contents(); ob_end_clean(); $this->assertEquals($expected, $output); }
/** * Static access to the default instance * * @return mixed * @throws BadMethodCallException if the request method does not exist */ public static function __callStatic($name, $arguments) { // old pre-1.4 mapping to new instance methods static $mapping = array('get' => '__get', 'set' => '__set', 'set_config' => '__set', 'create_links' => 'render', 'page_links' => 'pages_render', 'prev_link' => 'previous', 'next_link' => 'next'); array_key_exists($name, $mapping) and $name = $mapping[$name]; // call the method on the default instance if ($instance = static::instance() and method_exists($instance, $name)) { return call_fuel_func_array(array($instance, $name), $arguments); } throw new \BadMethodCallException('The pagination class doesn\'t have a method called "' . $name . '"'); }
/** * router * * this router will call action methods for normal requests, * and REST methods for RESTful calls * * @param * string * @param * array */ public function router($resource, $arguments) { // if this is an ajax call if ($this->is_restful()) { // have the Controller_Rest router deal with it return parent::router($resource, $arguments); } // check if a input specific method exists $controller_method = strtolower(\Input::method()) . '_' . $resource; // fall back to action_ if no rest method is provided if (!method_exists($this, $controller_method)) { $controller_method = 'action_' . $resource; } // check if the action method exists if (method_exists($this, $controller_method)) { return call_fuel_func_array(array($this, $controller_method), $arguments); } // if not, we got ourselfs a genuine 404! throw new \HttpNotFoundException(); }
/** * Exectues the presets set in the config. Additional parameters replace the $1, $2, ect. * * @param string $name The name of the preset. * @return Image_Driver */ public function preset($name) { $vars = func_get_args(); if (isset($this->config['presets'][$name])) { $old_config = $this->config; $this->config = array_merge($this->config, $this->config['presets'][$name]); foreach ($this->config['actions'] as $action) { $func = $action[0]; array_shift($action); for ($i = 0; $i < count($action); $i++) { for ($x = count($vars) - 1; $x >= 0; $x--) { $action[$i] = preg_replace('#\\$' . $x . '#', $vars[$x], $action[$i]); } } call_fuel_func_array(array($this, $func), $action); } $this->config = $old_config; } else { throw new \InvalidArgumentException("Could not load preset {$name}, you sure it exists?"); } return $this; }
/** * Runs all queued actions on the loaded image. * * @param boolean $clear Decides if the queue should be cleared once completed. */ public function run_queue($clear = null) { foreach ($this->queued_actions as $action) { $tmpfunc = array(); for ($i = 0; $i < count($action); $i++) { $tmpfunc[$i] = var_export($action[$i], true); } $this->debug('', "<b>Executing <code>" . implode(", ", $tmpfunc) . "</code></b>"); call_fuel_func_array(array(&$this, '_' . $action[0]), array_slice($action, 1)); } if ($clear === null and $this->config['clear_queue'] or $clear === true) { $this->queued_actions = array(); } }
/** * Benchmark anything that is callable * * @access public * @static * */ public static function benchmark($callable, array $params = array()) { // get the before-benchmark time if (function_exists('getrusage')) { $dat = getrusage(); $utime_before = $dat['ru_utime.tv_sec'] + round($dat['ru_utime.tv_usec'] / 1000000, 4); $stime_before = $dat['ru_stime.tv_sec'] + round($dat['ru_stime.tv_usec'] / 1000000, 4); } else { list($usec, $sec) = explode(" ", microtime()); $utime_before = (double) $usec + (double) $sec; $stime_before = 0; } // call the function to be benchmarked $result = is_callable($callable) ? call_fuel_func_array($callable, $params) : null; // get the after-benchmark time if (function_exists('getrusage')) { $dat = getrusage(); $utime_after = $dat['ru_utime.tv_sec'] + round($dat['ru_utime.tv_usec'] / 1000000, 4); $stime_after = $dat['ru_stime.tv_sec'] + round($dat['ru_stime.tv_usec'] / 1000000, 4); } else { list($usec, $sec) = explode(" ", microtime()); $utime_after = (double) $usec + (double) $sec; $stime_after = 0; } return array('user' => sprintf('%1.6f', $utime_after - $utime_before), 'system' => sprintf('%1.6f', $stime_after - $stime_before), 'result' => $result); }
public function output($filetype = null) { $this->gdresizefunc = $filetype == 'gif' ? 'imagecopyresized' : ($this->gdresizefunc = 'imagecopyresampled'); extract(parent::output($filetype)); $this->run_queue(); $this->add_background(); $vars = array($this->image_data, null); if ($filetype == 'jpg' || $filetype == 'jpeg') { $vars[] = $this->config['quality']; $filetype = 'jpeg'; } elseif ($filetype == 'png') { $vars[] = floor($this->config['quality'] / 100 * 9); } call_fuel_func_array('image' . $filetype, $vars); if ($this->config['persistence'] === false) { $this->reload(); } return $this; }
/** * Alias of and_having() * * @param mixed $column * column name or array($column, $alias) or object * @param string $op * logic operator * @param mixed $value * column value * * @return $this */ public function having($column, $op = null, $value = null) { return call_fuel_func_array(array($this, 'and_having'), func_get_args()); }
/** * Alias of and_where() * * @return $this */ public function where() { return call_fuel_func_array(array($this, 'and_where'), func_get_args()); }
public static function init($args) { \Config::load('oil', true); // Remove flag options from the main argument list $args = self::_clear_args($args); try { if (!isset($args[1])) { if (\Cli::option('v', \Cli::option('version'))) { \Cli::write('Fuel: ' . \Fuel::VERSION . ' running in "' . \Fuel::$env . '" mode'); return; } static::help(); return; } switch ($args[1]) { case 'g': case 'generate': $action = isset($args[2]) ? $args[2] : 'help'; $subfolder = 'orm'; if (is_int(strpos($action, '/'))) { list($action, $subfolder) = explode('/', $action); } switch ($action) { case 'config': case 'controller': case 'model': case 'module': case 'migration': case 'task': case 'package': call_user_func('Oil\\Generate::' . $action, array_slice($args, 3)); break; case 'views': call_user_func('Oil\\Generate::views', array_slice($args, 3), $subfolder); break; case 'admin': call_user_func('Oil\\Generate_Admin::forge', array_slice($args, 3), $subfolder); break; case 'scaffold': call_user_func('Oil\\Generate_Scaffold::forge', array_slice($args, 3), $subfolder); break; default: Generate::help(); } break; case 'c': case 'console': if (isset($args[2]) and $args[2] == 'help') { Console::help(); } else { new Console(); } break; case 'p': case 'package': $action = isset($args[2]) ? $args[2] : 'help'; switch ($action) { case 'install': case 'uninstall': call_fuel_func_array('Oil\\Package::' . $action, array_slice($args, 3)); break; default: Package::help(); } break; case 'r': case 'refine': $task = isset($args[2]) ? $args[2] : null; call_user_func('Oil\\Refine::run', $task, array_slice($args, 3)); break; case 'cell': case 'cells': $action = isset($args[2]) ? $args[2] : 'help'; switch ($action) { case 'list': call_user_func('Oil\\Cell::all'); break; case 'search': case 'install': case 'upgrade': case 'uninstall': call_fuel_func_array('Oil\\Cell::' . $action, array_slice($args, 3)); break; case 'info': case 'details': call_fuel_func_array('Oil\\Cell::info', array_slice($args, 3)); break; default: Cell::help(); } break; case 't': case 'test': if (isset($args[2]) and $args[2] == 'help') { $output = <<<HELP Usage: php oil [t|test] Runtime options: --file=<file> # Run a test on a specific file only. --group=<group> # Only runs tests from the specified group(s). --exclude-group=<group> # Exclude tests from the specified group(s). --testsuite=<testsuite> # Only runs tests from the specified testsuite(s). --coverage-clover=<file> # Generate code coverage report in Clover XML format. --coverage-html=<dir> # Generate code coverage report in HTML format. --coverage-php=<file> # Serialize PHP_CodeCoverage object to file. --coverage-text=<file> # Generate code coverage report in text format. --log-junit=<file> # Generate report of test execution in JUnit XML format to file. --debug # Display debugging information during test execution. Description: Run phpunit on all or a subset of tests defined for the current application. Examples: php oil test Documentation: http://fuelphp.com/docs/packages/oil/test.html HELP; \Cli::write($output); } else { $phpunit_command = \Config::get('oil.phpunit.binary_path', 'phpunit'); // Check if we might be using the phar library $is_phar = false; foreach (explode(':', getenv('PATH')) as $path) { if (is_file($path . DS . $phpunit_command)) { $handle = fopen($path . DS . $phpunit_command, 'r'); $is_phar = fread($handle, 18) == '#!/usr/bin/env php'; fclose($handle); if ($is_phar) { break; } } } // Suppressing this because if the file does not exist... well thats a bad thing and we can't really check // I know that supressing errors is bad, but if you're going to complain: shut up. - Phil $phpunit_autoload_path = \Config::get('oil.phpunit.autoload_path', 'PHPUnit/Autoload.php'); @(include_once $phpunit_autoload_path); // Attempt to load PHUnit. If it fails, we are done. if (!$is_phar and !class_exists('PHPUnit_Framework_TestCase')) { throw new Exception('PHPUnit does not appear to be installed.' . PHP_EOL . PHP_EOL . "\tPlease visit http://phpunit.de and install."); } // Check for a custom phpunit config, but default to the one from core if (is_file(APPPATH . 'phpunit.xml')) { $phpunit_config = APPPATH . 'phpunit.xml'; } else { $phpunit_config = COREPATH . 'phpunit.xml'; } // CD to the root of Fuel and call up phpunit with the path to our config $command = 'cd ' . DOCROOT . '; ' . $phpunit_command . ' -c "' . $phpunit_config . '"'; // Respect the group options \Cli::option('group') and $command .= ' --group ' . \Cli::option('group'); \Cli::option('exclude-group') and $command .= ' --exclude-group ' . \Cli::option('exclude-group'); // Respect the testsuite options \Cli::option('testsuite') and $command .= ' --testsuite ' . \Cli::option('testsuite'); // Respect the debug options \Cli::option('debug') and $command .= ' --debug'; // Respect the coverage-html option \Cli::option('coverage-html') and $command .= ' --coverage-html ' . \Cli::option('coverage-html'); \Cli::option('coverage-clover') and $command .= ' --coverage-clover ' . \Cli::option('coverage-clover'); \Cli::option('coverage-text') and $command .= ' --coverage-text=' . \Cli::option('coverage-text'); \Cli::option('coverage-php') and $command .= ' --coverage-php ' . \Cli::option('coverage-php'); \Cli::option('log-junit') and $command .= ' --log-junit ' . \Cli::option('log-junit'); \Cli::option('file') and $command .= ' ' . \Cli::option('file'); \Cli::write('Tests Running...This may take a few moments.', 'green'); $return_code = 0; foreach (explode(';', $command) as $c) { passthru($c, $return_code_task); // Return failure if any subtask fails $return_code |= $return_code_task; } exit($return_code); } break; case 's': case 'server': if (isset($args[2]) and $args[2] == 'help') { $output = <<<HELP Usage: php oil [s|server] Runtime options: --php=<file> # The full pathname of your PHP-CLI binary if it's not in the path. --port=<port> # TCP port number the webserver should listen too. Defaults to 8000. --host=<host> # Hostname the webserver should run at. Defaults to "localhost". --docroot=<dir> # Your FuelPHP docroot. Defaults to "public". --router=<file> # PHP router script. Defaults to "fuel/packages/oil/phpserver.php". Description: Starts a local webserver to run your FuelPHP application, using PHP 5.4+ internal webserver. Examples: php oil server -p=8080 Documentation: http://fuelphp.com/docs/packages/oil/server.html HELP; \Cli::write($output); } else { if (version_compare(PHP_VERSION, '5.4.0') < 0) { \Cli::write('The PHP built-in webserver is only available on PHP 5.4+', 'red'); break; } $php = \Cli::option('php', 'php'); $port = \Cli::option('p', \Cli::option('port', '8000')); $host = \Cli::option('h', \Cli::option('host', 'localhost')); $docroot = \Cli::option('d', \Cli::option('docroot', 'public')); $router = \Cli::option('r', \Cli::option('router', __DIR__ . DS . '..' . DS . 'phpserver.php')); \Cli::write("Listening on http://{$host}:{$port}"); \Cli::write("Document root is {$docroot}"); \Cli::write("Press Ctrl-C to quit."); passthru("{$php} -S {$host}:{$port} -t {$docroot} {$router}"); } break; case 'create': \Cli::write('You can not use "oil create", a valid FuelPHP installation already exists in this directory', 'red'); break; default: static::help(); } } catch (\Exception $e) { static::print_exception($e); exit(1); } }
/** * Set a Model's properties as fields on a Fieldset, which will be created with the Model's * classname if none is provided. * * @param string * @param \Fieldset|null * @return \Fieldset */ public static function set_fields($obj, $fieldset = null) { static $_generated = array(); static $_tabular_rows = array(); $class = is_object($obj) ? get_class($obj) : $obj; if (is_null($fieldset)) { $fieldset = \Fieldset::instance($class); if (!$fieldset) { $fieldset = \Fieldset::forge($class); } } // is our parent fieldset a tabular form set? $tabular_form = is_object($fieldset->parent()) ? $fieldset->parent()->get_tabular_form() : false; // don't cache tabular form fieldsets if (!$tabular_form) { !array_key_exists($class, $_generated) and $_generated[$class] = array(); if (in_array($fieldset, $_generated[$class], true)) { return $fieldset; } $_generated[$class][] = $fieldset; } $primary_keys = is_object($obj) ? $obj->primary_key() : $class::primary_key(); $primary_key = count($primary_keys) === 1 ? reset($primary_keys) : false; $properties = is_object($obj) ? $obj->properties() : $class::properties(); if ($tabular_form and $primary_key and !is_object($obj)) { isset($_tabular_rows[$class]) or $_tabular_rows[$class] = 0; } foreach ($properties as $p => $settings) { if (\Arr::get($settings, 'skip', in_array($p, $primary_keys))) { continue; } if (isset($settings['form']['options'])) { foreach ($settings['form']['options'] as $key => $value) { is_array($value) or $settings['form']['options'][$key] = \Lang::get($value, array(), false) ?: $value; } } // field attributes can be passed in form key $attributes = isset($settings['form']) ? $settings['form'] : array(); // label is either set in property setting, as part of form attributes or defaults to fieldname $label = isset($settings['label']) ? $settings['label'] : (isset($attributes['label']) ? $attributes['label'] : $p); $label = \Lang::get($label, array(), false) ?: $label; // change the fieldname and label for tabular form fieldset children if ($tabular_form and $primary_key) { if (is_object($obj)) { $p = $tabular_form . '[' . $obj->{$primary_key} . '][' . $p . ']'; } else { $p = $tabular_form . '_new[' . $_tabular_rows[$class] . '][' . $p . ']'; } $label = ''; } // create the field and add validation rules $field = $fieldset->add($p, $label, $attributes); if (!empty($settings['validation'])) { foreach ($settings['validation'] as $rule => $args) { if (is_int($rule) and is_string($args)) { $args = array($args); } else { array_unshift($args, $rule); } call_fuel_func_array(array($field, 'add_rule'), $args); } } } // increase the row counter for tabular row fieldsets if ($tabular_form and $primary_key and !is_object($obj)) { $_tabular_rows[$class]++; } return $fieldset; }
/** * Sorts an array on multitiple values, with deep sorting support. * * @param array $array * collection of arrays/objects to sort * @param array $conditions * sorting conditions * @param * bool @ignore_case wether to sort case insensitive */ public static function multisort($array, $conditions, $ignore_case = false) { $temp = array(); $keys = array_keys($conditions); foreach ($keys as $key) { $temp[$key] = static::pluck($array, $key, true); is_array($conditions[$key]) or $conditions[$key] = array($conditions[$key]); } $args = array(); foreach ($keys as $key) { $args[] = $ignore_case ? array_map('strtolower', $temp[$key]) : $temp[$key]; foreach ($conditions[$key] as $flag) { $args[] = $flag; } } $args[] =& $array; call_fuel_func_array('array_multisort', $args); return $array; }
/** * This executes the request and sets the output to be used later. * * Usage: * * $request = Request::forge('hello/world')->execute(); * * @param array|null $method_params An array of parameters to pass to the method being executed * @return Request This request object */ public function execute($method_params = null) { // fire any request started events \Event::instance()->has_events('request_started') and \Event::instance()->trigger('request_started', '', 'none'); if (\Fuel::$profiling) { \Profiler::mark(__METHOD__ . ': Start of ' . $this->uri->get()); } logger(\Fuel::L_INFO, 'Called', __METHOD__); // Make the current request active static::$active = $this; // First request called is also the main request if (!static::$main) { logger(\Fuel::L_INFO, 'Setting main Request', __METHOD__); static::$main = $this; } if (!$this->route) { static::reset_request(); throw new \HttpNotFoundException(); } // save the current language so we can restore it after the call $current_language = \Config::get('language', 'en'); try { if ($this->route->callable !== null) { $response = call_fuel_func_array($this->route->callable, array($this)); if (!$response instanceof Response) { $response = new \Response($response); } } else { $method_prefix = $this->method . '_'; $class = $this->controller; // Allow override of method params from execute if (is_array($method_params)) { $this->method_params = array_merge($this->method_params, $method_params); } // If the class doesn't exist then 404 if (!class_exists($class)) { throw new \HttpNotFoundException(); } // Load the controller using reflection $class = new \ReflectionClass($class); if ($class->isAbstract()) { throw new \HttpNotFoundException(); } // Create a new instance of the controller $this->controller_instance = $class->newInstance($this); $this->action = $this->action ?: ($class->hasProperty('default_action') ? $class->getProperty('default_action')->getValue($this->controller_instance) : 'index'); $method = $method_prefix . $this->action; // Allow to do in controller routing if method router(action, params) exists if ($class->hasMethod('router')) { $method = 'router'; $this->method_params = array($this->action, $this->method_params); } if (!$class->hasMethod($method)) { // If they call user, go to $this->post_user(); $method = strtolower(\Input::method()) . '_' . $this->action; // Fall back to action_ if no HTTP request method based method exists if (!$class->hasMethod($method)) { $method = 'action_' . $this->action; } } if ($class->hasMethod($method)) { $action = $class->getMethod($method); if (!$action->isPublic()) { throw new \HttpNotFoundException(); } if (count($this->method_params) < $action->getNumberOfRequiredParameters()) { throw new \HttpNotFoundException(); } // fire any controller started events \Event::instance()->has_events('controller_started') and \Event::instance()->trigger('controller_started', '', 'none'); $class->hasMethod('before') and $class->getMethod('before')->invoke($this->controller_instance); $response = $action->invokeArgs($this->controller_instance, $this->method_params); $class->hasMethod('after') and $response = $class->getMethod('after')->invoke($this->controller_instance, $response); // fire any controller finished events \Event::instance()->has_events('controller_finished') and \Event::instance()->trigger('controller_finished', '', 'none'); } else { throw new \HttpNotFoundException(); } } // restore the language setting \Config::set('language', $current_language); } catch (\Exception $e) { static::reset_request(); // restore the language setting \Config::set('language', $current_language); throw $e; } // Get the controller's output if ($response instanceof Response) { $this->response = $response; } else { throw new \FuelException(get_class($this->controller_instance) . '::' . $method . '() or the controller after() method must return a Response object.'); } // fire any request finished events \Event::instance()->has_events('request_finished') and \Event::instance()->trigger('request_finished', '', 'none'); if (\Fuel::$profiling) { \Profiler::mark(__METHOD__ . ': End of ' . $this->uri->get()); } static::reset_request(); return $this; }
/** * Run rule * * Performs a single rule on a field and its value * * @param callback * @param mixed Value by reference, will be edited * @param array Extra parameters * @param array Validation field description * @throws Validation_Error */ protected function _run_rule($rule, &$value, $params, $field) { if (($rule = $this->_find_rule($rule)) === false) { return; } $output = call_fuel_func_array(reset($rule), array_merge(array($value), $params)); if ($output === false and ($value !== false or key($rule) == 'required')) { throw new \Validation_Error($field, $value, $rule, $params); } elseif ($output !== true) { $value = $output; } }
/** * Call rerouting for static usage. * * @param string $method method name called * @param array $args supplied arguments * * @throws \BadMethodCallException Invalid method * * @return mixed */ public static function __callStatic($method, $args = array()) { if (static::$_instance === false) { $instance = static::forge(); static::$_instance =& $instance; } if (is_callable(array(static::$_instance, $method))) { return call_fuel_func_array(array(static::$_instance, $method), $args); } throw new \BadMethodCallException('Invalid method: ' . get_called_class() . '::' . $method); }
/** * Get the Query as it's been build up to this point and return it as an object * * @return Database_Query */ public function get_query() { // Get the columns $columns = $this->select(false); // Start building the query $select = $columns; if ($this->use_subquery()) { $select = array(); foreach ($columns as $c) { $select[] = $c[0]; } } $query = call_fuel_func_array('DB::select', $select); // Set the defined connection on the query $query->set_connection($this->connection); // Set from table $query->from(array($this->_table(), $this->alias)); // Build the query further $tmp = $this->build_query($query, $columns); return $tmp['query']; }
/** * Does get() & set() in one call that takes a callback and it's arguments to generate the contents * * @param * string|array Valid PHP callback * @param * array Arguments for the above function/method * @param * int|null Cache expiration in seconds * @param * array Contains the identifiers of caches this one will depend on * @return mixed */ public final function call($callback, $args = array(), $expiration = null, $dependencies = array()) { try { $this->get(); } catch (\CacheNotFoundException $e) { // Create the contents $contents = call_fuel_func_array($callback, $args); $this->set($contents, $expiration, $dependencies); } return $this->get_contents(); }
/** * Magic method used to retrieve driver instances and check them for validity * * @param string * @param array * @return mixed * @throws BadMethodCallException */ public static function __callStatic($method, $args) { $args = array_pad($args, 3, null); if (array_key_exists($method, static::$_drivers)) { return static::_driver_instance($method, $args[0]); } if ($type = array_search($method, static::$_drivers)) { return static::_driver_check($type, $args[0], $args[1], @$args[2]); } if (static::$_verify_multiple !== true and method_exists(static::$_instance, $method)) { return call_fuel_func_array(array(static::$_instance, $method), $args); } throw new \BadMethodCallException('Invalid method: ' . get_called_class() . '::' . $method); }
/** * Router * * Requests are not made to methods directly The request will be for an "object". * this simply maps the object and method to the correct Controller method. * * @param * string * @param * array */ public function router($resource, $arguments) { \Config::load('rest', true); // If no (or an invalid) format is given, auto detect the format if (is_null($this->format) or !array_key_exists($this->format, $this->_supported_formats)) { // auto-detect the format $this->format = array_key_exists(\Input::extension(), $this->_supported_formats) ? \Input::extension() : $this->_detect_format(); } // Get the configured auth method if none is defined $this->auth === null and $this->auth = \Config::get('rest.auth'); // Check method is authorized if required, and if we're authorized if ($this->auth == 'basic') { $valid_login = $this->_prepare_basic_auth(); } elseif ($this->auth == 'digest') { $valid_login = $this->_prepare_digest_auth(); } elseif (method_exists($this, $this->auth)) { if (($valid_login = $this->{$this->auth}()) instanceof \Response) { return $valid_login; } } else { $valid_login = false; } // If the request passes auth then execute as normal if (empty($this->auth) or $valid_login) { // If they call user, go to $this->post_user(); $controller_method = strtolower(\Input::method()) . '_' . $resource; // Fall back to action_ if no rest method is provided if (!method_exists($this, $controller_method)) { $controller_method = 'action_' . $resource; } // If method is not available, set status code to 404 if (method_exists($this, $controller_method)) { return call_fuel_func_array(array($this, $controller_method), $arguments); } else { $this->response->status = $this->no_method_status; return; } } else { $this->response(array('status' => 0, 'error' => 'Not Authorized'), 401); } }
/** * Constructor * * @param string * @param string * @param array * @param array * @param Fieldset */ public function __construct($name, $label = '', array $attributes = array(), array $rules = array(), $fieldset = null) { $this->name = (string) $name; // determine the field's base name (for fields with array indices) $this->basename = ($pos = strpos($this->name, '[')) ? rtrim(substr(strrchr($this->name, '['), 1), ']') : $this->name; $this->fieldset = $fieldset instanceof Fieldset ? $fieldset : null; // Don't allow name in attributes unset($attributes['name']); // Take rules out of attributes unset($attributes['rules']); // Use specific setter when available foreach ($attributes as $attr => $val) { if (method_exists($this, $method = 'set_' . $attr)) { $this->{$method}($val); unset($attributes[$attr]); } } // Add default "type" attribute if not specified empty($attributes['type']) and $this->set_type($this->type); // only when non-empty, will supersede what was given in $attributes $label and $this->set_label($label); $this->attributes = array_merge($this->attributes, $attributes); foreach ($rules as $rule) { call_fuel_func_array(array($this, 'add_rule'), (array) $rule); } }