Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'release-0.7.0'

  • Loading branch information...
commit c73f11129a581d69d47c7f07d34950953744984d 2 parents 5d67a09 + 4c20396
@trq trq authored
Showing with 940 additions and 1,340 deletions.
  1. +2 −0  .gitignore
  2. +3 −2 .travis.yml
  3. +12 −0 CONTRIBUTING.md
  4. +12 −4 Phakefile
  5. +13 −2 composer.json
  6. +47 −18 lib/Proem/Bootstrap/Filter/Event/Dispatch.php
  7. +23 −14 lib/Proem/Bootstrap/Filter/Event/Request.php
  8. +22 −14 lib/Proem/Bootstrap/Filter/Event/Response.php
  9. +69 −45 lib/Proem/Bootstrap/Filter/Event/Route.php
  10. +2 −3 lib/Proem/Bootstrap/Signal/Event/Bootstrap.php
  11. +13 −11 lib/Proem/Controller/Standard.php
  12. +15 −10 lib/Proem/Dispatch/Stage.php
  13. +129 −20 lib/Proem/Dispatch/Standard.php
  14. +2 −2 lib/Proem/Dispatch/Template.php
  15. +3 −3 lib/Proem/Ext/Module/Generic.php
  16. +3 −3 lib/Proem/Ext/Plugin/Generic.php
  17. +17 −9 lib/Proem/Filter/Event/Generic.php
  18. +4 −5 lib/Proem/Filter/Manager/Standard.php
  19. +3 −3 lib/Proem/Filter/Manager/Template.php
  20. +13 −9 lib/Proem/IO/Request/Http/Fake.php
  21. +8 −6 lib/Proem/IO/Request/Http/Standard.php
  22. +0 −1  lib/Proem/IO/Request/Template.php
  23. +7 −8 lib/Proem/IO/Response/Http/Standard.php
  24. +0 −1  lib/Proem/IO/Response/Template.php
  25. +35 −24 lib/Proem/Proem.php
  26. +22 −6 lib/Proem/Routing/Route/Generic.php
  27. +19 −15 lib/Proem/Routing/Route/Standard.php
  28. +13 −7 lib/Proem/Routing/Route/StaticRoute.php
  29. +0 −1  lib/Proem/Routing/Route/Template.php
  30. +5 −6 lib/Proem/Routing/Router/Standard.php
  31. +0 −1  lib/Proem/Routing/Router/Template.php
  32. +2 −2 lib/Proem/Routing/Signal/Event/RouteDispatch.php
  33. +2 −2 lib/Proem/Routing/Signal/Event/RouteExhausted.php
  34. +2 −2 lib/Proem/Routing/Signal/Event/RouteMatch.php
  35. +13 −6 lib/Proem/Service/Asset/Standard.php
  36. +0 −1  lib/Proem/Service/Asset/Template.php
  37. +2 −3 lib/Proem/Service/Manager/Standard.php
  38. +0 −1  lib/Proem/Service/Manager/Template.php
  39. +59 −5 lib/Proem/Signal/Event/Standard.php
  40. +42 −4 lib/Proem/Signal/Event/Template.php
  41. +148 −54 lib/Proem/Signal/Manager/Standard.php
  42. +2 −3 lib/Proem/Signal/Manager/Template.php
  43. +24 −20 lib/Proem/{ → Util}/Autoloader.php
  44. +0 −423 lib/Proem/Util/Opt/Option.php
  45. +0 −79 lib/Proem/Util/Opt/Options.php
  46. +0 −41 lib/Proem/Util/Opt/Payload.php
  47. +0 −1  lib/Proem/Util/Process/Callback.php
  48. +38 −17 ...s/lib/Proem/Tests/Util/Options/Fixtures/OptionsFixture3.php → lib/Proem/Util/Process/EventCallback.php
  49. +10 −6 lib/Proem/Util/Storage/KeyValStore.php
  50. +0 −1  lib/Proem/Util/Storage/Queue.php
  51. +2 −2 tests/bootstrap.php
  52. +1 −1  tests/lib/Proem/Tests/AutoloaderTest.php
  53. +3 −3 tests/lib/Proem/Tests/ControllerTest.php
  54. +1 −1  tests/lib/Proem/Tests/ExtTest.php
  55. +2 −2 tests/lib/Proem/Tests/Fixtures/Controller/Bar.php
  56. +12 −0 tests/lib/Proem/Tests/Routing/StandardRouteTest.php
  57. +59 −3 tests/lib/Proem/Tests/SignalTest.php
  58. +0 −242 tests/lib/Proem/Tests/Util/OptTest.php
  59. +0 −72 tests/lib/Proem/Tests/Util/Options/Fixtures/OptionsFixture.php
  60. +0 −59 tests/lib/Proem/Tests/Util/Options/Fixtures/OptionsFixture2.php
  61. +0 −31 tests/lib/Proem/Tests/Util/Options/Fixtures/ProemFixture.php
