diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index 88a9a1ad877..ce687ac49bc 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/lib/Cake/Routing/Dispatcher.php @@ -20,16 +20,19 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('Router', 'Routing'); -App::uses('CakeRequest', 'Network'); -App::uses('CakeResponse', 'Network'); -App::uses('Controller', 'Controller'); -App::uses('Scaffold', 'Controller'); -App::uses('View', 'View'); -App::uses('Debugger', 'Utility'); -App::uses('CakeEvent', 'Event'); -App::uses('CakeEventManager', 'Event'); -App::uses('CakeEventListener', 'Event'); +namespace Cake\Routing; +use Cake\Core\Configure, + Cake\Core\Plugin, + Cake\Core\App, + Cake\Controller\Controller, + Cake\Event\Event, + Cake\Event\EventListener, + Cake\Event\EventManager, + Cake\Network\Request, + Cake\Network\Response, + Cake\Utility\Inflector, + Cake\View\View, + Cake\Error; /** * Dispatcher converts Requests into controller actions. It uses the dispatched Request @@ -38,7 +41,7 @@ * * @package Cake.Routing */ -class Dispatcher implements CakeEventListener { +class Dispatcher implements EventListener { /** * Event manager, used to handle dispatcher filters @@ -59,14 +62,14 @@ public function __construct($base = false) { } /** - * Returns the CakeEventManager instance or creates one if none was + * Returns the Cake\Event\EventManager instance or creates one if none was * creted. Attaches the default listeners and filters * - * @return CakeEventmanger + * @return Cake\Event\EventManager */ public function getEventManager() { if (!$this->_eventManager) { - $this->_eventManager = new CakeEventManager(); + $this->_eventManager = new EventManager(); $this->_eventManager->attach($this); $this->_attachFilters($this->_eventManager); } @@ -86,7 +89,7 @@ public function implementedEvents() { * Attaches all event listeners for this dispatcher instance. Loads the * dispatcher filters from the configured locations. * - * @param CakeEventManager $manager + * @param Cake\Event\EventManager $manager * @return void * @throws MissingDispatcherFilterException */ @@ -101,10 +104,9 @@ protected function _attachFilters($manager) { $filter = array('callable' => $filter); } if (is_string($filter['callable'])) { - list($plugin, $callable) = pluginSplit($filter['callable'], true); - App::uses($callable, $plugin . 'Routing/Filter'); - if (!class_exists($callable)) { - throw new MissingDispatcherFilterException($callable); + $callable = App::classname($filter['callable'], 'Routing/Filter'); + if (!$callable) { + throw new Error\MissingDispatcherFilterException($filter['callable']); } $manager->attach(new $callable); } else { @@ -130,18 +132,18 @@ protected function _attachFilters($manager) { * If no controller of given name can be found, invoke() will throw an exception. * If the controller is found, and the action is not found an exception will be thrown. * - * @param CakeRequest $request Request object to dispatch. - * @param CakeResponse $response Response object to put the results of the dispatch into. + * @param Cake\Network\Request $request Request object to dispatch. + * @param Cake\Network\Response $response Response object to put the results of the dispatch into. * @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params * @return string|void if `$request['return']` is set then it returns response body, null otherwise * @throws MissingControllerException When the controller is missing. */ - public function dispatch(CakeRequest $request, CakeResponse $response, $additionalParams = array()) { - $beforeEvent = new CakeEvent('Dispatcher.beforeDispatch', $this, compact('request', 'response', 'additionalParams')); + public function dispatch(Request $request, Response $response, $additionalParams = array()) { + $beforeEvent = new Event('Dispatcher.beforeDispatch', $this, compact('request', 'response', 'additionalParams')); $this->getEventManager()->dispatch($beforeEvent); $request = $beforeEvent->data['request']; - if ($beforeEvent->result instanceof CakeResponse) { + if ($beforeEvent->result instanceof Response) { if (isset($request->params['return'])) { return $response->body(); } @@ -152,8 +154,8 @@ public function dispatch(CakeRequest $request, CakeResponse $response, $addition $controller = $this->_getController($request, $response); if (!($controller instanceof Controller)) { - throw new MissingControllerException(array( - 'class' => Inflector::camelize($request->params['controller']) . 'Controller', + throw new Error\MissingControllerException(array( + 'class' => Inflector::camelize($request->params['controller']), 'plugin' => empty($request->params['plugin']) ? null : Inflector::camelize($request->params['plugin']) )); } @@ -163,7 +165,7 @@ public function dispatch(CakeRequest $request, CakeResponse $response, $addition return $response->body(); } - $afterEvent = new CakeEvent('Dispatcher.afterDispatch', $this, compact('request', 'response')); + $afterEvent = new Event('Dispatcher.afterDispatch', $this, compact('request', 'response')); $this->getEventManager()->dispatch($afterEvent); $afterEvent->data['response']->send(); } @@ -174,17 +176,17 @@ public function dispatch(CakeRequest $request, CakeResponse $response, $addition * Otherwise the return value of the controller action are returned. * * @param Controller $controller Controller to invoke - * @param CakeRequest $request The request object to invoke the controller for. - * @param CakeResponse $response The response object to receive the output - * @return CakeResponse te resulting response object + * @param Cake\Network\Request $request The request object to invoke the controller for. + * @param Cake\Network\Response $response The response object to receive the output + * @return Cake\Network\Response te resulting response object */ - protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) { + protected function _invoke(Controller $controller, Request $request, Response $response) { $controller->constructClasses(); $controller->startupProcess(); $render = true; $result = $controller->invokeAction($request); - if ($result instanceof CakeResponse) { + if ($result instanceof Response) { $render = false; $response = $result; } @@ -203,7 +205,7 @@ protected function _invoke(Controller $controller, CakeRequest $request, CakeRes * Applies Routing and additionalParameters to the request to be dispatched. * If Routes have not been loaded they will be loaded, and app/Config/routes.php will be run. * - * @param CakeEvent $event containing the request, response and additional params + * @param Cake\Event\Event $event containing the request, response and additional params * @return void */ public function parseParams($event) { @@ -226,8 +228,8 @@ public function parseParams($event) { /** * Get controller to use, either plugin controller or application controller * - * @param CakeRequest $request Request object - * @param CakeResponse $response Response for the controller. + * @param Cake\Network\Request $request Request object + * @param Cake\Network\Response $response Response for the controller. * @return mixed name of controller if not loaded, or object if loaded */ protected function _getController($request, $response) { @@ -235,7 +237,7 @@ protected function _getController($request, $response) { if (!$ctrlClass) { return false; } - $reflection = new ReflectionClass($ctrlClass); + $reflection = new \ReflectionClass($ctrlClass); if ($reflection->isAbstract() || $reflection->isInterface()) { return false; } @@ -245,7 +247,7 @@ protected function _getController($request, $response) { /** * Load controller and return controller classname * - * @param CakeRequest $request + * @param Cake\Network\Request $request * @return string|bool Name of controller class name */ protected function _loadController($request) { @@ -258,12 +260,9 @@ protected function _loadController($request) { $controller = Inflector::camelize($request->params['controller']); } if ($pluginPath . $controller) { - $class = $controller . 'Controller'; - App::uses('AppController', 'Controller'); - App::uses($pluginName . 'AppController', $pluginPath . 'Controller'); - App::uses($class, $pluginPath . 'Controller'); - if (class_exists($class)) { - return $class; + $controller = App::classname($pluginPath . $controller, 'Controller', 'Controller'); + if ($controller) { + return $controller; } } return false; diff --git a/lib/Cake/Routing/DispatcherFilter.php b/lib/Cake/Routing/DispatcherFilter.php index cf6f4fa519c..c3ae21d94be 100644 --- a/lib/Cake/Routing/DispatcherFilter.php +++ b/lib/Cake/Routing/DispatcherFilter.php @@ -16,7 +16,8 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('CakeEventListener', 'Event'); +namespace Cake\Routing; +use Cake\Event\EventListener; /** * This abstract class represents a filter to be applied to a dispatcher cycle. It acts as as @@ -25,7 +26,7 @@ * * @package Cake.Routing */ -abstract class DispatcherFilter implements CakeEventListener { +abstract class DispatcherFilter implements EventListener { /** * Default priority for all methods in this filter @@ -55,16 +56,16 @@ public function implementedEvents() { * If used with default priority, it will be called after the Router has parsed the * url and set the routing params into the request object. * - * If a CakeResponse object instance is returned, it will be served at the end of the + * If a Cake\Network\Response object instance is returned, it will be served at the end of the * event cycle, not calling any controller as a result. This will also have the effect of * not calling the after event in the dispatcher. * * If false is returned, the event will be stopped and no more listeners will be notified. * Alternatively you can call `$event->stopPropagation()` to acheive the same result. * - * @param CakeEvent $event container object having the `request`, `response` and `additionalParams` + * @param Cake\Event\Event $event container object having the `request`, `response` and `additionalParams` * keys in the data property. - * @return CakeResponse|boolean + * @return Cake\Network\Response|boolean **/ public function beforeDispatch($event) { } @@ -77,7 +78,7 @@ public function beforeDispatch($event) { * If false is returned, the event will be stopped and no more listeners will be notified. * Alternatively you can call `$event->stopPropagation()` to acheive the same result. * - * @param CakeEvent $event container object having the `request` and `response` + * @param Cake\Event\Event $event container object having the `request` and `response` * keys in the data property. * @return mixed boolean to stop the event dispatching or null to continue **/ diff --git a/lib/Cake/Routing/Filter/AssetDispatcher.php b/lib/Cake/Routing/Filter/AssetDispatcher.php index 11840ba8bf2..8d38d390c6c 100644 --- a/lib/Cake/Routing/Filter/AssetDispatcher.php +++ b/lib/Cake/Routing/Filter/AssetDispatcher.php @@ -16,7 +16,13 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('DispatcherFilter', 'Routing'); +namespace Cake\Routing\Filter; +use Cake\Routing\DispatcherFilter; +use Cake\Core\App; +use Cake\Core\Configure; +use Cake\Core\Plugin; +use Cake\Network\Response; +use Cake\Utility\Inflector; /** * Filters a request and tests whether it is a file in the webroot folder or not and @@ -37,8 +43,8 @@ class AssetDispatcher extends DispatcherFilter { /** * Checks if a requested asset exists and sends it to the browser * - * @param CakeEvent $event containing the request and response object - * @return CakeResponse if the client is requesting a recognized asset, null otherwise + * @param Cake\Event\Event $event containing the request and response object + * @return Cake\Network\Response if the client is requesting a recognized asset, null otherwise */ public function beforeDispatch($event) { $url = $event->data['request']->url; @@ -68,10 +74,10 @@ public function beforeDispatch($event) { } } else { $plugin = Inflector::camelize($parts[0]); - if (CakePlugin::loaded($plugin)) { + if (Plugin::loaded($plugin)) { unset($parts[0]); $fileFragment = urldecode(implode(DS, $parts)); - $pluginWebroot = CakePlugin::path($plugin) . 'webroot' . DS; + $pluginWebroot = Plugin::path($plugin) . 'webroot' . DS; if (file_exists($pluginWebroot . $fileFragment)) { $assetFile = $pluginWebroot . $fileFragment; } @@ -92,8 +98,8 @@ public function beforeDispatch($event) { * Checks if the client is requeting a filtered asset and runs the corresponding * filter if any is configured * - * @param CakeEvent $event containing the request and response object - * @return CakeResponse if the client is requesting a recognized asset, null otherwise + * @param Cake\Event\Event $event containing the request and response object + * @return Cake\Network\Response if the client is requesting a recognized asset, null otherwise */ protected function _filterAsset($event) { $url = $event->data['request']->url; @@ -123,12 +129,12 @@ protected function _filterAsset($event) { /** * Sends an asset file to the client * - * @param CakeResponse $response The response object to use. + * @param Cake\Network\Response $response The response object to use. * @param string $assetFile Path to the asset file in the file system * @param string $ext The extension of the file to determine its mime type * @return void */ - protected function _deliverAsset(CakeResponse $response, $assetFile, $ext) { + protected function _deliverAsset(Response $response, $assetFile, $ext) { ob_start(); $compressionEnabled = Configure::read('Asset.compress') && $response->compress(); if ($response->type($ext) == $ext) { diff --git a/lib/Cake/Routing/Filter/CacheDispatcher.php b/lib/Cake/Routing/Filter/CacheDispatcher.php index 908d77a4a38..2a59ed76086 100644 --- a/lib/Cake/Routing/Filter/CacheDispatcher.php +++ b/lib/Cake/Routing/Filter/CacheDispatcher.php @@ -12,7 +12,11 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('DispatcherFilter', 'Routing'); +namespace Cake\Routing\Filter; +use Cake\Routing\DispatcherFilter; +use Cake\Core\Configure; +use Cake\Utility\Inflector; +use Cake\View\View; /** * This filter will check wheter the response was previously cached in the file system @@ -33,8 +37,8 @@ class CacheDispatcher extends DispatcherFilter { /** * Checks whether the response was cached and set the body accordingly. * - * @param CakeEvent $event containing the request and response object - * @return CakeResponse with cached content if found, null otherwise + * @param Cake\Event\Event $event containing the request and response object + * @return Cake\NetworkResponse with cached content if found, null otherwise */ public function beforeDispatch($event) { if (Configure::read('Cache.check') !== true) { diff --git a/lib/Cake/Routing/Route/PluginShortRoute.php b/lib/Cake/Routing/Route/PluginShortRoute.php index 2edd944e4ed..6763f9415b3 100644 --- a/lib/Cake/Routing/Route/PluginShortRoute.php +++ b/lib/Cake/Routing/Route/PluginShortRoute.php @@ -11,8 +11,9 @@ * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +namespace Cake\Routing\Route; -App::uses('CakeRoute', 'Routing/Route'); +use Cake\Routing\Route\Route; /** * Plugin short route, that copies the plugin param to the controller parameters @@ -20,7 +21,7 @@ * * @package Cake.Routing.Route */ -class PluginShortRoute extends CakeRoute { +class PluginShortRoute extends Route { /** * Parses a string url into an array. If a plugin key is found, it will be copied to the diff --git a/lib/Cake/Routing/Route/RedirectRoute.php b/lib/Cake/Routing/Route/RedirectRoute.php index bfb0f06c380..e8fb0866116 100644 --- a/lib/Cake/Routing/Route/RedirectRoute.php +++ b/lib/Cake/Routing/Route/RedirectRoute.php @@ -12,9 +12,11 @@ * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +namespace Cake\Routing\Route; -App::uses('CakeResponse', 'Network'); -App::uses('CakeRoute', 'Routing/Route'); +use Cake\Routing\Router, + Cake\Routing\Route\Route, + Cake\Network\Response; /** * Redirect route will perform an immediate redirect. Redirect routes @@ -23,12 +25,12 @@ * * @package Cake.Routing.Route */ -class RedirectRoute extends CakeRoute { +class RedirectRoute extends Route { /** - * A CakeResponse object + * A Response object * - * @var CakeResponse + * @var Cake\Network\Response */ public $response = null; @@ -71,7 +73,7 @@ public function parse($url) { return false; } if (!$this->response) { - $this->response = new CakeResponse(); + $this->response = new Response(); } $redirect = $this->redirect; if (count($this->redirect) == 1 && !isset($this->redirect['controller'])) { diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/Route.php similarity index 99% rename from lib/Cake/Routing/Route/CakeRoute.php rename to lib/Cake/Routing/Route/Route.php index b3121de3998..f9c69a60ebd 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/Route.php @@ -11,8 +11,10 @@ * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +namespace Cake\Routing\Route; -App::uses('Set', 'Utility'); +use Cake\Routing\Router, + Cake\Utility\Hash; /** * A single Route used by the Router to connect requests to @@ -23,7 +25,7 @@ * * @package Cake.Routing.Route */ -class CakeRoute { +class Route { /** * An array of named segments in a Route. diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index 95c49814f16..8f038ac103b 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -16,9 +16,16 @@ * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +namespace Cake\Routing; -App::uses('CakeRequest', 'Network'); -App::uses('CakeRoute', 'Routing/Route'); +use Cake\Core\Configure, + Cake\Network\Request, + Cake\Network\Response, + Cake\Routing\Route\Route, + Cake\Utility\Set, + Cake\Utility\Hash, + Cake\Utility\Inflector, + Cake\Error; /** * Parses the request URL into controller, action, and parameters. Uses the connected routes @@ -157,7 +164,7 @@ class Router { * * @var string */ - protected static $_routeClass = 'CakeRoute'; + protected static $_routeClass = 'Cake\Routing\Route\Route'; /** * Set the default route class to use or return the current one @@ -175,15 +182,15 @@ public static function defaultRouteClass($routeClass = null) { } /** - * Validates that the passed route class exists and is a subclass of CakeRoute + * Validates that the passed route class exists and is a subclass of Cake Route * * @param $routeClass * @return string * @throws RouterException */ protected static function _validateRouteClass($routeClass) { - if (!class_exists($routeClass) || !is_subclass_of($routeClass, 'CakeRoute')) { - throw new RouterException(__d('cake_dev', 'Route classes must extend CakeRoute')); + if (!class_exists($routeClass) || !is_subclass_of($routeClass, 'Cake\Routing\Route\Route')) { + throw new Error\RouterException(__d('cake_dev', 'Route classes must extend Cake\Routing\Route\Route')); } return $routeClass; } @@ -304,7 +311,7 @@ public static function connect($route, $defaults = array(), $options = array()) $routeClass = self::_validateRouteClass($options['routeClass']); unset($options['routeClass']); } - if ($routeClass == 'RedirectRoute' && isset($defaults['redirect'])) { + if ($routeClass === 'Cake\Routing\Route\RedirectRoute' && isset($defaults['redirect'])) { $defaults = $defaults['redirect']; } self::$routes[] = new $routeClass($route, $defaults, $options); @@ -344,8 +351,7 @@ public static function connect($route, $defaults = array(), $options = array()) * @return array Array of routes */ public static function redirect($route, $url, $options = array()) { - App::uses('RedirectRoute', 'Routing/Route'); - $options['routeClass'] = 'RedirectRoute'; + $options['routeClass'] = 'Cake\Routing\Route\RedirectRoute'; if (is_string($url)) { $url = array('redirect' => $url); } @@ -580,17 +586,17 @@ protected static function _parseExtension($url) { * Nested requests will create a stack of requests. You can remove requests using * Router::popRequest(). This is done automatically when using Object::requestAction(). * - * Will accept either a CakeRequest object or an array of arrays. Support for + * Will accept either a Cake\Network\Request object or an array of arrays. Support for * accepting arrays may be removed in the future. * - * @param CakeRequest|array $request Parameters and path information or a CakeRequest object. + * @param Cake\Network\Request|array $request Parameters and path information or a Cake\Network\Request object. * @return void */ public static function setRequestInfo($request) { - if ($request instanceof CakeRequest) { + if ($request instanceof Request) { self::$_requests[] = $request; } else { - $requestObj = new CakeRequest(); + $requestObj = new Request(); $request += array(array(), array()); $request[0] += array('controller' => false, 'action' => false, 'plugin' => null); $requestObj->addParams($request[0])->addPaths($request[1]); @@ -601,7 +607,7 @@ public static function setRequestInfo($request) { /** * Pops a request off of the request stack. Used when doing requestAction * - * @return CakeRequest The request removed from the stack. + * @return Cake\Network\Request The request removed from the stack. * @see Router::setRequestInfo() * @see Object::requestAction() */ @@ -613,7 +619,7 @@ public static function popRequest() { * Get the either the current request object, or the first one. * * @param boolean $current Whether you want the request from the top of the stack or the first one. - * @return CakeRequest or null. + * @return Cake\Network\Request or null. */ public static function getRequest($current = false) { if ($current) { @@ -678,7 +684,7 @@ public static function getPaths($current = false) { */ public static function reload() { if (empty(self::$_initialState)) { - self::$_initialState = get_class_vars('Router'); + self::$_initialState = get_class_vars(get_called_class()); self::_setPrefixes(); return; } @@ -984,13 +990,13 @@ public static function queryString($q, $extra = array(), $escape = false) { * This will strip out 'autoRender', 'bare', 'requested', and 'return' param names as those * are used for CakePHP internals and should not normally be part of an output url. * - * @param CakeRequest|array $params The params array or CakeRequest object that needs to be reversed. + * @param Cake\Network\Request|array $params The params array or Cake\Network\Request object that needs to be reversed. * @param boolean $full Set to true to include the full url including the protocol when reversing * the url. * @return string The string that is the reversed result of the array */ public static function reverse($params, $full = false) { - if ($params instanceof CakeRequest) { + if ($params instanceof Request) { $url = $params->query; $params = $params->params; } else { @@ -1047,7 +1053,7 @@ public static function normalize($url = '/') { /** * Returns the route matching the current request URL. * - * @return CakeRoute Matching route object. + * @return Cake\Routing\Route\Route Matching route object. */ public static function &requestRoute() { return self::$_currentRoute[0]; @@ -1056,7 +1062,7 @@ public static function &requestRoute() { /** * Returns the route matching the current request (useful for requestAction traces) * - * @return CakeRoute Matching route object. + * @return Cake\Routing\Route\Route Matching route object. */ public static function ¤tRoute() { return self::$_currentRoute[count(self::$_currentRoute) - 1]; @@ -1090,7 +1096,7 @@ public static function stripPlugin($base, $plugin = null) { * `$this->params['ext']`, and is used by the RequestHandler component to * automatically switch to alternate layouts and templates, and load helpers * corresponding to the given content, i.e. RssHelper. Switching layouts and helpers - * requires that the chosen extension has a defined mime type in `CakeResponse` + * requires that the chosen extension has a defined mime type in `Cake\Network\Response` * * A list of valid extension can be passed to this method, i.e. Router::parseExtensions('rss', 'xml'); * If no parameters are given, anything after the first . (dot) after the last / in the URL will be