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

Commit

Permalink
Extract user & repository interfaces, create Context object.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 2, 2016
1 parent 494a27b commit 26b2499
Show file tree
Hide file tree
Showing 19 changed files with 917 additions and 402 deletions.
3 changes: 0 additions & 3 deletions core/src/core/src/pydio/Core/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,6 @@ private static function appliesCondition($callback, $actionName, $httpVars, $fil
* Applies a callback node
* @static
* @param \DOMElement|array $callback The DOM Node or directly an array of attributes
* @param String $actionName
* @param array $httpVars
* @param array $fileVars
* @param null $variableArgs
* @param bool $defer
* @throws PydioException
Expand Down
1 change: 0 additions & 1 deletion core/src/core/src/pydio/Core/Http/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public static function callNextMiddleWare(ServerRequestInterface $requestInterfa
* @param ResponseInterface $responseInterface
* @param callable|null $next
* @return ResponseInterface
* @internal param array $rewindTo
*/
public static function callNextMiddleWareAndRewind(callable $comparisonFunction, ServerRequestInterface $requestInterface, ResponseInterface $responseInterface, callable $next = null){
if($next !== null){
Expand Down
149 changes: 149 additions & 0 deletions core/src/core/src/pydio/Core/Model/Context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php
/*
* Copyright 2007-2016 Abstrium <contact (at) pydio.com>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com/>.
*/
namespace Pydio\Core\Model;

use Pydio\Core\Services\ConfService;

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


class Context implements ContextInterface
{

/**
* @var string
*/
private $userId;

/**
* @var
*/
private $userObject;

/**
* @var
*/
private $repositoryId;

/**
* @var
*/
private $repositoryObject;

public function __construct($userId = null, $repositoryId = null)
{
if($userId !== null) {
$this->userId = $userId;
}
if($repositoryId !== null){
$this->repositoryId = $repositoryId;
}
}

/**
* @return boolean
*/
public function hasUser()
{
return !empty($this->userId);
}

/**
* @return UserInterface|null
*/
public function getUser()
{
if(isSet($this->userObject)){
return $this->userObject;
}
if(isSet($this->userId)){
$this->userObject = ConfService::getConfStorageImpl()->createUserObject($this->userId);
return $this->userObject;
}
return null;
}

/**
* @param string $userId
*/
public function setUserId($userId)
{
$this->userId = $userId;
}

/**
* @param UserInterface $user
*/
public function setUserObject($user)
{
$this->userObject = $user;
$this->userId = $user->getId();
}

public function resetUser(){
$this->userId = null;
$this->userObject = null;
}

/**
* @return boolean
*/
public function hasRepository()
{
return (!empty($this->repositoryId));
}

/**
* @return RepositoryInterface|null
*/
public function getRepository()
{
if(isSet($this->repositoryId)){
if(!isSet($this->repositoryObject)){
$this->repositoryObject = ConfService::getRepositoryById($this->repositoryId);
}
return $this->repositoryObject;
}
return null;
}

/**
* @param string $repositoryId
*/
public function setRepositoryId($repositoryId)
{
$this->repositoryId = $repositoryId;
}

/**
* @param RepositoryInterface $repository
*/
public function setRepositoryObject($repository)
{
$this->repositoryObject = $repository;
$this->repositoryId = $repository->getId();
}

public function resetRepository()
{
$this->repositoryId = $this->repositoryObject = null;
}
}
71 changes: 71 additions & 0 deletions core/src/core/src/pydio/Core/Model/ContextInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/*
* Copyright 2007-2016 Abstrium <contact (at) pydio.com>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com/>.
*/
namespace Pydio\Core\Model;

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


interface ContextInterface
{
/**
* @return boolean
*/
public function hasUser();

/**
* @return UserInterface|null
*/
public function getUser();

/**
* @param string $userId
*/
public function setUserId($userId);

/**
* @param UserInterface $user
*/
public function setUserObject($user);

public function resetUser();

/**
* @return boolean
*/
public function hasRepository();

/**
* @return RepositoryInterface|null
*/
public function getRepository();

/**
* @param string $repositoryId
*/
public function setRepositoryId($repositoryId);

/**
* @param RepositoryInterface $repository
*/
public function setRepositoryObject($repository);

public function resetRepository();
}
Loading

0 comments on commit 26b2499

Please sign in to comment.