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

Commit

Permalink
Massive Refactoring for using namespaces (at last). Step 1.
Browse files Browse the repository at this point in the history
Use class_alias to avoid unserialization issues.
Replace is_a() usage by instanceof everywhere possible to ease future refactoring.
  • Loading branch information
cdujeu committed May 6, 2016
1 parent 920258a commit f99f31e
Show file tree
Hide file tree
Showing 288 changed files with 2,117 additions and 732 deletions.
10 changes: 10 additions & 0 deletions core/src/cmd.php
Expand Up @@ -20,6 +20,16 @@
*
* Description : Command line access of the framework.
*/
use Pydio\Auth\Core\AJXP_Safe;
use Pydio\Auth\Core\AuthService;
use Pydio\Conf\Core\ConfService;
use Pydio\Core\AJXP_Controller;
use Pydio\Core\AJXP_Exception;
use Pydio\Core\AJXP_XMLWriter;
use Pydio\Core\Plugins\AJXP_PluginsService;
use Pydio\Core\SystemTextEncoding;
use Pydio\Log\Core\AJXP_Logger;

if (php_sapi_name() !== "cli") {
die("This is the command line version of the framework, you are not allowed to access this page");
}
Expand Down
18 changes: 14 additions & 4 deletions core/src/conf/bootstrap_context.php
Expand Up @@ -70,10 +70,6 @@
// example in log.serial. Do not forget the trailing slash
// define("AJXP_FORCE_LOGPATH", "/var/log/ajaxplorer/");

// KEY-VALUE-CACHE
define("AJXP_KVCACHE_PREFIX", "pydio-unique-id");
define("AJXP_KVCACHE_IGNORE", true);

// DEBUG OPTIONS
define("AJXP_CLIENT_DEBUG" , false);
define("AJXP_SERVER_DEBUG" , false);
Expand All @@ -96,8 +92,18 @@
// MAKE SURE YOU HAVE PHP.5.3, OPENSSL, AND THAT IT DOES NOT DEGRADE PERFORMANCES
define("USE_OPENSSL_RANDOM", false);

$corePlugAutoloads = glob(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/core.*/vendor/autoload.php", GLOB_NOSORT);
if ($corePlugAutoloads !== false && count($corePlugAutoloads)) {
foreach($corePlugAutoloads as $autoloader){
require_once ($autoloader);
}
}

function AjaXplorer_autoload($className)
{
// Temp : super dummy autoloader, take only class name
$className = array_pop(explode("\\", $className));

if($className == "dibi"){
require_once(AJXP_BIN_FOLDER."/dibi/dibi.php");
}
Expand All @@ -124,6 +130,10 @@ function AjaXplorer_autoload($className)
}
spl_autoload_register('AjaXplorer_autoload');

include_once (AJXP_BIN_FOLDER."/compat.php");

use Pydio\Core\AJXP_Utils;

AJXP_Utils::safeIniSet("session.cookie_httponly", 1);

if (is_file(AJXP_CONF_PATH."/bootstrap_conf.php")) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/core/classes/class.AJXP_Cache.php
Expand Up @@ -18,6 +18,8 @@
*
* The latest code can be found at <http://pyd.io/>.
*/
namespace Pydio\Core;

defined('AJXP_EXEC') or die( 'Access not allowed');
/**
* Generic caching system that can be used by the plugins. Use the static factory getItem() to generate
Expand Down
49 changes: 28 additions & 21 deletions core/src/core/classes/class.AJXP_Controller.php
Expand Up @@ -18,6 +18,13 @@
*
* The latest code can be found at <http://pyd.io/>.
*/
namespace Pydio\Core;

use Pydio\Auth\Core\AuthService;
use Pydio\Conf\Core\ConfService;
use Pydio\Core\Plugins\AJXP_PluginsService;
use Pydio\Log\Core\AJXP_Logger;

defined('AJXP_EXEC') or die( 'Access not allowed');
/**
* Core controller for dispatching the actions.
Expand All @@ -28,7 +35,7 @@
class AJXP_Controller
{
/**
* @var DOMXPath
* @var \DOMXPath
*/
private static $xPath;
/**
Expand All @@ -46,13 +53,13 @@ class AJXP_Controller
* Initialize the queryable xPath object
* @static
* @param bool $useCache Whether to cache the registry version in a memory cache.
* @return DOMXPath
* @return \DOMXPath
*/
private static function initXPath($useCache = false)
{
if (!isSet(self::$xPath)) {
$registry = ConfService::getFilteredXMLRegistry(false, false, $useCache);
self::$xPath = new DOMXPath($registry);
self::$xPath = new \DOMXPath($registry);
}
return self::$xPath;
}
Expand Down Expand Up @@ -95,18 +102,18 @@ public static function findRestActionAndApply($actionName, $path)
if (count($paramValues) < count($paramNames)) {
$paramNames = array_slice($paramNames, 0, count($paramValues));
}
$paramValues = array_map(array("SystemTextEncoding", "toUTF8"), $paramValues);
$paramValues = array_map(array("Pydio\\Core\\SystemTextEncoding", "toUTF8"), $paramValues);
$httpVars = array_merge($_GET, $_POST, array_combine($paramNames, $paramValues));
return self::findActionAndApply($actionName, $httpVars, $_FILES, $action);

}