View
2  .gitignore
@@ -2,3 +2,5 @@ build
tests/log/*
tests/coverage
vendor
+composer.lock
+issues
View
5 .travis.yml
@@ -3,14 +3,15 @@ language: php
php:
- 5.4
-before_script: curl -s http://getcomposer.org/installer | php -- && php composer.phar install --dev
+before_script: composer --dev install
script: ./vendor/bin/phake dev:tests
notifications:
irc:
on_success: change
on_failure: always
- - "irc.freenode.net#proem"
+ channels:
+ - "irc.freenode.net#proem"
branches:
only:
View
12 CONTRIBUTING.md
@@ -0,0 +1,12 @@
+## CONTRIBUTING
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
+
+## FEEDS & IRC
+Proem now has a dedicated twitter feed http://twitter.com/proem which will automatically post any commits as well as news. If you plan on helping out, you should follow this.
+
+Also available now is an irc channel (#proem) on freenode. Join if you have any questions.
View
16 Phakefile
@@ -1,9 +1,8 @@
<?php
-require_once 'lib/Proem/Autoloader.php';
+require_once 'lib/Proem/Util/Autoloader.php';
-(new \Proem\Autoloader)
- ->attachNamespace('Proem', 'lib')
+(new \Proem\Util\Autoloader)
->register();
group('proem', function() {
@@ -15,6 +14,9 @@ group('proem', function() {
group('dev', function() {
+ desc('Default tasks to execute before commit');
+ task('pre-commit', 'tests', 'sniff', function() {});
+
desc('Run the unit tests');
task('tests', function($args) {
$report = ' ';
@@ -31,6 +33,12 @@ group('dev', function() {
}
});
+ desc('Sniff code for PSR-1/2');
+ task('sniff', function ($args) {
+ chdir(realpath(__DIR__));
+ system('vendor/bin/phpcs -a --standard=PSR2 lib/');
+ });
+
desc('Build the Phar archive');
task('build', 'tests', function($args) {
if (!is_dir('build')) {
@@ -80,4 +88,4 @@ group('dev', function() {
});
});
-task('default', 'dev:tests');
+task('default', 'dev:pre-commit');
View
15 composer.json
@@ -12,14 +12,25 @@
"homepage": "http://thorpesystems.com"
}
],
+ "support": {
+ "issues": "https://github.com/proem/proem/issues",
+ "irc": "irc://irc.freenode.net/proem"
+ },
"require": {
- "php": ">=5.4.0"
+ "php": ">=5.4.0",
+ "ext-pcre": "*",
+ "ext-reflection": "*",
+ "ext-spl": "*"
+ },
+ "suggest": {
+ "ext-apc": "*"
},
"autoload": {
"psr-0": { "Proem": "lib/" }
},
"require-dev": {
"jaz303/phake": "dev-master",
- "EHER/PHPUnit": ">=1.6"
+ "phpunit/phpunit": "3.7.*",
+ "squizlabs/php_codesniffer": "dev-master"
}
}
View
65 lib/Proem/Bootstrap/Filter/Event/Dispatch.php
@@ -30,12 +30,12 @@
*/
namespace Proem\Bootstrap\Filter\Event;
-use Proem\Service\Manager\Template as Manager,
- Proem\Service\Asset\Standard as Asset,
- Proem\Bootstrap\Signal\Event\Bootstrap,
- Proem\Filter\Event\Generic as Event,
- Proem\Dispatch\Standard as DispatchStandard,
- Proem\Dispatch\Stage as DispatchStage;
+use Proem\Service\Manager\Template as Manager;
+use Proem\Service\Asset\Standard as Asset;
+use Proem\Bootstrap\Signal\Event\Bootstrap;
+use Proem\Filter\Event\Generic as Event;
+use Proem\Dispatch\Standard as DispatchStandard;
+use Proem\Dispatch\Stage as DispatchStage;
/**
* The default "Dispatch" filter event.
@@ -45,9 +45,10 @@ class Dispatch extends Event
/**
* Called prior to inBound.
*
- * A listener responding with an object implementing the
- * Proem\Dispatch\Template interface, will result in that object being
- * placed within the main service manager under the index of *dispatch*.
+ * A listener responding with an event containing a DI container holding an
+ * implemention of the Proem\Dispatch\Template interface, will result in
+ * that implementation being placed within the main service manager under
+ * the index of *dispatch*.
*
* @see Proem\Dispatch\Template
* @param Proem\Service\Manager\Template
@@ -58,9 +59,12 @@ public function preIn(Manager $assets)
if ($assets->provides('events', 'Proem\Signal\Manager\Template')) {
$assets->get('events')->trigger(
(new Bootstrap('proem.pre.in.dispatch'))->setServiceManager($assets),
- function($response) use ($assets) {
- if ($response->provides('Proem\Dispatch\Template')) {
- $assets->set('dispatch', $response);
+ function ($response) use ($assets) {
+ if (
+ $response->has('dispatch.asset') &&
+ $response->getParam('dispatch.asset')->provides('Proem\Dispatch\Template')
+ ) {
+ $assets->set('dispatch', $response->getParam('dispatch.asset'));
}
}
);
@@ -83,9 +87,14 @@ public function inBound(Manager $assets)
$asset = new Asset;
$assets->set(
'dispatch',
- $asset->set('Proem\Dispatch\Template', $asset->single(function() use ($assets) {
- return new DispatchStandard($assets);
- }))
+ $asset->set(
+ 'Proem\Dispatch\Template',
+ $asset->single(
+ function () use ($assets) {
+ return new DispatchStandard($assets);
+ }
+ )
+ )
);
}
}
@@ -101,11 +110,31 @@ public function inBound(Manager $assets)
*/
public function postIn(Manager $assets)
{
+ $skipDispatch = false;
+ $dispatchStageAsset = null;
+
if ($assets->provides('events', 'Proem\Signal\Manager\Template')) {
- $assets->get('events')->trigger((new Bootstrap('proem.post.in.dispatch'))->setServiceManager($assets));
- }
+ $assets->get('events')->trigger(
+ (new Bootstrap('proem.post.in.dispatch'))->setServiceManager($assets),
+ function ($response) use (&$skipDispatch) {
+ if ($response->has('skip.dispatch') && $response->getParam('skip.dispatch')) {
+ $skipDispatch = true;
+ }
+ if ($response->has('stage.asset')) {
+ $dispatchStageAsset = $response->get('stage.asset');
+ }
+ }
+ );
- (new DispatchStage($assets));
+ if (!$skipDispatch) {
+ if ($dispatchStageAsset !== null) {
+ $dispatchStageAsset->setParam('assets', $assets);
+ $dispatchStageAsset->get();
+ } else {
+ (new DispatchStage($assets));
+ }
+ }
+ }
}
/**
View
37 lib/Proem/Bootstrap/Filter/Event/Request.php
@@ -30,11 +30,11 @@
*/
namespace Proem\Bootstrap\Filter\Event;
-use Proem\Service\Manager\Template as Manager,
- Proem\Bootstrap\Signal\Event\Bootstrap,
- Proem\IO\Request\Http\Standard as HTTPRequest,
- Proem\Service\Asset\Standard as Asset,
- Proem\Filter\Event\Generic as Event;
+use Proem\Service\Manager\Template as Manager;
+use Proem\Bootstrap\Signal\Event\Bootstrap;
+use Proem\IO\Request\Http\Standard as HTTPRequest;
+use Proem\Service\Asset\Standard as Asset;
+use Proem\Filter\Event\Generic as Event;
/**
* The default "Request" filter event.
@@ -44,9 +44,10 @@ class Request extends Event
/**
* Called prior to inBound.
*
- * A listener responding with an object that implements the
- * Proem\IO\Request\Template interface will result in that object
- * being placed within the service manager under the *request* index.
+ * A listener responding with an event containing a DI container holding an
+ * implemention of the Proem\IO\Request\Template interface, will result in
+ * that implementation being placed within the main service manager under
+ * the index of *request*.
*
* @param Proem\Service\Manager\Template $assets
* @triggers Proem\Bootstrap\Signal\Event\Bootstrap proem.pre.in.request
@@ -56,9 +57,12 @@ public function preIn(Manager $assets)
if ($assets->provides('events', 'Proem\Signal\Manager\Template')) {
$assets->get('events')->trigger(
(new Bootstrap('proem.pre.in.request'))->setServiceManager($assets),
- function($response) use ($assets) {
- if ($response->provides('Proem\IO\Request\Template')) {
- $assets->set('request', $response);
+ function ($response) use ($assets) {
+ if (
+ $response->has('request.asset') &&
+ $response->getParam('request.asset')->provides('Proem\IO\Request\Template')
+ ) {
+ $assets->set('request', $response->getParam('request.asset'));
}
}
);
@@ -80,9 +84,14 @@ public function inBound(Manager $assets)
$asset = new Asset;
$assets->set(
'request',
- $asset->set('Proem\IO\Request\Template', $asset->single(function() {
- return new HTTPRequest;
- }))
+ $asset->set(
+ 'Proem\IO\Request\Template',
+ $asset->single(
+ function () {
+ return new HTTPRequest;
+ }
+ )
+ )
);
}
}
View
36 lib/Proem/Bootstrap/Filter/Event/Response.php
@@ -30,11 +30,11 @@
*/
namespace Proem\Bootstrap\Filter\Event;
-use Proem\Service\Manager\Template as Manager,
- Proem\Bootstrap\Signal\Event\Bootstrap,
- Proem\Service\Asset\Standard as Asset,
- Proem\IO\Response\Http\Standard as HTTPResponse,
- Proem\Filter\Event\Generic as Event;
+use Proem\Service\Manager\Template as Manager;
+use Proem\Bootstrap\Signal\Event\Bootstrap;
+use Proem\Service\Asset\Standard as Asset;
+use Proem\IO\Response\Http\Standard as HTTPResponse;
+use Proem\Filter\Event\Generic as Event;
/**
* The default "Response" filter event.
@@ -44,9 +44,9 @@ class Response extends Event
/**
* Called prior to inBound.
*
- * A listener responding with an object implementing the
- * Proem\IO\Response\Template interface, will result in that
- * object being placed within the main service manager under
+ * A listener responding with an event containing a DI container holding an
+ * implemention of the Proem\IO\Response\Template interface, will result in
+ * that implementation being placed within the main service manager under
* the index of *response*.
*
* @param Proem\Service\Manager\Template $assets
@@ -57,9 +57,12 @@ public function preIn(Manager $assets)
if ($assets->provides('events', 'Proem\Signal\Manager\Template')) {
$assets->get('events')->trigger(
(new Bootstrap('proem.pre.in.response'))->setServiceManager($assets),
- function($response) use ($assets) {
- if ($response->provides('Proem\IO\Response\Template')) {
- $assets->set('response', $response);
+ function ($response) use ($assets) {
+ if (
+ $response->has('response.asset') &&
+ $response->getParam('response.asset')->provides('Proem\IO\Response\Template')
+ ) {
+ $assets->set('response', $response->getParam('response.asset'));
}
}
);
@@ -81,9 +84,14 @@ public function inBound(Manager $assets)
$asset = new Asset;
$assets->set(
'response',
- $asset->set('Proem\IO\Response\Template', $asset->single(function() {
- return new HTTPResponse;
- }))
+ $asset->set(
+ 'Proem\IO\Response\Template',
+ $asset->single(
+ function () {
+ return new HTTPResponse;
+ }
+ )
+ )
);
}
}
View
114 lib/Proem/Bootstrap/Filter/Event/Route.php
@@ -30,12 +30,12 @@
*/
namespace Proem\Bootstrap\Filter\Event;
-use Proem\Service\Manager\Template as Manager,
- Proem\Bootstrap\Signal\Event\Bootstrap,
- Proem\Service\Asset\Standard as Asset,
- Proem\Routing\Router\Standard as Router,
- Proem\Routing\Route\Standard as StandardRoute,
- Proem\Filter\Event\Generic as Event;
+use Proem\Service\Manager\Template as Manager;
+use Proem\Bootstrap\Signal\Event\Bootstrap;
+use Proem\Service\Asset\Standard as Asset;
+use Proem\Routing\Router\Standard as Router;
+use Proem\Routing\Route\Standard as StandardRoute;
+use Proem\Filter\Event\Generic as Event;
/**
* The default "Route" filter event.
@@ -45,9 +45,9 @@ class Route extends Event
/**
* Called prior to inBound.
*
- * A listener responding with an object implementing the
- * Proem\Routing\Router\Template interface, will result in that
- * object being placed within the main service manager under
+ * A listener responding with an event containing a DI container holding an
+ * implemention of the Proem\Routing\Router\Template interface, will result in
+ * that implementation being placed within the main service manager under
* the index of *router*.
*
* @param Proem\Service\Manager\Template $assets
@@ -58,9 +58,12 @@ public function preIn(Manager $assets)
if ($assets->provides('events', 'Proem\Signal\Manager\Template')) {
$assets->get('events')->trigger(
(new Bootstrap('proem.pre.in.router'))->setServiceManager($assets),
- function($response) use ($assets) {
- if ($response->provides('Proem\Routing\Router\Template')) {
- $assets->set('router', $response);
+ function ($response) use ($assets) {
+ if (
+ $response->has('router.asset') &&
+ $response->getParam('router.asset')->provides('Proem\Routing\Router\Template')
+ ) {
+ $assets->set('router', $response->getParam('router.asset'));
}
}
);
@@ -80,9 +83,14 @@ public function inBound(Manager $assets)
$asset = new Asset;
$assets->set(
'router',
- $asset->set('Proem\Routing\Router\Template', $asset->single(function() use ($assets) {
- return new Router($assets->get('request'));
- }))
+ $asset->set(
+ 'Proem\Routing\Router\Template',
+ $asset->single(
+ function () use ($assets) {
+ return new Router($assets->get('request'));
+ }
+ )
+ )
);
}
}
@@ -102,57 +110,73 @@ public function postIn(Manager $assets)
if ($assets->provides('router', 'Proem\Routing\Router\Template')) {
$assets->get('router')->attach(
'default-module-controller-action-params',
- new StandardRoute([
- 'rule' => '/:module/:controller/:action/:params'
- ])
+ new StandardRoute(
+ [
+ 'rule' => '/:module/:controller/:action/:params'
+ ]
+ )
)
->attach(
'default-module-controller-action-noparams',
- new StandardRoute([
- 'rule' => '/:module/:controller/:action'
- ])
+ new StandardRoute(
+ [
+ 'rule' => '/:module/:controller/:action'
+ ]
+ )
)
->attach(
'default-module-controller-noaction',
- new StandardRoute([
- 'rule' => '/:module/:controller',
- 'targets' => ['action' => 'index']
- ])
+ new StandardRoute(
+ [
+ 'rule' => '/:module/:controller',
+ 'targets' => ['action' => 'index']
+ ]
+ )
)
->attach(
'default-nomodule-controller-action',
- new StandardRoute([
- 'rule' => '/:controller/:action',
- 'targets' => ['module' => 'index']
- ])
+ new StandardRoute(
+ [
+ 'rule' => '/:controller/:action',
+ 'targets' => ['module' => 'index']
+ ]
+ )
)
->attach(
'default-module-nocontroller',
- new StandardRoute([
- 'rule' => '/:module',
- 'targets' => ['controller' => 'index', 'action' => 'index']
- ])
+ new StandardRoute(
+ [
+ 'rule' => '/:module',
+ 'targets' => ['controller' => 'index', 'action' => 'index']
+ ]
+ )
)
->attach(
'default-nomodule-controller',
- new StandardRoute([
- 'rule' => '/:controller',
- 'targets' => ['module' => 'index', 'action' => 'index']
- ])
+ new StandardRoute(
+ [
+ 'rule' => '/:controller',
+ 'targets' => ['module' => 'index', 'action' => 'index']
+ ]
+ )
)
->attach(
'default-nomodule-nocontroller',
- new StandardRoute([
- 'rule' => '/:action',
- 'targets' => ['module' => 'index', 'controller' => 'index']
- ])
+ new StandardRoute(
+ [
+ 'rule' => '/:action',
+ 'targets' => ['module' => 'index', 'controller' => 'index']
+ ]
+ )
)
->attach(
'default-noparams',
- new StandardRoute([
- 'rule' => '/',
- 'targets' => ['module' => 'index', 'controller' => 'index', 'action' => 'index']
- ])
+ new StandardRoute(
+ [
+ 'rule' => '/',
+ 'targets' => ['module' => 'index', 'controller' => 'index', 'action' => 'index']
+ ]
+ )
);
}
}
View
5 lib/Proem/Bootstrap/Signal/Event/Bootstrap.php
@@ -30,8 +30,8 @@
*/
namespace Proem\Bootstrap\Signal\Event;
-use Proem\Service\Manager\Template as Manager,
- Proem\Signal\Event\Standard as StandardEvent;
+use Proem\Service\Manager\Template as Manager;
+use Proem\Signal\Event\Standard as StandardEvent;
/**
* A custom event used by the bootstrap triggered events.
@@ -95,5 +95,4 @@ public function getEnvironment()
{
return $this->environment;
}
-
}
View
24 lib/Proem/Controller/Standard.php
@@ -29,9 +29,9 @@
*/
namespace Proem\Controller;
-use Proem\Controller\Template as ControllerTemplate,
- Proem\Bootstrap\Signal\Event\Bootstrap as Bootstrap,
- Proem\Service\Manager\Template as ServiceManager;
+use Proem\Controller\Template as ControllerTemplate;
+use Proem\Bootstrap\Signal\Event\Bootstrap as Bootstrap;
+use Proem\Service\Manager\Template as ServiceManager;
/**
* The standard controller implementation.
@@ -53,7 +53,7 @@ class Standard implements ControllerTemplate
*
* @param Proem\Service\Manager\Template
*/
- public final function __construct(ServiceManager $assets)
+ final public function __construct(ServiceManager $assets)
{
$this->assets = $assets;
$this->init();
@@ -69,18 +69,20 @@ public function init()
/**
* Metod called to dispatch an action.
*/
- public function dispatch($action) {
- $action = strtolower($action);
-
+ public function dispatch($action)
+ {
if ($this->assets->provides('events', '\Proem\Signal\Manager\Template')) {
- $this->assets->get('events')->trigger((new Bootstrap('proem.pre.action.' . $action))->setServiceManager($this->assets));
+ $this->assets->get('events')->trigger(
+ (new Bootstrap('proem.pre.action.' . $action))->setServiceManager($this->assets)
+ );
}
- $method = $action . 'Action';
- $result = $this->{$method}();
+ $result = $this->{$action}();
if ($this->assets->provides('events', '\Proem\Signal\Manager\Template')) {
- $this->assets->get('events')->trigger((new Bootstrap('proem.post.action.' . $action))->setServiceManager($this->assets));
+ $this->assets->get('events')->trigger(
+ (new Bootstrap('proem.post.action.' . $action))->setServiceManager($this->assets)
+ );
}
return $result;
View
25 lib/Proem/Dispatch/Stage.php
@@ -29,10 +29,10 @@
*/
namespace Proem\Dispatch;
-use Proem\Service\Manager\Template as Manager,
- Proem\Routing\Signal\Event\RouteMatch,
- Proem\Routing\Signal\Event\RouteDispatch,
- Proem\Routing\Signal\Event\RouteExhausted;
+use Proem\Service\Manager\Template as Manager;
+use Proem\Routing\Signal\Event\RouteMatch;
+use Proem\Routing\Signal\Event\RouteDispatch;
+use Proem\Routing\Signal\Event\RouteExhausted;
/**
* The dispatch stage.
@@ -131,8 +131,8 @@ protected function processRoutes()
while ($payload = $router->route()) {
$assets->get('events')->trigger(
(new RouteMatch('proem.route.match'))->setPayload($payload),
- function($e) use (&$dispatched, &$assets) {
- if ($e) {
+ function ($response) use (&$dispatched, &$assets) {
+ if ($response->has('isDispatchable') && $response->getParam('isDispatchable')) {
$dispatched = true;
$assets->get('events')->trigger(new RouteDispatch('proem.route.dispatch'));
}
@@ -168,12 +168,17 @@ public function dispatch($e)
* @param Proem\Routing\Signal\Event\RouteMatch $e
* @return bool
*/
- public function testRoute($e)
+ public function testRoute($event)
{
if ($this->assets->has('dispatch')) {
- return $this->assets->get('dispatch')
- ->setPayload($e->getPayload())
- ->isDispatchable();
+ $this->assets->get('dispatch')->setPayload($event->getPayload());
+ $this->assets->get('dispatch')->setModule($event->getPayload()->get('module', ''));
+ $this->assets->get('dispatch')->setController($event->getPayload()->get('controller', ''));
+ $this->assets->get('dispatch')->setAction($event->getPayload()->get('action', ''));
+ return $event->setParam(
+ 'isDispatchable',
+ $this->assets->get('dispatch')->isDispatchable()
+ );
}
}
View
149 lib/Proem/Dispatch/Standard.php
@@ -29,9 +29,10 @@
*/
namespace Proem\Dispatch;
-use Proem\Dispatch\Template as Template,
- Proem\Service\Manager\Template as Manager,
- Proem\Routing\Route\Payload as Payload;
+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
@@ -39,6 +40,18 @@
class Standard implements Template
{
/**
+ * Priorities
+ */
+ const DEFAULT_CONTROLLERMAP_PRIORITY = 0;
+
+ /**
+ * Placeholders
+ */
+ const MODULE_PLACEHOLDER = '{:module}';
+ const CONTROLLER_PLACEHOLDER = '{:controller}';
+ const ACTION_PLACEHOLDER = '{:action}';
+
+ /**
* Store the Assets manager
*
* @var Proem\Service\Manager\Template
@@ -49,9 +62,19 @@ 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;
+
+ /**
+ * Store the *action map* pattern.
*/
- protected $controllerMaps = [];
+ protected $actionMap;
/**
* Store the absolute namespace to the current class
@@ -96,7 +119,12 @@ 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\\' . self::MODULE_PLACEHOLDER . '\Controller\\' . self::CONTROLLER_PLACEHOLDER,
+ self::DEFAULT_CONTROLLERMAP_PRIORITY
+ );
+ $this->actionMap = self::ACTION_PLACEHOLDER . 'Action';
}
/**
@@ -112,22 +140,103 @@ public function setPayload(Payload $payload)
}
/**
+ * Set the current module
+ *
+ * @param string $module
+ */
+ public function setModule($module)
+ {
+ $this->module = $module;
+ return $this;
+ }
+
+ /**
+ * Get the current module
+ */
+ public function getModule()
+ {
+ return $this->module;
+ }
+
+ /**
+ * Set the current controller
+ *
+ * @param string $controller
+ */
+ public function setController($controller)
+ {
+ $this->controller = $controller;
+ return $this;
+ }
+
+ /**
+ * Get the current controller
+ */
+ public function getController()
+ {
+ return $this->controller;
+ }
+
+ /**
+ * Set the current action
+ *
+ * @param string $action
+ */
+ public function setAction($action)
+ {
+ $this->action = $action;
+ return $this;
+ }
+
+ /**
+ * Get the current action
+ */
+ public function getAction()
+ {
+ return str_replace(self::ACTION_PLACEHOLDER, strtolower($this->action), $this->actionMap);
+ }
+
+ /**
* Add a new controller map onto the stack of controller
* maps.
*
* 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}' where
+ * {:module} and {:controller} are respectfully replaced by data provided by the payload.
+ *
+ * This controller map is injected with a priority of 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
+ * @param int $priority
* @return Proem\Dispatch\Template
*/
- public function attachControllerMap($map) {
- $this->controllerMaps[] = $map;
+ public function attachControllerMap($map, $priority = self::DEFAULT_CONTROLLERMAP_PRIORITY)
+ {
+ $this->controllerMaps->insert($map, $priority);
+ return $this;
+ }
+
+ /**
+ * Allows the customisation of the *action map*.
+ *
+ * The default implementation looks like {:action}Action
+ *
+ * {:action} gets replaced by the action returning from the
+ * router.
+ *
+ * @param string $mapping
+ */
+ public function setActionMap($mapping)
+ {
+ $this->actionMap = $mapping;
return $this;
}
@@ -145,27 +254,25 @@ public function attachControllerMap($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->controllerMaps as $map) {
$this->class = str_replace(
- [':module', ':controller'],
+ [self::MODULE_PLACEHOLDER, self::CONTROLLER_PLACEHOLDER],
[$this->module, $this->controller],
$map
);
- if (class_exists($this->class)) {
- $this->class = new $this->class($this->assets);
- if ($this->class instanceof \Proem\Controller\Template) {
- if (is_callable([$this->class, $this->action . 'Action'])) {
+ try {
+ $class = new \ReflectionClass($this->class);
+ if ($class->implementsInterface('\Proem\Controller\Template')) {
+ $method = $class->getMethod($this->getAction());
+ if ($method->isPublic()) {
return true;
}
}
+ } catch (\ReflectionException $e) {
+ // The next controllerMap might still succeed.
}
}
-
return false;
}
@@ -187,7 +294,9 @@ public function dispatch()
if ($this->assets->has('request')) {
$this->assets->get('request')->injectPayload($this->payload->prepare());
}
- $this->class->dispatch($this->action);
+
+ $this->class = new $this->class($this->assets);
+ $this->class->dispatch($this->getAction());
return $this;
}
}
View
4 lib/Proem/Dispatch/Template.php
@@ -29,8 +29,8 @@
*/
namespace Proem\Dispatch;
-use Proem\Service\Manager\Template as Manager,
- Proem\Routing\Route\Payload as Payload;
+use Proem\Service\Manager\Template as Manager;
+use Proem\Routing\Route\Payload as Payload;
/**
* Interface all dispatcher must implement.
View
6 lib/Proem/Ext/Module/Generic.php
@@ -30,8 +30,8 @@
*/
namespace Proem\Ext\Module;
-use Proem\Ext\Template,
- Proem\Service\Manager\Template as Manager;
+use Proem\Ext\Template;
+use Proem\Service\Manager\Template as Manager;
/**
* A base Module abstract.
@@ -44,5 +44,5 @@
* @param Proem\Service\Manager\Template $assets
* @param string $environment
*/
- public abstract function init(Manager $assets, $environment = null);
+ abstract public function init(Manager $assets, $environment = null);
}
View
6 lib/Proem/Ext/Plugin/Generic.php
@@ -30,8 +30,8 @@
*/
namespace Proem\Ext\Plugin;
-use Proem\Ext\Template,
- Proem\Service\Manager\Template as Manager;
+use Proem\Ext\Template;
+use Proem\Service\Manager\Template as Manager;
/**
* A base Plugin sbstract.
@@ -44,5 +44,5 @@
* @param Proem\Service\Manager\Template $assets
* @param string $environment
*/
- public abstract function init(Manager $assets, $environment = null);
+ abstract public function init(Manager $assets, $environment = null);
}
View
26 lib/Proem/Filter/Event/Generic.php
@@ -30,9 +30,9 @@
*/
namespace Proem\Filter\Event;
-use Proem\Filter\Manager\Standard as FilterManager,
- Proem\Service\Manager\Template as ServiceManager,
- Proem\Filter\Event\Template as Template;
+use Proem\Filter\Manager\Standard as FilterManager;
+use Proem\Service\Manager\Template as ServiceManager;
+use Proem\Filter\Event\Template as Template;
/**
* Filter event abstract
@@ -49,42 +49,50 @@
*
* @param Proem\Service\Manager\Template $assets
*/
- public function preIn(ServiceManager $assets) {}
+ public function preIn(ServiceManager $assets)
+ {
+ }
/**
* Define the method to be called on the way into the filter.
*
* @param Proem\Service\Manager\Template $assets
*/
- public abstract function inBound(ServiceManager $assets);
+ abstract public function inBound(ServiceManager $assets);
/**
* Called after inBound
*
* @param Proem\Service\Manager\Template $assets
*/
- public function postIn(ServiceManager $assets) {}
+ public function postIn(ServiceManager $assets)
+ {
+ }
/**
* Called prior outBound
*
* @param Proem\Service\Manager\Template $assets
*/
- public function preOut(ServiceManager $assets) {}
+ public function preOut(ServiceManager $assets)
+ {
+ }
/**
* Define the method to be called on the way out of the filter.
*
* @param Proem\Service\Manager\Template $assets
*/
- public abstract function outBound(ServiceManager $assets);
+ abstract public function outBound(ServiceManager $assets);
/**
* Called after outBound
*
* @param Proem\Service\Manager\Template $assets
*/
- public function postOut(ServiceManager $assets) {}
+ public function postOut(ServiceManager $assets)
+ {
+ }
/**
* Execute this event.
View
9 lib/Proem/Filter/Manager/Standard.php
@@ -30,10 +30,10 @@
*/
namespace Proem\Filter\Manager;
-use Proem\Filter\Event\Template as Event,
- Proem\Util\Storage\Queue,
- Proem\Service\Manager\Template as ServiceManager,
- Proem\Filter\Manager\Template;
+use Proem\Filter\Event\Template as Event;
+use Proem\Util\Storage\Queue;
+use Proem\Service\Manager\Template as ServiceManager;
+use Proem\Filter\Manager\Template;
/**
* The standard filter manager.
@@ -143,5 +143,4 @@ public function init()
{
return $this->getInitialEvent()->init($this);
}
-
}
View
6 lib/Proem/Filter/Manager/Template.php
@@ -30,9 +30,9 @@
*/
namespace Proem\Filter\Manager;
-use Proem\Filter\Event\Template as Event,
- Proem\Util\Storage\Queue,
- Proem\Service\Manager\Template as ServiceManager;
+use Proem\Filter\Event\Template as Event;
+use Proem\Util\Storage\Queue;
+use Proem\Service\Manager\Template as ServiceManager;
/**
* Interface that service managers must implement.
View
22 lib/Proem/IO/Request/Http/Fake.php
@@ -35,8 +35,8 @@
*/
namespace Proem\IO\Request\Http;
-use Proem\IO\Request\Template,
- Proem\Util\Storage\KeyValStore;
+use Proem\IO\Request\Template;
+use Proem\Util\Storage\KeyValStore;
/**
* A fake http request implementation.
@@ -109,6 +109,7 @@ public function __construct($uri, $method = 'GET', $body = '', $param = [], $coo
case 'PUT':
case 'DELETE':
$defaults['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
+ // Allow this condition to fall through.
case 'PATCH':
$post = $param;
$get = [];
@@ -132,12 +133,16 @@ public function __construct($uri, $method = 'GET', $body = '', $param = [], $coo
$uri = $components['path'] . ($getString ? '?' . $getString : '');
- $meta = array_replace($defaults, $meta, [
- 'REQUEST_METHOD' => strtoupper($method),
- 'PATH_INFO' => '',
- 'REQUEST_URI' => $uri,
- 'QUERY_STRING' => $getString,
- ]);
+ $meta = array_replace(
+ $defaults,
+ $meta,
+ [
+ 'REQUEST_METHOD' => strtoupper($method),
+ 'PATH_INFO' => '',
+ 'REQUEST_URI' => $uri,
+ 'QUERY_STRING' => $getString
+ ]
+ );
$this->body = $body;
@@ -151,5 +156,4 @@ public function __construct($uri, $method = 'GET', $body = '', $param = [], $coo
'header' => new KeyValStore($this->formHeaders($meta))
];
}
-
}
View
14 lib/Proem/IO/Request/Http/Standard.php
@@ -30,8 +30,8 @@
*/
namespace Proem\IO\Request\Http;
-use Proem\IO\Request\Template,
- Proem\Util\Storage\KeyValStore;
+use Proem\IO\Request\Template;
+use Proem\Util\Storage\KeyValStore;
/**
* The standard http request class.
@@ -82,7 +82,8 @@ class Standard implements Template
*
* @param Proem\Util\Storage\KeyValStore
*/
- public function __construct(KeyValStore $payload = null) {
+ public function __construct(KeyValStore $payload = null)
+ {
$this->data = [
'payload' => $payload,
'get' => new KeyValStore($_GET),
@@ -255,7 +256,8 @@ public function isPost()
*
* @return bool
*/
- public function isAjax() {
+ public function isAjax()
+ {
return $this->data['header']->get('X_REQUESTED_WITH') === 'XMLHttpRequest';
}
@@ -264,7 +266,8 @@ public function isAjax() {
*
* @return string
*/
- public function getRequestUri() {
+ public function getRequestUri()
+ {
return parse_url($this->data['meta']->get('REQUEST_URI'), PHP_URL_PATH);
}
@@ -296,5 +299,4 @@ public function getClientIp()
return $this->data['meta']->get('REMOTE_ADDR');
}
-
}
View
1  lib/Proem/IO/Request/Template.php
@@ -41,5 +41,4 @@
* @param bool $raw
*/
public function getBody($raw = true);
-
}
View
15 lib/Proem/IO/Response/Http/Standard.php
@@ -30,8 +30,8 @@
*/
namespace Proem\IO\Response\Http;
-use Proem\IO\Response\Template,
- Proem\Util\Storage\KeyValStore;
+use Proem\IO\Response\Template;
+use Proem\Util\Storage\KeyValStore;
/**
* A standard http response implementation.
@@ -127,7 +127,7 @@ class Standard implements Template
public function __construct()
{
$this->headers = new KeyValStore;
- $this->headers->set('X-Powered-By','Proem Framework ' . \Proem\Proem::VERSION);
+ $this->headers->set('X-Powered-By', 'Proem Framework ' . \Proem\Proem::VERSION);
}
/**
@@ -155,7 +155,7 @@ public function silence()
*/
public function setHttpVersion($version)
{
- if (in_array($version, [1.0,1.1])) {
+ if (in_array($version, [1.0, 1.1])) {
$this->httpVersion = $version;
}
return $this;
@@ -294,14 +294,14 @@ public function getContentLength()
*
* @param bool $include_content_length Optionaly disable the Content-Length header.
*/
- public function sendHeaders($include_content_length = true)
+ public function sendHeaders($include_content_length = false)
{
if (headers_sent()) {
return;
}
if ($include_content_length) {
- $this->headers->set('Content-Length', $this->length);
+ //$this->headers->set('Content-Length', $this->length);
}
if (in_array($this->httpStatus, [204, 304])) {
@@ -326,9 +326,8 @@ public function send($include_content_length = true)
{
$this->sendHeaders($include_content_length);
- if (( $this->httpStatus < 100 || $this->httpStatus >= 200 ) && $this->httpStatus != 204 && $this->httpStatus != 304) {
+ if (($this->httpStatus < 100 || $this->httpStatus >= 200) && !in_array($this->httpStatus, [204, 304])) {
echo $this->body;
}
}
-
}
View
1  lib/Proem/IO/Response/Template.php
@@ -68,5 +68,4 @@ public function getBody();
* This method should first send any headers and then the request body.
*/
public function send();
-
}
View
59 lib/Proem/Proem.php
@@ -29,18 +29,18 @@
*/
namespace Proem;
-use Proem\Service\Manager\Standard as ServiceManager,
- Proem\Signal\Manager\Standard as SignalManager,
- Proem\Filter\Manager\Standard as FilterManager,
- Proem\Service\Asset\Standard as Asset,
- Proem\Bootstrap\Filter\Event\Dispatch,
- Proem\Bootstrap\Filter\Event\Response,
- Proem\Bootstrap\Filter\Event\Request,
- Proem\Bootstrap\Filter\Event\Route,
- Proem\Bootstrap\Signal\Event\Bootstrap,
- Proem\Ext\Template as Extension,
- Proem\Ext\Module\Generic as Module,
- Proem\Ext\Plugin\Generic as Plugin;
+use Proem\Service\Manager\Standard as ServiceManager;
+use Proem\Signal\Manager\Standard as SignalManager;
+use Proem\Filter\Manager\Standard as FilterManager;
+use Proem\Service\Asset\Standard as Asset;
+use Proem\Bootstrap\Filter\Event\Dispatch;
+use Proem\Bootstrap\Filter\Event\Response;
+use Proem\Bootstrap\Filter\Event\Request;
+use Proem\Bootstrap\Filter\Event\Route;
+use Proem\Bootstrap\Signal\Event\Bootstrap;
+use Proem\Ext\Template as Extension;
+use Proem\Ext\Module\Generic as Module;
+use Proem\Ext\Plugin\Generic as Plugin;
/**
* The Proem boostrap wrapper
@@ -52,7 +52,7 @@ class Proem
/**
* Store the framework version
*/
- const VERSION = '0.6.5';
+ const VERSION = '0.7.0';
/**
* Store events
@@ -81,9 +81,14 @@ class Proem
public function __construct()
{
$this->events = new Asset;
- $this->events->set('Proem\Signal\Manager\Template', $this->events->single(function($asset) {
- return new SignalManager;
- }));
+ $this->events->set(
+ 'Proem\Signal\Manager\Template',
+ $this->events->single(
+ function ($asset) {
+ return new SignalManager;
+ }
+ )
+ );
$this->serviceManager = new ServiceManager;
}
@@ -100,10 +105,13 @@ public function __construct()
*/
protected function attachExtension(Extension $extension, $event = 'proem.init', $priority = 0)
{
- $this->attachEventListener($event, function($e) use ($extension) {
- $extension->init($e->getServiceManager(), $e->getEnvironment());
- }, $priority);
-
+ $this->attachEventListener(
+ $event,
+ function ($e) use ($extension) {
+ $extension->init($e->getServiceManager(), $e->getEnvironment());
+ },
+ $priority
+ );
return $this;
}
@@ -112,7 +120,7 @@ protected function attachExtension(Extension $extension, $event = 'proem.init',
*
* @param string $name The name of the event.
* @param callable $callback The callback that will be executed when the event is triggered.
- * @param int $priority The priority that this listenever will have above other listeners attached to this same event.
+ * @param int $priority The priority that this listenever will have above other listeners attached to this event.
*
* @return Proem\Proem
*/
@@ -175,9 +183,12 @@ public function init($environment = null)
$this->events->get()->trigger(
(new Bootstrap('proem.init'))->setServiceManager($this->serviceManager)->setEnvironment($environment),
- function($response) {
- if ($response instanceof Proem\Filter\Manager\Template) {
- $this->filterManager = $response;
+ function ($response) {
+ if (
+ $response->has('filterManager.asset') &&
+ $response->getParam('filterManager.asset')->provides('Proem\Filter\Manager\Template')
+ ) {
+ $this->filterManager = $response->getParam('filterManager.asset');
}
}
);
View
28 lib/Proem/Routing/Route/Generic.php
@@ -30,11 +30,11 @@
*/
namespace Proem\Routing\Route;
-use Proem\Routing\Route\Payload,
- Proem\Util\ArrayHelper,
- Proem\Util\Process\Callback,
- Proem\IO\Request\Template as Request,
- Proem\Routing\Route\Template;
+use Proem\Routing\Route\Payload;
+use Proem\Util\ArrayHelper;
+use Proem\Util\Process\Callback;
+use Proem\IO\Request\Template as Request;
+use Proem\Routing\Route\Template;
/**
* Generic route abstract.
@@ -137,6 +137,23 @@ public function getPayload()
}
/**
+ * A generic testMethod function used to test a route
+ * against a request type.
+ *
+ * This should be called within any process() method
+ */
+ public function testRequestMethod(Request $request)
+ {
+ $method = isset($this->options['method']) ? $this->options['method'] : false;
+ $requestMethod = $request->getMethod();
+ if ($method && (strtoupper($method) !== strtoupper($requestMethod))) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
* Method used to execute a route callback.
*
* @param Proem\IO\Request\Template $request
@@ -156,5 +173,4 @@ public function call(Request $request)
* @param Proem\IO\Request\Template $request
*/
abstract public function process(Request $request);
-
}
View
34 lib/Proem/Routing/Route/Standard.php
@@ -30,9 +30,9 @@
*/
namespace Proem\Routing\Route;
-use Proem\Routing\Route\Template,
- Proem\Routing\Route\Generic,
- Proem\IO\Request\Template as Request;
+use Proem\Routing\Route\Template;
+use Proem\Routing\Route\Generic;
+use Proem\IO\Request\Template as Request;
/**
* Proem's standard route.
@@ -61,7 +61,8 @@ class Standard extends Generic
*
* @param array $options Array of Proem\Utils\Option objects
*/
- public function __construct(array $options) {
+ public function __construct(array $options)
+ {
parent::__construct($options);
$this->default_filters = [
@@ -113,16 +114,13 @@ public function process(Request $request)
return false;
}
+ if (!$this->testRequestMethod($request)) {
+ return false;
+ }
+
$rule = $this->options['rule'];
$target = isset($this->options['targets']) ? $this->options['targets'] : [];
$custom_filters = isset($this->options['filters']) ? $this->options['filters'] : [];
- $method = isset($this->options['method']) ? $this->options['method'] : false;
-
- $requestMethod = $request->getMethod();
-
- if ($method && (strtoupper($method) !== strtoupper($requestMethod))) {
- return false;
- }
$default_tokens = $this->default_tokens;
$default_filters = $this->default_filters;
@@ -137,16 +135,22 @@ public function process(Request $request)
$regex = preg_replace_callback(
'@:[\w]+@',
- function($matches) use ($custom_filters, $default_tokens, $default_filters)
- {
+ function ($matches) use ($custom_filters, $default_tokens, $default_filters) {
$key = str_replace(':', '', $matches[0]);
if (isset($custom_filters[$key])) {
if (isset($default_filters[$custom_filters[$key]])) {
return '(' . $default_filters[$custom_filters[$key]] . ')';
} else {
- return '(' . $custom_filters[$key] . ')';
+ if ($custom_filters[$key]{0} == ':') {
+ throw new \RuntimeException(
+ "The custom filter named \"{$key}\" references a
+ non-existent builtin filter named \"{$custom_filters[$key]}\"."
+ );
+ } else {
+ return '(' . $custom_filters[$key] . ')';
+ }
}
- } else if (isset($default_tokens[$key])) {
+ } elseif (isset($default_tokens[$key])) {
return '(' . $default_tokens[$key] . ')';
} else {
return '(' . $default_filters[':default'] . ')';
View
20 lib/Proem/Routing/Route/StaticRoute.php
@@ -30,9 +30,9 @@
*/
namespace Proem\Routing\Route;
-use Proem\Routing\Route\Template,
- Proem\Routing\Route\Generic,
- Proem\IO\Request\Template as Request;
+use Proem\Routing\Route\Template;
+use Proem\Routing\Route\Generic;
+use Proem\IO\Request\Template as Request;
/**
* A simple static route.
@@ -45,13 +45,19 @@ public function process(Request $request)
return false;
}
- $method = isset($this->options['method']) ? $this->options['method'] : 'GET';
-
- if (!isset($this->options['targets']) || !isset($this->options['targets']['module']) || !isset($this->options['targets']['controller']) || !isset($this->options['targets']['action'])) {
+ if (!$this->testRequestMethod($request)) {
return false;
}
- if ($request->getRequestUri() == $this->options['rule'] && $request->getMethod() == $method) {
+ switch (true) {
+ case !isset($this->options['targets']):
+ case !isset($this->options['targets']['module']):
+ case !isset($this->options['targets']['controller']):
+ case !isset($this->options['targets']['action']):
+ return false;
+ }
+
+ if ($request->getRequestUri() == $this->options['rule']) {
$this->getPayload()->set('module', $this->options['targets']['module']);
$this->getPayload()->set('controller', $this->options['targets']['controller']);
$this->getPayload()->set('action', $this->options['targets']['action']);
View
1  lib/Proem/Routing/Route/Template.php
@@ -50,5 +50,4 @@ public function process(Request $request);
* @param Proem\IO\Request\Template $request
*/
public function call(Request $request);
-
}
View
11 lib/Proem/Routing/Router/Standard.php
@@ -30,11 +30,11 @@
*/
namespace Proem\Routing\Router;
-use Proem\Routing\Router\Template,
- Proem\Routing\Route\Template as Route,
- Proem\IO\Request\Template as Request,
- Proem\Signal\Manager\Template as SignalManager,
- Proem\Util\Storage\KeyValStore;
+use Proem\Routing\Router\Template;
+use Proem\Routing\Route\Template as Route;
+use Proem\IO\Request\Template as Request;
+use Proem\Signal\Manager\Template as SignalManager;
+use Proem\Util\Storage\KeyValStore;
/**
* The standard router.
@@ -110,5 +110,4 @@ public function route()
$this->routes->rewind();
return false;
}
-
}
View
1  lib/Proem/Routing/Router/Template.php
@@ -57,5 +57,4 @@ public function attach($name, Route $route);
* again.
*/
public function route();
-
}
View
4 lib/Proem/Routing/Signal/Event/RouteDispatch.php
@@ -30,8 +30,8 @@
*/
namespace Proem\Routing\Signal\Event;
-use Proem\Signal\Event\Standard,
- Proem\Routing\Route\Payload;
+use Proem\Signal\Event\Standard;
+use Proem\Routing\Route\Payload;
/**
* Proem\Routing\Signal\Event\RouteDispatch
View
4 lib/Proem/Routing/Signal/Event/RouteExhausted.php
@@ -30,8 +30,8 @@
*/
namespace Proem\Routing\Signal\Event;
-use Proem\Signal\Event\Standard,
- Proem\Routing\Route\Payload;
+use Proem\Signal\Event\Standard;
+use Proem\Routing\Route\Payload;
/**
* Proem\Routing\Signal\Event\RouteExhausted
View
4 lib/Proem/Routing/Signal/Event/RouteMatch.php
@@ -30,8 +30,8 @@
*/
namespace Proem\Routing\Signal\Event;
-use Proem\Signal\Event\Standard,
- Proem\Routing\Route\Payload;
+use Proem\Signal\Event\Standard;
+use Proem\Routing\Route\Payload;
/**
* A custom event used by the router to communicate matching routes
View
19 lib/Proem/Service/Asset/Standard.php
@@ -30,8 +30,8 @@
*/
namespace Proem\Service\Asset;
-use Proem\Service\Asset\Template,
- Proem\Service\Manager\Template as Manager;
+use Proem\Service\Asset\Template;
+use Proem\Service\Manager\Template as Manager;
/**
* Standard asset container.
@@ -80,7 +80,13 @@ protected function validate($object)
return $object;
}
- throw new \DomainException(sprintf("The Asset providing %s actually provides a %s object", $this->provides, get_class($object)));
+ throw new \DomainException(
+ sprintf(
+ "The Asset providing %s actually provides a %s object",
+ $this->provides,
+ get_class($object)
+ )
+ );
}
/**
@@ -113,7 +119,8 @@ public function setParam($index, $value)
* @param mixed $value
* @return Proem\Service\Asset\Template
*/
- public function __set($index, $value) {
+ public function __set($index, $value)
+ {
return $this->setParam($index, $value);
}
@@ -144,7 +151,8 @@ public function getParam($index)
*
* @param string $index
*/
- public function __get($index) {
+ public function __get($index)
+ {
return $this->getParam($index);
}
@@ -224,5 +232,4 @@ public function single(\Closure $closure)
return $obj;
};
}
-
}
View
1  lib/Proem/Service/Asset/Template.php
@@ -103,5 +103,4 @@ public function __invoke();
* @param closure $closure
*/
public function single(\Closure $closure);
-
}
View
5 lib/Proem/Service/Manager/Standard.php
@@ -30,8 +30,8 @@
*/
namespace Proem\Service\Manager;
-use Proem\Service\Manager\Template,
- Proem\Service\Asset\Template as Asset;
+use Proem\Service\Manager\Template;
+use Proem\Service\Asset\Template as Asset;
/**
* A registry of assets.
@@ -183,5 +183,4 @@ public function getProvided($provides)
}
}
}
-
}
View
1  lib/Proem/Service/Manager/Template.php
@@ -104,5 +104,4 @@ public function provides($index, $provides = null);
* @return object
*/
public function getProvided($provides);
-
}
View
64 lib/Proem/Signal/Event/Standard.php
@@ -30,9 +30,7 @@
*/
namespace Proem\Signal\Event;
-use Proem\Util\Opt\Options,
- Proem\Util\Opt\Option,
- Proem\Signal\Event\Template;
+use Proem\Signal\Event\Template;
/**
* The standard event implementation
@@ -40,6 +38,20 @@
class Standard implements Template
{
/**
+ * Halted queue flag
+ *
+ * @var bool
+ */
+ protected $haltedQueue = false;
+
+ /**
+ * Halt the queue *early* flag.
+ *
+ * @var bool
+ */
+ protected $haltedQueueEarly = false;
+
+ /**
* Store params
*
* @var array
@@ -62,6 +74,37 @@ public function __construct($name)
}
/**
+ * Set the halt queue flag to true
+ *
+ * @param bool $early If true, the queue will be halted prior to the triggers callback being executed
+ */
+ public function haltQueue($early = false)
+ {
+ if ($early) {
+ $this->haltedQueueEarly = true;
+ }
+
+ $this->haltedQueue = true;
+ return $this;
+ }
+
+ /**
+ * Check to see if the haltedQueueEarly flag is true
+ */
+ public function isQueueHaltedEarly()
+ {
+ return $this->haltedQueueEarly;
+ }
+
+ /**
+ * Check to see if the haltedQueue flag is true
+ */
+ public function isQueueHalted()
+ {
+ return $this->haltedQueue;
+ }
+
+ /**
* Set a param
*
* @param string $index
@@ -79,11 +122,23 @@ public function setParam($index, $value)
*
* @return mixed
*/
- public function getParam($index)
+ public function getParam($index, $default = null)
{
if (isset($this->params[$index])) {
return $this->params[$index];
}
+
+ return $default;
+ }
+
+ /**
+ * Check for the existance of a parameter.
+ *
+ * @return bool
+ */
+ public function has($index)
+ {
+ return isset($this->params[$index]);
}
/**
@@ -131,5 +186,4 @@ public function getName()
{
return $this->name;
}
-
}
View
46 lib/Proem/Signal/Event/Template.php
@@ -30,9 +30,6 @@
*/
namespace Proem\Signal\Event;
-use Proem\Util\Opt\Options,
- Proem\Util\Opt\Option;
-
/**
* Interface that all events must implement.
*/
@@ -44,6 +41,48 @@
public function __construct($name);
/**
+ * Set the halt queue flag to true
+ *
+ * @param bool $early If true, the queue will be halted prior to the triggers callback being executed
+ */
+ public function haltQueue($early);
+
+ /**
+ * Check to see if the haltedQueueEarly flag is true
+ */
+ public function isQueueHaltedEarly();
+
+ /**
+ * Check to see if the haltedQueue flag is true
+ */
+ public function isQueueHalted();
+
+ /**
+ * Set a param
+ *
+ * @param string $key
+ * @param mixed $param
+ * @return Proem\Signal\Event\Template
+ */
+ public function setParam($key, $param);
+
+ /**
+ * Retrieve a parameter (or some default value) by key
+ *
+ * @param string $key
+ * @param mixed $default Default value returned if $key does not exist
+ * @return mixed
+ */
+ public function getParam($key, $default);
+
+ /**
+ * Check for the existance of a parameter.
+ *
+ * @return bool
+ */
+ public function has($index);
+
+ /**
* Set params
*
* @param array $params
@@ -74,5 +113,4 @@ public function setName($name);
* @return string The name of the triggered event.
*/
public function getName();
-
}
View
202 lib/Proem/Signal/Manager/Standard.php
@@ -30,10 +30,11 @@
*/
namespace Proem\Signal\Manager;
-use Proem\Util\Storage\Queue,
- Proem\Util\Process\Callback,
- Proem\Signal\Event\Standard as Event,
- Proem\Signal\Manager\Template;
+use Proem\Util\Storage\Queue;
+use Proem\Util\Process\Callback;
+use Proem\Util\Process\EventCallback;
+use Proem\Signal\Event\Template as EventInterface;
+use Proem\Signal\Manager\Template;
/**
* Standard event manager implementation.
@@ -46,7 +47,7 @@ class Standard implements Template
/**
* Wildcard used when listening for all events
*/
- const WILDCARD = '*';
+ const WILDCARD = '.*';
/**
* Stores listeners in a hash of priority queues.
@@ -63,6 +64,89 @@ class Standard implements Template
protected $callbacks = [];
/**
+ * Store a flag regarding searching for wildcards
+ */
+ protected $wildcardSearching = false;
+
+ /**
+ * Given an event name, this method searches for all possible
+ * wildcard matches in the queues. When/If a match is found
+ * it will then copy it's key and priority from the wildcards
+ * queue into the named event's queue.
+ *
+ * @param $name The event name
+ * @return bool True if match is found
+ */
+ protected function populateQueueFromWildSearch($name)
+ {
+ $listenerMatched = false;
+ $parts = explode('.', $name);
+ while (count($parts)) {
+ array_pop($parts);
+ $part = implode('.', $parts) . self::WILDCARD;
+
+ if (isset($this->queues[$part])) {
+ $listenerMatched = true;
+ /**
+ * Add to currently named queue
+ */
+ foreach ($this->queues[$part] as $listener) {
+ if (isset($this->queues[$name])) {
+ $this->queues[$name]->insert($listener['key'], $listener['priority']);
+ } else {
+ $this->queues[$name] = new Queue;
+ $this->queues[$name]->insert($listener['key'], $listener['priority']);
+ }
+ }
+ }
+ }
+
+ return $listenerMatched;
+ }
+
+ /**
+ * Store a callback index by a generated key
+ *
+ * @param callable $callback
+ * @return string $key
+ */
+ protected function storeCallback(callable $callback)
+ {
+ $key = md5(microtime());
+ $this->callbacks[$key] = $callback;
+ return $key;
+ }
+
+ /**
+ * Store a callback's key and priority in a queue indexed
+ * by the event they are attached to.
+ *
+ * @param $event The name of the event this callback is being attached to
+ * @param string $key The key the callback is stored under
+ * @priority The priority this callback has within this queue
+ */
+ protected function pushToQueue($event, $key, $priority)
+ {
+ $end = substr($event, -2);
+ if (isset($this->queues[$event])) {
+ if ($end == self::WILDCARD) {
+ $this->wildcardSearching = true;
+ $this->queues[$event][] = ['key' => $key, 'priority' => $priority];
+ } else {
+ $this->queues[$event]->insert($key, $priority);
+ }
+ } else {
+ if ($end == self::WILDCARD) {
+ $this->wildcardSearching = true;
+ $this->queues[$event][] = ['key' => $key, 'priority' => $priority];
+ } else {
+ $this->queues[$event] = new Queue;
+ $this->queues[$event]->insert($key, $priority);
+ }
+ }
+ }
+
+ /**
* Remove event listeners from a particular index.
*