Permalink
Browse files

Add ability to prioritise controller maps.

Closes #131
  • Loading branch information...
1 parent 5c7d238 commit 5bb28c59f45e6c9c83a3b9a92658174491cfad3d @trq trq committed Nov 12, 2012
Showing with 25 additions and 6 deletions.
  1. +25 −6 lib/Proem/Dispatch/Standard.php
View
31 lib/Proem/Dispatch/Standard.php
@@ -32,13 +32,19 @@
use Proem\Dispatch\Template as Template;
use Proem\Service\Manager\Template as Manager;
use Proem\Routing\Route\Payload as Payload;
+use Proem\Util\Storage\Queue;
/**
* Proem\Dispatch\Standard
*/
class Standard implements Template
{
/**
+ * Constants used for priorities
+ */
+ const DEFAULT_CONTROLLERMAP_PRIORITY = 0;
+
+ /**
* Store the Assets manager
*
* @var Proem\Service\Manager\Template
@@ -49,9 +55,14 @@ class Standard implements Template
* Store an array of patterns used to searching
* for classes within a namepspace.
*
- * @var array $controllerMaps
+ * Controller maps are actually stored within a priority
+ * queue with the default controller map sitting at priority 0.
+ * If you want custom controller maps to be looked at before
+ * the default controller map, give them a higher priority.
+ *
+ * @var Queue $controllerMaps
*/
- protected $controllerMaps = [];
+ protected $controllerMaps;
/**
* Store the absolute namespace to the current class
@@ -96,7 +107,11 @@ class Standard implements Template
public function __construct(Manager $assets)
{
$this->assets = $assets;
- $this->controllerMaps = ['Module\:module\Controller\:controller'];
+ $this->controllerMaps = new Queue;
+ $this->controllerMaps->insert(
+ 'Module\:module\Controller\:controller',
+ self::DEFAULT_CONTROLLERMAP_PRIORITY
+ );
}
/**
@@ -126,17 +141,21 @@ public function setPayload(Payload $payload)
* This method allows us to add different directory structures
* which the dispatcher can use to locate controllers.
*
- * The default controller map looks like: 'Module\:module\Controller\:controller'
+ * The default controller map looks like: 'Module\:module\Controller\:controller' and
+ * is stored at priority 0.
+ *
+ * If you want custom controller maps to be looked at before the default controller map,
+ * give them a higher priority.
*
* You can create your own. The tokens :module and :controller will be replaced
* with the module and controller that are made available via the payload.
*
* @param string $map
* @return Proem\Dispatch\Template
*/
- public function attachControllerMap($map)
+ public function attachControllerMap($map, $priority = self::DEFAULT_CONTROLLERMAP_PRIORITY)
{
- $this->controllerMaps[] = $map;
+ $this->controllerMaps->insert($map, $priority);
return $this;
}

0 comments on commit 5bb28c5

Please sign in to comment.