0, 'return' => 1, 'bare' => 1, 'requested' => 1); $data = isset($extra['data']) ? $extra['data'] : null; unset($extra['data']); if (is_string($url) && strpos($url, Router::fullBaseUrl()) === 0) { $url = Router::normalize(str_replace(Router::fullBaseUrl(), '', $url)); } if (is_string($url)) { $request = new CakeRequest($url); } elseif (is_array($url)) { $params = $url + array('pass' => array(), 'named' => array(), 'base' => false); $params = $extra + $params; $request = new CakeRequest(Router::reverse($params)); } if (isset($data)) { $request->data = $data; } $dispatcher = new Dispatcher(); $result = $dispatcher->dispatch($request, new CakeResponse(), $extra); Router::popRequest(); return $result; } /** * Calls a method on this object with the given parameters. Provides an OO wrapper * for `call_user_func_array` * * @param string $method Name of the method to call * @param array $params Parameter list to use when calling $method * @return mixed Returns the result of the method call */ public function dispatchMethod($method, $params = array()) { switch (count($params)) { case 0: return $this->{$method}(); case 1: return $this->{$method}($params[0]); case 2: return $this->{$method}($params[0], $params[1]); case 3: return $this->{$method}($params[0], $params[1], $params[2]); case 4: return $this->{$method}($params[0], $params[1], $params[2], $params[3]); case 5: return $this->{$method}($params[0], $params[1], $params[2], $params[3], $params[4]); default: return call_user_func_array(array(&$this, $method), $params); } } /** * Stop execution of the current script. Wraps exit() making * testing easier. * * @param int|string $status see http://php.net/exit for values * @return void */ protected function _stop($status = 0) { exit($status); } /** * Convenience method to write a message to CakeLog. See CakeLog::write() * for more information on writing to logs. * * @param string $msg Log message * @param int $type Error type constant. Defined in app/Config/core.php. * @param null|string|array $scope The scope(s) a log message is being created in. * See CakeLog::config() for more information on logging scopes. * @return bool Success of log write */ public function log($msg, $type = LOG_ERR, $scope = null) { if (!is_string($msg)) { $msg = print_r($msg, true); } return CakeLog::write($type, $msg, $scope); } /** * Allows setting of multiple properties of the object in a single line of code. Will only set * properties that are part of a class declaration. * * @param array $properties An associative array containing properties and corresponding values. * @return void */ protected function _set($properties = array()) { if (is_array($properties) && !empty($properties)) { $vars = get_object_vars($this); foreach ($properties as $key => $val) { if (array_key_exists($key, $vars)) { $this->{$key} = $val; } } } } /** * Merges this objects $property with the property in $class' definition. * This classes value for the property will be merged on top of $class' * * This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine * this method as an empty function. * * @param array $properties The name of the properties to merge. * @param string $class The class to merge the property with. * @param bool $normalize Set to true to run the properties through Hash::normalize() before merging. * @return void */ protected function _mergeVars($properties, $class, $normalize = true) { $classProperties = get_class_vars($class); foreach ($properties as $var) { if (isset($classProperties[$var]) && !empty($classProperties[$var]) && is_array($this->{$var}) && $this->{$var} != $classProperties[$var] ) { if ($normalize) { $classProperties[$var] = Hash::normalize($classProperties[$var]); $this->{$var} = Hash::normalize($this->{$var}); } $this->{$var} = Hash::merge($classProperties[$var], $this->{$var}); } } } }