Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 5 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 30, 2012
@trq Moving the instantiation of a controller into the Dispatch objects
dispatch() method.

This meens that isDispatchable() now uses reflection to run it's tests.

Fixes #126
2bf3437
Commits on Sep 03, 2012
@trq Fixing the request type filter on the Static Route.
This change also moves the code required to do the request type check
into a more common location within the Generic abstract.

Fixes #125
dc7a1d8
Commits on Sep 08, 2012
@trq Allow namespace paths to include the actual vendor name.
eg;

$autoloader->attachNamespace('Module', __DIR__ . '/module', true);

Instead of:

$autoloader->attachNamespace('Module', __DIR__);
f3d110d
@trq Remove request method check. This is now handled elsewhere. 787bae7
@trq Controller maps are now processed FIFO. ccb6d01
View
9 lib/Proem/Autoloader.php
@@ -72,7 +72,7 @@ public function __construct($loadProem = true)
}
if ($loadProem) {
- $this->attachNamespace('Proem', realpath(__DIR__) . '/..');
+ $this->attachNamespace('Proem', __DIR__);
}
}
@@ -219,6 +219,7 @@ private function locateFile($class)
$namespace = substr($class, 0, $pos);
$className = substr($class, $pos + 1);
$normalized = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
+
foreach ($this->namespaces as $space => $paths) {
if (strpos($namespace, $space) !== 0) {
continue;
@@ -230,6 +231,12 @@ private function locateFile($class)
if (is_file($file)) {
return $file;
}
+
+ // Attempt to handle paths that end with the *vendor* name.
+ $file = $path . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $normalized;
+ if (is_file($file)) {
+ return $file;
+ }
}
}
View
15 lib/Proem/Dispatch/Standard.php
@@ -149,20 +149,23 @@ public function isDispatchable()
$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) {
+ foreach (array_reverse($this->controllerMaps) as $map) {
$this->class = str_replace(
[':module', ':controller'],
[$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->action . 'Action');
+ if ($method->isPublic()) {
return true;
}
}
+ } catch (\ReflectionException $e) {
+ return false;
}
}
@@ -187,6 +190,8 @@ public function dispatch()
if ($this->assets->has('request')) {
$this->assets->get('request')->injectPayload($this->payload->prepare());
}
+
+ $this->class = new $this->class($this->assets);
$this->class->dispatch($this->action);
return $this;
}
View
17 lib/Proem/Routing/Route/Generic.php
@@ -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
View
11 lib/Proem/Routing/Route/Standard.php
@@ -113,16 +113,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;
View
6 lib/Proem/Routing/Route/StaticRoute.php
@@ -45,13 +45,15 @@ public function process(Request $request)
return false;
}
- $method = isset($this->options['method']) ? $this->options['method'] : 'GET';
+ if (!$this->testRequestMethod($request)) {
+ return false;
+ }
if (!isset($this->options['targets']) || !isset($this->options['targets']['module']) || !isset($this->options['targets']['controller']) || !isset($this->options['targets']['action'])) {
return false;
}
- if ($request->getRequestUri() == $this->options['rule'] && $request->getMethod() == $method) {
+ 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']);

No commit comments for this range

Something went wrong with that request. Please try again.