// public function getReferer();
// public function getUserAgent();
$r = $this->_request;
-// echo $r->getMethod();
+ echo $r->getPath();
$this->_response->setHeader('Content-Type', 'application/json')
->setBody(json_encode(array('body' => $r->getBody())))
{
return $_SERVER['HTTP_USER_AGENT'];
}
+
+ private function getPhysicalPath()
+ {
+ $scriptName = $_SERVER['SCRIPT_NAME']; // <-- "/foo/index.php"
+ $requestUri = $_SERVER['REQUEST_URI']; // <-- "/foo/bar?test=abc" or "/foo/index.php/bar?test=abc"
+
+ // Physical path
+ if (strpos($requestUri, $scriptName) !== false) {
+ $physicalPath = $scriptName; // <-- Without rewriting
+ } else {
+ $physicalPath = str_replace('\\', '', dirname($scriptName)); // <-- With rewriting
+ }
+
+ return $physicalPath;
+ }
+
+ public function getPath()
+ {
+ $physicalPath = $this->getPhysicalPath();
+ $requestUri = $_SERVER['REQUEST_URI']; // <-- "/foo/bar?test=abc" or "/foo/index.php/bar?test=abc"
+ $queryString = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; // <-- "test=abc" or ""
+
+ // Virtual path
+ $path = substr_replace($requestUri, '', 0, strlen($physicalPath)); // <-- Remove physical path
+ $path = str_replace('?' . $queryString, '', $path); // <-- Remove query string
+ $path = '/' . ltrim($path, '/'); // <-- Ensure leading slash
+
+ return $path;
+ }
}
\ No newline at end of file
public function getReferrer();
public function getReferer();
public function getUserAgent();
+ public function getPath();
}
\ No newline at end of file
--- /dev/null
+<?php
+
+namespace Services\Routing;
+
+interface IRoute
+{
+ public function matches($uri);
+ public function supports($method);
+ public function execute();
+}
--- /dev/null
+<?php
+
+namespace Services\Routing;
+
+class Route
+{
+ private $_controllerName;
+ private $_pattern;
+ private $_methods;
+
+ public function __construct($controllerName, $pattern, array $methods)
+ {
+ $this->_controllerName = $controllerName;
+ $this->_pattern = $pattern;
+ $this->_methods = $methods;
+ }
+
+ public function matches($path) {
+ $argNames = array();
+
+ /*
+ * Set up a callback for preg_replace_callback. What this does is
+ * replace the :argName style arguments with named groups to match
+ * against the resource URI. So for example:
+ *
+ * my/:pattern/
+ *
+ * Becomes:
+ *
+ * my/(?P<pattern>[^/]+
+ *
+ * Then we can feed the new regex and the URI in to preg_match to
+ * extract the variables.
+ */
+ $callback = function($m) use ($argNames) {
+ /*
+ * We save away the names of the arguments in a variable so we can
+ * loop through later and put them in $this->arguments.
+ */
+ $argNames[] = $m[1];
+ return '(?P<' . $m[1] . '>[^/]+)';
+ };
+
+ $patternAsRegex = preg_replace_callback('#:([\w]+)\+?#', $callback, $this->_pattern);
+
+ if (!preg_match('#^' . $patternAsRegex . '$#', $path, $argValues))
+ return false;
+
+ return true;
+ }
+
+ public function supports($method)
+ {
+ return in_array($method, $this->_methods);
+ }
+
+ public function getControllerName()
+ {
+ $this->_controllerName;
+ }
+}
+
--- /dev/null
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
--- /dev/null
+RewriteEngine On
+RewriteBase /
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule ^ index.php [QSA,L]
+
+php_value auto_prepend_file /home/cameron/vhosts/xhprof/public_html/header.php
+php_value auto_append_file /home/cameron/vhosts/xhprof/public_html/footer.php
+
\r
$container = $containerBuilder->build();\r
\r
+$route = new Services\Routing\Route('swege', '/yolo/swage', array('GET'));\r
+$request = new Services\Http\HttpRequest();\r
\r
-$indexController = $container->get('Controllers\IndexController');\r
-$indexController->getAction();\r
+$match = $route->matches($request->getPath());\r
+\r
+var_dump($route->supports('POST'));\r
+\r
+//$indexController = $container->get('Controllers\IndexController');\r
+//$indexController->getAction();\r
\r
/* @var $foo Domain\Entities\Foo */\r
//$foo = $container->get('Domain\Entities\Foo');\r