Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Allow Base + Server initialisation with additional attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Sep 8, 2016
1 parent 685e46c commit 84d3cf4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
18 changes: 11 additions & 7 deletions core/src/core/src/pydio/Core/Http/Base.php
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions core/src/core/src/pydio/Core/Http/Rest/RestApiServer.php
Expand Up @@ -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);
}

Expand Down
34 changes: 31 additions & 3 deletions core/src/core/src/pydio/Core/Http/Server.php
Expand Up @@ -37,6 +37,10 @@

defined('AJXP_EXEC') or die('Access not allowed');

/**
* Pydio HTTP Server
* @package Pydio\Core\Http
*/
class Server
{
/**
Expand Down Expand Up @@ -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);
Expand All @@ -74,7 +88,8 @@ public function __construct($base){
$this->stackMiddleWares();

self::$middleWareInstance = &$this->middleWares;


$this->requestAttributes = $requestAttributes;
}

protected function stackMiddleWares(){
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;

}
Expand Down
16 changes: 12 additions & 4 deletions core/src/core/src/pydio/Core/Http/Wopi/RestWopiServer.php
Expand Up @@ -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);
}

Expand Down

0 comments on commit 84d3cf4

Please sign in to comment.