Permalink
Browse files

Allow Base + Server initialisation with additional attributes

  • Loading branch information...
1 parent 685e46c commit 84d3cf490833c68f4f5e406f7b35a32517714201 @cdujeu cdujeu committed Sep 8, 2016
@@ -24,28 +24,32 @@
defined('AJXP_EXEC') or die('Access not allowed');
-
+/**
+ * Very Top Level Routing
+ * @package Pydio\Core\Http
+ */
class Base
{
/**
* @param string $base
* @param string $route
+ * @param array $additionalAttributes
*/
- public static function handleRoute($base, $route){
+ public static function handleRoute($base, $route, $additionalAttributes = []){
if ($route === "/api") {
- $server = new Rest\RestApiServer($base.$route);
+ $server = new Rest\RestApiServer($base.$route, $additionalAttributes);
} else if ($route == "/wopi") {
- $server = new Wopi\RestWopiServer($base.$route);
+ $server = new Wopi\RestWopiServer($base.$route, $additionalAttributes);
} else if ($route === "/user") {
$_GET["get_action"] = "user_access_point";
- $server = new Server($base);
+ $server = new Server($base, $additionalAttributes);
} else if ($route == "/favicon"){
$_GET["get_action"] = "serve_favicon";
- $server = new Server($base);
+ $server = new Server($base, $additionalAttributes);
} else {
- $server = new Server($base);
+ $server = new Server($base, $additionalAttributes);
}
$server->registerCatchAll();
@@ -30,9 +30,9 @@
class RestApiServer extends Server
{
- public function __construct($base)
+ public function __construct($base, $requestAttributes = [])
{
- parent::__construct($base);
+ parent::__construct($base, $requestAttributes);
ConfService::currentContextIsRestAPI($base);
}
@@ -37,6 +37,10 @@
defined('AJXP_EXEC') or die('Access not allowed');
+/**
+ * Pydio HTTP Server
+ * @package Pydio\Core\Http
+ */
class Server
{
/**
@@ -64,7 +68,17 @@ class Server
*/
protected static $middleWareInstance;
- public function __construct($base){
+ /**
+ * @var array Additional attributes will be added to the initial Request object
+ */
+ private $requestAttributes;
+
+ /**
+ * Server constructor.
+ * @param $base
+ * @param $requestAttributes
+ */
+ public function __construct($base, $requestAttributes = []){
$this->middleWares = new \SplStack();
$this->middleWares->setIteratorMode(\SplDoublyLinkedList::IT_MODE_LIFO | \SplDoublyLinkedList::IT_MODE_KEEP);
@@ -74,7 +88,8 @@ public function __construct($base){
$this->stackMiddleWares();
self::$middleWareInstance = &$this->middleWares;
-
+
+ $this->requestAttributes = $requestAttributes;
}
protected function stackMiddleWares(){
@@ -98,13 +113,19 @@ public function registerCatchAll(){
}
}
+ /**
+ * @return ServerRequestInterface
+ */
public function getRequest(){
if(!isSet($this->request)){
$this->request = $this->initServerRequest();
}
return $this->request;
}
+ /**
+ * @param ServerRequestInterface $request
+ */
public function updateRequest(ServerRequestInterface $request){
$this->request = $request;
}
@@ -160,7 +181,9 @@ public static function callNextMiddleWareAndRewind(callable $comparisonFunction,
return $responseInterface;
}
-
+ /**
+ * @param callable $middleWareCallable
+ */
public function addMiddleware(callable $middleWareCallable){
$this->middleWares->push($middleWareCallable);
self::$middleWareInstance = $this->middleWares;
@@ -182,6 +205,11 @@ protected function initServerRequest($rest = false){
$request = ServerRequestFactory::fromGlobals();
$request = $request->withAttribute("ctx", Context::emptyContext());
+ if(!empty($this->requestAttributes) && count($this->requestAttributes)){
+ foreach($this->requestAttributes as $attName => $attValue){
+ $request = $request->withAttribute($attName, $attValue);
+ }
+ }
return $request;
}
@@ -26,13 +26,21 @@
defined('AJXP_EXEC') or die('Access not allowed');
-
+/**
+ * Class RestWopiServer
+ * Dedicated server for Wopi implementation (must start with /wopi).
+ * @package Pydio\Core\Http\Wopi
+ */
class RestWopiServer extends Server
{
-
- public function __construct($base)
+ /**
+ * RestWopiServer constructor.
+ * @param $base
+ * @param array $additionalAttributes
+ */
+ public function __construct($base, $additionalAttributes = [])
{
- parent::__construct($base);
+ parent::__construct($base, $additionalAttributes);
ConfService::currentContextIsRestAPI($base);
}

0 comments on commit 84d3cf4

Please sign in to comment.