Fri Jul 7 19:24:02 PHT 2006 nimrod.abing@gmail.com
* Allow client code to specify a custom dispatcher.
Rationale:
There are some scenarios where a custom dispatcher may appropriate. This
patch allows the client code to specify a custom dispatcher that will be
used instead of the core dispatcher.
Full Description:
A custom dispatcher can be any class that implements the dispatch() method.
Ideally, the custom dispatcher should be a subclass of the core Dispatcher
class the overrides the dispatch() method.
A custom dispatcher can be placed in one of three locations:
- Under the app folder.
- Under the app/vendors/vendorname folder.
- Under the vendors/vendorname folder.
The use of a custom dispatcher is controlled by two constants defined in
app/core.php:
- CUSTOM_DISPATCHER
Set this to the name of the custom dispatcher class that should be used
instead of the core dispatcher class.
We follow the usual CakePHP class naming and file naming conventions.
- DISPATCHER_VENDOR_PATH
When using a custom dispatcher from a vendor, set this to the path where
the custom dispatcher class file can be found. Place the vendor's folder
in either app/vendors or vendors.
diff -rN old-cake/app/config/core.php new-cake/app/config/core.php
146a147,160
>
> /**
> * Set the name of the custom dispatcher class that you want to use here. Place
> * the custom dispatcher class file in /app/ Leave this value as is if you want
> * to use the default dispatcher. We follow the usual CakePHP naming conventions
> * for both the class and the class file.
> */
> define('CUSTOM_DISPATCHER', false);
>
> /**
> * If using a custom dispatcher from a vendor, specify the vendor directory that
> * contains the custom dispatcher class.
> */
> define('DISPATCHER_VENDOR_PATH', false);
diff -rN old-cake/cake/basics.php new-cake/cake/basics.php
183a184,230
> * Determine the name of the dispatcher class to use based on settings found in
> * CUSTOM_DISPATCHER. It also loads the custom dispatcher class file if one
> * is specified.
> *
> */
> function getDispatcherClass() {
> $dispatcherClass = 'Dispatcher';
> if (defined('CUSTOM_DISPATCHER') && false !== CUSTOM_DISPATCHER) {
> if (loadDispatcher(CUSTOM_DISPATCHER)) {
> $dispatcherClass = CUSTOM_DISPATCHER;
> define('CUSTOM_DISPACHER_ERROR', false);
> }
> else {
> define('CUSTOM_DISPATCHER_ERROR', true);
> }
> }
> return $dispatcherClass;
> }
> /**
> * Loads a custom dispatcher if the client code defines the constant CUSTOM_DISPATCHER.
> *
> * @param string $name Name of the dispatcher class to load.
> * @return boolean Success
> */
> function loadDispatcher($name) {
> $paths = Configure::getInstance();
> $dispatcherFile = Inflector::underscore($name).'.php';
> if (!class_exists($name)) {
> $dispatcherPath = APP . $dispatcherFile;
> if (false !== DISPATCHER_VENDOR_PATH) {
> vendor(preg_replace('%'.DS.'+$%', '', DISPATCHER_VENDOR_PATH).DS.Inflector::underscore($name));
> }
> elseif (file_exists($dispatcherPath)) {
> require_once($dispatcherPath);
> } else {
> return false;
> }
> }
>
> if (class_exists($name)) {
> return true;
> }
> else {
> return false;
> }
> }
> /**
diff -rN old-cake/cake/bootstrap.php new-cake/cake/bootstrap.php
121c121,122
< $Dispatcher = new Dispatcher();
---
> $dispatcherClass = getDispatcherClass();
> $Dispatcher = new $dispatcherClass();
diff -rN old-cake/cake/dispatcher.php new-cake/cake/dispatcher.php
227a228,236
> if (defined('CUSTOM_DISPATCHER_ERROR')) {
> return $this->cakeError('missingDispatcher', array(
> array('className' => CUSTOM_DISPATCHER,
> 'dispatcher' => CUSTOM_DISPATCHER,
> 'webroot' => $this->webroot,
> 'url' => $url,
> 'base' => $this->base)));
> }
>
diff -rN old-cake/cake/libs/error.php new-cake/cake/libs/error.php
50c50,51
< $this->__dispatch =& new Dispatcher();
---
> $dispatcherClass = getDispatcherClass();
> $this->__dispatch =& new $dispatcherClass();
321a323,337
> * Renders the Missing Dispatcher class web page.
> *
> * @param unknown_type $params
> */
> function missingDispatcher($params) {
> extract($params);
> $this->controller->base = $base;
> $this->controller->viewPath = 'errors';
> $this->controller->webroot = $this->_webroot();
> $this->controller->set(array('dispatcher' => CUSTOM_DISPATCHER,
> 'title' => 'Missing Dispatcher'));
> $this->controller->render('missingDispatcher');
> exit();
> }
> /**
diff -rN old-cake/cake/libs/object.php new-cake/cake/libs/object.php
86c86,87
< $dispatcher =& new Dispatcher();
---
> $dispatcherClass = getDispatcherClass();
> $dispatcher =& new $dispatcherClass();
diff -rN old-cake/cake/libs/view/templates/errors/missing_dispatcher.thtml new-cake/cake/libs/view/templates/errors/missing_dispatcher.thtml
0a1,71
> /* SVN FILE: $Id$ */
>
> /**
> *
> *
> *
> *
> * PHP versions 4 and 5
> *
> * CakePHP : Rapid Development Framework
You are seeing this error because the bootstrapper cannot find > the class definition of the dispatcher that you have set in the constant CUSTOM_DISPATCHER. >
> > >> Notice: this error is being rendered by the app/views/errors/missing_dispatcher.thtml > view file, a user-customizable error page for handling undefined dispatcher classes.. >
> >> Fatal: Create Class: >
><?php
> class extends Dispatcher
> {
> }
> ?>
>
> > if (false === DISPATCHER_VENDOR_PATH): > ?> > in file : >
> else: > $dispatcherVendorPath = preg_replace('%'.DS.'+$%', '', DISPATCHER_VENDOR_PATH); > ?> > in file : or > endif; > ?> > >> Error: Unable to load dispatcher during bootstrapping process. >
\ No newline at end of file diff -rN old-cake/cake/scripts/templates/skel/config/core.php new-cake/cake/scripts/templates/skel/config/core.php 146a147,160 > > /** > * Set the name of the custom dispatcher class that you want to use here. Place > * the custom dispatcher class file in /app/ Leave this value as is if you want > * to use the default dispatcher. We follow the usual CakePHP naming conventions > * for both the class and the class file. > */ > define('CUSTOM_DISPATCHER', false); > > /** > * If using a custom dispatcher from a vendor, specify the vendor directory that > * contains the custom dispatcher class. > */ > define('DISPATCHER_VENDOR_PATH', false);