Permalink
Browse files

Merge branch 'release-0.3.0'

  • Loading branch information...
2 parents 18a42a7 + 5d47f62 commit 0b3bf7e925df2485850868fb0c4bd691a407a628 @trq trq committed Apr 9, 2012
View
Binary file not shown.
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * @namespace Proem\Api\Controller
+ */
+namespace Proem\Api\Controller;
+
+use Proem\Controller\Template as ControllerTemplate,
+ Proem\Service\Manager\Template as ServiceManager;
+
+/**
+ * Proem\Api\Controller\Standard
+ */
+class Standard implements ControllerTemplate
+{
+ /**
+ * Store the Service Manager
+ *
+ * @var Proem\Service\Manager\Template
+ */
+ protected $assets;
+
+ /**
+ * The __construct sets up the Service Manager and
+ * is marked final so it can not be overloaded.
+ */
+ public final function __construct(ServiceManager $assets)
+ {
+ $this->assets = $assets;
+ }
+
+ /**
+ * Method called prior to any action
+ */
+ public function preAction()
+ {
+ }
+
+ /**
+ * Method called after any action
+ */
+ public function postAction()
+ {
+ }
+
+}
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * @namespace Proem\Api\Controller
+ */
+namespace Proem\Api\Controller;
+
+use Proem\Service\Manager\Template as ServiceManager;
+
+/**
+ * Proem\Api\Controller\Template
+ */
+interface Template
+{
+ public function preAction();
+
+ public function postAction();
+}
@@ -49,7 +49,7 @@ class Standard implements Template
* Store an array of patterns used to searching
* for classes within a namepspace.
*/
- protected $namespacePatterns = [];
+ protected $controllerMaps = [];
/**
* Store the absolute namespace to the current class
@@ -81,7 +81,7 @@ class Standard implements Template
public function __construct(Manager $assets)
{
$this->assets = $assets;
- $this->namespacePatterns = ['Module\:module\Controller\:controller'];
+ $this->controllerMaps = ['Module\:module\Controller\:controller'];
}
public function setPayload(Payload $payload)
@@ -90,23 +90,29 @@ public function setPayload(Payload $payload)
return $this;
}
+ public function registerControllerMap($map) {
+ $this->controllerMaps[] = $map;
+ }
+
public function isDispatchable()
{
$this->module = $this->payload->has('module') ? ucfirst(strtolower($this->payload->get('module'))) : '';
$this->controller = $this->payload->has('controller') ? ucfirst(strtolower($this->payload->get('controller'))) : '';
$this->action = $this->payload->has('action') ? $this->payload->get('action') : '';
- foreach ($this->namespacePatterns as $pattern) {
+ foreach ($this->controllerMaps as $map) {
$this->class = str_replace(
[':module', ':controller'],
[$this->module, $this->controller],
- $pattern
+ $map
);
if (class_exists($this->class)) {
$this->class = new $this->class($this->assets);
- if (method_exists($this->class, $this->action)) {
- return true;
+ if ($this->class instanceof \Proem\Controller\Template) {
+ if (method_exists($this->class, $this->action)) {
+ return true;
+ }
}
}
}
@@ -120,9 +126,9 @@ public function dispatch()
$this->assets->get('request')
->setGetData($this->payload->get('params'));
}
- $this->class->setUp();
+ $this->class->preAction();
$this->class->{$this->action}();
- $this->class->tearDown();
+ $this->class->postAction();
return $this;
}
}
View
@@ -52,7 +52,7 @@ class Proem
/**
* Store the framework version
*/
- const VERSION = '0.2.6';
+ const VERSION = '0.3.0';
/**
* Store events
@@ -33,7 +33,8 @@
use Proem\Routing\Router\Template,
Proem\Routing\Route\Template as Route,
Proem\Routing\Signal\Event\RouteMatch,
- Proem\Signal\Manager\Template as SignalManager;
+ Proem\Signal\Manager\Template as SignalManager,
+ Proem\Util\Storage\KeyValStore;
/**
* Proem\Api\Routing\Router\Standard
@@ -48,9 +49,9 @@ class Standard implements Template
/**
* Store our routes
*
- * @var array
+ * @var Proem\Util\Storage\KeyValStore
*/
- private $routes = [];
+ private $routes;
/**
* Setup
@@ -60,14 +61,15 @@ class Standard implements Template
public function __construct($requestUrl)
{
$this->requestUrl = $requestUrl;
+ $this->routes = new KeyValStore;
}
/**
* Store route objects
*/
public function map($name, Route $route)
{
- $this->routes[$name] = $route;
+ $this->routes->set($name, $route);
return $this;
}
@@ -84,8 +86,8 @@ public function map($name, Route $route)
*/
public function route()
{
- if ($route = current($this->routes)) {
- next($this->routes);
+ if ($route = $this->routes->current()) {
+ $this->routes->next();
$route->process($this->requestUrl);
if ($route->isMatch() && $route->getPayload()->isPopulated()) {
@@ -94,7 +96,7 @@ public function route()
return $this->route();
}
}
- reset($this->routes);
+ $this->routes->rewind();
return false;
}
}
@@ -66,6 +66,16 @@ class Standard implements Template
*/
private $callbacks = [];
+ /**
+ * Remove Event listeners from the Queue.
+ */
+ public function remove($name)
+ {
+ if (isset($this->queues[$name])) {
+ unset($this->queues[$name]);
+ }
+ }
+
/**
* Register a listener attached to a particular named Event.
*
@@ -35,6 +35,8 @@
*/
interface Template
{
+ public function remove($name);
+
public function attach(array $options);
public function trigger(array $options);

0 comments on commit 0b3bf7e

Please sign in to comment.