commit 4c4a100dee38345d3adf990d50b506e5b8f3d5ab
parent 19007cb730e3105bb80712643afdb7a6ba6c4c5c
Author: finwo <finwo@pm.me>
Date: Wed, 20 Apr 2016 00:36:23 +0200
Bugfix
Diffstat:
5 files changed, 59 insertions(+), 54 deletions(-)
diff --git a/.htaccess b/.htaccess
@@ -1,3 +0,0 @@
-# We'll route everything to our app
-RewriteEngine on
-RewriteRule ^(.*)$ /web/app.php [NC,L,QSA]
diff --git a/config/config.yml b/config/config.yml
@@ -9,7 +9,7 @@ authors:
routes:
rest_proxy:
type: rest
- path: ^\/(?<resource>[a-z\/]+)(\.(?<format>[a-z]+))?$
+ pattern: ^\/(?<resource>[a-z\/]+)(\.(?<format>[a-z]+))?$
method: GET
prefix: /rest
controller: Finwo\RestProxy:Rest:get
diff --git a/src/Finwo/Framework/Application.php b/src/Finwo/Framework/Application.php
@@ -4,6 +4,7 @@ namespace Finwo\Framework;
use Finwo\PropertyAccessor\PropertyAccessor;
use Invoker\Invoker;
+use OAuth2\Exception;
class Application
{
@@ -66,6 +67,7 @@ class Application
$loader->loadFile($file)
);
}
+
$this->container->set('config', $config);
// Transform routes into route objects, for easy usage
@@ -122,7 +124,6 @@ class Application
}
// Check if we match any known routes
- $routes = $this->container->get('config.routes');
/** @var Route $route */
$route = @array_shift(array_filter($this->container->get('config.routes'), function(Route $route) {
return $route->match();
@@ -134,6 +135,9 @@ class Application
if (!is_null($route)) {
// Fetch callable for the route
list($controller, $method) = $this->routeToCallable($route);
+ } else {
+ // Find something based upon the request uri
+ die('Not Implemented');
}
// Create the controller object
diff --git a/src/Finwo/Framework/Route.php b/src/Finwo/Framework/Route.php
@@ -10,7 +10,7 @@ class Route extends Mappable
protected $type = 'default';
protected $name;
protected $host;
- protected $path;
+ protected $pattern;
protected $method;
protected $controller;
protected $defaults;
@@ -35,9 +35,9 @@ class Route extends Mappable
{
// If this function gets called, process the request.. No sooner
- // Handle path prefix
- if(strlen($this->prefix)) {
- if( substr($this->requestUri, 0, strlen($this->prefix)) == $this->prefix ) {
+ // Handle pattern prefix
+ if (strlen($this->prefix)) {
+ if (substr($this->requestUri, 0, strlen($this->prefix)) == $this->prefix) {
$this->requestUri = substr($this->requestUri, strlen($this->prefix));
} else {
return false;
@@ -54,7 +54,7 @@ class Route extends Mappable
return false;
}
- // Parse the path
+ // Parse the pattern
$parsed = array_merge(array(
'path' => '/',
'query' => ''
@@ -65,7 +65,7 @@ class Route extends Mappable
parse_str($this->parsedUri['query'], $query);
$this->parsedUri['query'] = $query;
- if (!is_null($this->path) && !preg_match('/' . $this->path . '/i', $parsed['path'], $this->parameters)) {
+ if (!is_null($this->pattern) && !preg_match('/' . $this->pattern . '/i', $parsed['path'], $this->parameters)) {
return false;
}
@@ -84,24 +84,6 @@ class Route extends Mappable
}
/**
- * @return mixed
- */
- public function getParsedUri()
- {
- return $this->parsedUri;
- }
-
- /**
- * @param mixed $parsedUri
- * @return Route
- */
- public function setParsedUri($parsedUri)
- {
- $this->parsedUri = $parsedUri;
- return $this;
- }
-
- /**
* @return string
*/
public function getType()
@@ -158,18 +140,18 @@ class Route extends Mappable
/**
* @return mixed
*/
- public function getPath()
+ public function getPattern()
{
- return $this->path;
+ return $this->pattern;
}
/**
- * @param mixed $path
+ * @param mixed $pattern
* @return Route
*/
- public function setPath($path)
+ public function setPattern($pattern)
{
- $this->path = $path;
+ $this->pattern = $pattern;
return $this;
}
@@ -246,6 +228,42 @@ class Route extends Mappable
}
/**
+ * @return mixed
+ */
+ public function getParsedUri()
+ {
+ return $this->parsedUri;
+ }
+
+ /**
+ * @param mixed $parsedUri
+ * @return Route
+ */
+ public function setParsedUri($parsedUri)
+ {
+ $this->parsedUri = $parsedUri;
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getParameters()
+ {
+ return $this->parameters;
+ }
+
+ /**
+ * @param mixed $parameters
+ * @return Route
+ */
+ public function setParameters($parameters)
+ {
+ $this->parameters = $parameters;
+ return $this;
+ }
+
+ /**
* @return string
*/
public function getRequestUri()
@@ -298,22 +316,4 @@ class Route extends Mappable
$this->httpHost = $httpHost;
return $this;
}
-
- /**
- * @return mixed
- */
- public function getParameters()
- {
- return $this->parameters;
- }
-
- /**
- * @param mixed $parameters
- * @return Route
- */
- public function setParameters($parameters)
- {
- $this->parameters = $parameters;
- return $this;
- }
}
\ No newline at end of file
diff --git a/web/.htaccess b/web/.htaccess
@@ -1,3 +1,8 @@
# We'll route everything to our app
+
+DirectoryIndex app.php
+
RewriteEngine on
-RewriteRule ^(.*)$ /app.php [NC,L,QSA]
-\ No newline at end of file
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule ^(.*)$ /app.php [NC,L]