/**
* @static
* @param Array $parameters
* @param DOMNode $callbackNode
* @param DOMXPath $xPath
* @throws Exception
* @param array $parameters
* @param \DOMNode $callbackNode
* @param \DOMXPath $xPath
* @throws \Exception
*/
public static function checkParams(&$parameters, $callbackNode, $xPath)
{
Expand All @@ -121,7 +128,7 @@ public static function checkParams(&$parameters, $callbackNode, $xPath)
$defaultNode = $param->attributes->getNamedItem("default");
$mandatory = ($param->attributes->getNamedItem("mandatory")->nodeValue == "true");
if ($mandatory && !isSet($parameters[$name])) {
throw new Exception("Missing parameter '".$name."' of type '$type'");
throw new \Exception("Missing parameter '".$name."' of type '$type'");
}
if ($defaultNode != null && !isSet($parameters[$name])) {
$parameters[$name] = $defaultNode->nodeValue;
Expand All @@ -140,7 +147,7 @@ public static function checkParams(&$parameters, $callbackNode, $xPath)
* @param String $actionName
* @param array $httpVars
* @param array $fileVars
* @param DOMNode $action
* @param \DOMNode $action
* @return mixed
*/
public static function findActionAndApply($actionName, $httpVars, $fileVars, &$action = null)
Expand Down Expand Up @@ -397,14 +404,14 @@ public static function runCommandInBackground($cmd, $logFile)
/**
* Find a callback node by its xpath query, filtering with the applyCondition if the xml attribute exists.
* @static
* @param DOMXPath $xPath
* @param DOMNode $actionNode
* @param \DOMXPath $xPath
* @param \DOMNode $actionNode
* @param string $query
* @param string $actionName
* @param array $httpVars
* @param array $fileVars
* @param bool $multiple
* @return DOMElement|bool|DOMElement[]
* @return \DOMElement|bool|\DOMElement[]
*/
private static function getCallbackNode($xPath, $actionNode, $query ,$actionName, $httpVars, $fileVars, $multiple = true)
{
Expand All @@ -430,7 +437,7 @@ private static function getCallbackNode($xPath, $actionNode, $query ,$actionName
* Check in the callback node if an applyCondition XML attribute exists, and eval its content.
* The content must set an $apply boolean as result
* @static
* @param DOMElement|DOMNode $callback
* @param \DOMElement|\DOMNode $callback
* @param string $actionName
* @param array $httpVars
* @param array $fileVars
Expand All @@ -449,10 +456,10 @@ 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 \DOMElement|array $callback The DOM Node or directly an array of attributes
* @param String $actionName
* @param Array $httpVars
* @param Array $fileVars
* @param array $httpVars
* @param array $fileVars
* @param null $variableArgs
* @param bool $defer
* @throws AJXP_Exception* @internal param \DOMXPath $xPath
Expand Down Expand Up @@ -516,7 +523,7 @@ public static function applyHook($hookName, $args, $forceNonDefer = false)
if(!$callbacks->length) return ;
self::$hooksCache[$hookName] = array();
/**
* @var $callback DOMElement
* @var $callback \DOMElement
*/
foreach ($callbacks as $callback) {
$defer = ($callback->getAttribute("defer") === "true");
Expand All @@ -541,7 +548,7 @@ public static function applyHook($hookName, $args, $forceNonDefer = false)
if($dontBreakOnException){
try{
self::applyCallback($hookCallback, $fake1, $fake2, $fake3, $args, $defer);
}catch(Exception $e){
}catch(\Exception $e){
AJXP_Logger::error("[Hook $hookName]", "[Callback ".$plugId.".".$methodName."]", $e->getMessage());
}
}else{
Expand Down Expand Up @@ -583,8 +590,8 @@ public static function registerIncludeHook($hookName, $callback)
/**
* Check the rightsContext node of an action.
* @static
* @param DOMNode $actionNode
* @param DOMXPath $xPath
* @param \DOMNode $actionNode
* @param \DOMXPath $xPath
* @param string $right
* @return bool
*/
Expand Down
8 changes: 6 additions & 2 deletions core/src/core/classes/class.AJXP_Exception.php
Expand Up @@ -18,13 +18,17 @@
*
* The latest code can be found at <http://pyd.io/>.
*/
namespace Pydio\Core;

use Pydio\Conf\Core\ConfService;

defined('AJXP_EXEC') or die( 'Access not allowed');
/**
* Custom exception (legacy from php4 when there were no exceptions)
* @package Pydio
* @subpackage Core
*/
class AJXP_Exception extends Exception
class AJXP_Exception extends \Exception
{
public function __construct($messageString, $messageId = false)
{
Expand All @@ -41,7 +45,7 @@ public function __construct($messageString, $messageId = false)

public function errorToXml($mixed)
{
if (is_a($mixed, "Exception")) {
if ($mixed instanceof \Exception) {
throw $this;
} else {
throw new AJXP_Exception($mixed);
Expand Down
9 changes: 6 additions & 3 deletions core/src/core/classes/class.AJXP_JSPacker.php
Expand Up @@ -18,6 +18,9 @@
*
* The latest code can be found at <http://pyd.io/>.
*/
namespace Pydio\Core;
use Pydio\Core\Plugins\AJXP_PluginsService;

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

/**
Expand Down Expand Up @@ -89,7 +92,7 @@ public function concatListAndPack($src, $out, $mode)

// Pack and write to file
require_once("packer/class.JavaScriptPacker.php");
$packer = new JavaScriptPacker($jscode, $mode , true, false);
$packer = new \JavaScriptPacker($jscode, $mode , true, false);
$packed = $packer->pack();
if ($mode == "None") { // css case, hack for I.E.
$packed = str_replace("solid#", "solid #", $packed);
Expand All @@ -113,12 +116,12 @@ public function compactEach($list, $mode){
$jscode = file_get_contents($in);
$fullcode .= $jscode;
// Pack and write to file
$packer = new JavaScriptPacker($jscode, $mode , true, false);
$packer = new \JavaScriptPacker($jscode, $mode , true, false);
$packed = $packer->pack();
file_put_contents($out, $packed);

// Pack and write to file
$packer = new JavaScriptPacker($fullcode, $mode , true, false);
$packer = new \JavaScriptPacker($fullcode, $mode , true, false);
$packed = $packer->pack();
file_put_contents($outfull, $packed);
}
Expand Down
107 changes: 0 additions & 107 deletions core/src/core/classes/class.AJXP_KeyValueCache.php

This file was deleted.

0 comments on commit f99f31e

Please sign in to comment.