Permalink
Browse files

Merge branch 'feature/controllermap' into develop

  • Loading branch information...
2 parents 5c7d238 + 5bb28c5 commit b574d0accb5b867bb82f72ceb580cd61e9974dd6 @trq trq committed Nov 12, 2012
Showing with 25 additions and 6 deletions.
  1. +25 −6 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 b574d0a

Please sign in to comment.