Permalink
Browse files

Php docs, array notation, remove static findPlugin calls.

  • Loading branch information...
1 parent d61761f commit 7098f8479aa1fea2e0c69ae11c1b2fe1a9600419 @cdujeu cdujeu committed Jun 15, 2016
@@ -537,7 +537,7 @@ public function getManifestRawContent($xmlNodeName = "", $format = "string", $ex
* the extended version is called when sending to the client, whereas the "small" version is loaded to find and apply actions.
* @param ContextInterface $ctx
* @param bool $extendedVersion Can be used by subclasses to optimize the size of the XML returned.
- * @return array
+ * @return \DOMElement[]
*/
public function getRegistryContributions(ContextInterface $ctx, $extendedVersion = true)
{
@@ -728,7 +728,7 @@ public function loadConfigs($configData)
*/
public function getConfigs()
{
- $core = PluginsService::getInstance()->findPlugin("core", $this->type);
+ $core = PluginsService::getInstance()->getPluginByTypeName("core", $this->type);
if (!empty($core)) {
$coreConfs = $core->getConfigs();
return array_merge($coreConfs, $this->pluginConf);
@@ -133,9 +133,9 @@ public static function confPluginSoftLoad()
{
$ctx = Context::emptyContext();
/** @var AbstractConfDriver $booter */
- $booter = PluginsService::getInstance($ctx)->softLoad("boot.conf", array());
+ $booter = PluginsService::getInstance($ctx)->softLoad("boot.conf", []);
$coreConfigs = $booter->loadPluginConfig("core", "conf");
- $corePlug = PluginsService::getInstance($ctx)->softLoad("core.conf", array());
+ $corePlug = PluginsService::getInstance($ctx)->softLoad("core.conf", []);
$corePlug->loadConfigs($coreConfigs);
return $corePlug->getImplementation();
@@ -147,10 +147,10 @@ public static function confPluginSoftLoad()
public static function cachePluginSoftLoad()
{
$ctx = Context::emptyContext();
- $coreConfigs = array();
- $corePlug = PluginsService::getInstance($ctx)->softLoad("core.cache", array());
+ $coreConfigs = [];
+ $corePlug = PluginsService::getInstance($ctx)->softLoad("core.cache", []);
/** @var CoreConfLoader $coreConf */
- $coreConf = PluginsService::getInstance($ctx)->softLoad("core.conf", array());
+ $coreConf = PluginsService::getInstance($ctx)->softLoad("core.conf", []);
$coreConf->loadBootstrapConfForPlugin("core.cache", $coreConfigs);
if (!empty($coreConfigs)) $corePlug->loadConfigs($coreConfigs);
return $corePlug->getImplementation();
@@ -162,23 +162,12 @@ public static function cachePluginSoftLoad()
* @param string $name
* @return Plugin
*/
- public static function findPlugin($type, $name)
+ public static function findPluginWithoutCtxt($type, $name)
{
return self::getInstance()->getPluginByTypeName($type, $name);
}
/**
- * Simply find a plugin by its id (type.name)
- * @static
- * @param $id
- * @return Plugin
- */
- public static function findPluginById($id)
- {
- return self::getInstance()->getPluginById($id);
- }
-
- /**
* Singleton method
* @param ContextInterface|null $ctx
* @return PluginsService the service instance
@@ -367,9 +356,10 @@ public static function searchManifestsWithCache($query, $callback, $typeChecker
public function searchAllManifests($query, $stringOrNodeFormat = "string", $limitToActivePlugins = false, $limitToEnabledPlugins = false, $loadExternalFiles = false)
{
$buffer = "";
- $nodes = array();
+ $nodes = [];
$detectedPlugins = $this->getDetectedPlugins();
foreach ($detectedPlugins as $plugType) {
+ /** @var Plugin $plugObject */
foreach ($plugType as $plugName => $plugObject) {
if ($limitToActivePlugins) {
$plugId = $plugObject->getId();
@@ -487,10 +477,10 @@ private function loadPlugins($pluginFolder, $confStorage, $cacheStorage)
}
if (is_string($pluginFolder)) {
- $pluginFolder = array($pluginFolder);
+ $pluginFolder = [$pluginFolder];
}
- $pluginsPool = array();
+ $pluginsPool = [];
foreach ($pluginFolder as $sourceFolder) {
$handler = @opendir($sourceFolder);
if ($handler) {
@@ -549,7 +539,7 @@ public function softLoad($pluginId, $pluginOptions)
$plugin = new Plugin($pluginId, AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/".$pluginId);
$plugin->loadManifest();
$plugin = $this->instanciatePluginClass($plugin);
- $plugin->loadConfigs(array()); // Load default
+ $plugin->loadConfigs([]); // Load default
$plugin->init($this->context, $pluginOptions);
return $plugin;
}
@@ -562,7 +552,7 @@ public function softLoad($pluginId, $pluginOptions)
public function getPluginsByType($type)
{
if(isSet($this->detectedPlugins[$type])) return $this->detectedPlugins[$type];
- else return array();
+ else return [];
}
/**
@@ -602,7 +592,7 @@ public function storeToPluginQueriesCache($key, $value)
{
if(AJXP_SKIP_CACHE) return;
$test = Utils::loadSerialFile(AJXP_PLUGINS_QUERIES_CACHE);
- if(!is_array($test)) $test = array();
+ if(!is_array($test)) $test = [];
$test[$key] = $value;
Utils::saveSerialFile(AJXP_PLUGINS_QUERIES_CACHE, $test);
}
@@ -643,9 +633,9 @@ public function initActivePlugins()
/**
* @var Plugin $pObject
*/
- $toActivate = array();
+ $toActivate = [];
foreach ($detected as $pType => $pObjects) {
- $coreP = $this->findPlugin("core", $pType);
+ $coreP = $this->getPluginByTypeName("core", $pType);
if($coreP !== false && !isSet($coreP->AUTO_LOAD_TYPE)) continue;
foreach ($pObjects as $pName => $pObject) {
$toActivate[$pObject->getId()] = $pObject ;
@@ -654,7 +644,7 @@ public function initActivePlugins()
$o = $this->getOrderByDependency($toActivate, false);
foreach ($o as $id) {
$pObject = $toActivate[$id];
- $pObject->init($this->context, array());
+ $pObject->init($this->context, []);
try {
$pObject->performChecks();
if(!$pObject->isEnabled() || $pObject->hasMissingExtensions()) continue;
@@ -744,7 +734,7 @@ public function getActivePlugins()
public function getActivePluginsForType($type, $unique = false)
{
$detectedPlugins = $this->getDetectedPlugins();
- $acts = array();
+ $acts = [];
foreach ($this->activePlugins as $plugId => $active) {
if(!$active) continue;
list($pT,$pN) = explode(".", $plugId);
@@ -868,6 +858,7 @@ public function patchPluginWithMixin(&$plugin, &$manifestDoc, $mixinName)
$nodeList = $this->mixinsXPath->query($mixinName);
if(!$nodeList->length) return;
$mixinNode = $nodeList->item(0);
+ /** @var \DOMElement $child */
foreach ($mixinNode->childNodes as $child) {
if($child->nodeType != XML_ELEMENT_NODE) continue;
$uuidAttr = $child->getAttribute("uuidAttr") OR "name";
@@ -946,7 +937,7 @@ private function recursiveLoadPlugin(AbstractConfDriver $confStorage, $plugin, $
}
$plugType = $plugin->getType();
if (!isSet($this->detectedPlugins[$plugType])) {
- $this->detectedPlugins[$plugType] = array();
+ $this->detectedPlugins[$plugType] = [];
}
$options = $confStorage->loadPluginConfig($plugType, $plugin->getName());
if($plugin->isEnabled() || (isSet($options["AJXP_PLUGIN_ENABLED"]) && $options["AJXP_PLUGIN_ENABLED"] === true)){
@@ -993,6 +984,7 @@ private function _loadDetectedPluginsFromCache($cacheStorage){
// Refresh streamWrapperPlugins
foreach ($this->detectedPlugins as $plugs) {
+ /** @var Plugin $plugin */
foreach ($plugs as $plugin) {
if (method_exists($plugin, "detectStreamWrapper") && $plugin->detectStreamWrapper(false) !== false) {
$this->streamWrapperPlugins[] = $plugin->getId();
@@ -1063,18 +1055,23 @@ private function checkDependencies(&$arrayToSort)
}
}
+ /**
+ * @param $plugins
+ * @param bool $withStatus
+ * @return array
+ */
private function getOrderByDependency($plugins, $withStatus = true)
{
- $keys = array();
- $unkowns = array();
+ $keys = [];
+ $unkowns = [];
if ($withStatus) {
foreach ($plugins as $pid => $status) {
if($status) $keys[] = $pid;
}
} else {
$keys = array_keys($plugins);
}
- $result = array();
+ $result = [];
while (count($keys) > 0) {
$test = array_shift($keys);
$testObject = $this->getPluginById($test);
@@ -1211,6 +1208,7 @@ private function mergeNodes(&$original, $parentName, $uuidAttr, $childrenNodes,
if ($parentSelection->length) {
$parentNode = $parentSelection->item(0);
$xPath = new \DOMXPath($original);
+ /** @var \DOMElement $child */
foreach ($childrenNodes as $child) {
if($child->nodeType != XML_ELEMENT_NODE) continue;
if ($child->getAttribute($uuidAttr) == "*") {
@@ -1221,6 +1219,7 @@ private function mergeNodes(&$original, $parentName, $uuidAttr, $childrenNodes,
$childrenSel = $xPath->query($query);
if ($childrenSel->length) {
if($doNotOverrideChildren) continue;
+ /** @var \DOMElement $existingNode */
foreach ($childrenSel as $existingNode) {
if($existingNode->getAttribute("forbidOverride") == "true"){
continue;
@@ -1257,10 +1256,12 @@ private function mergeChildByTagName($new, &$old)
$old->parentNode->replaceChild($new, $old);
return;
}
+ /** @var \DOMElement $newChild */
foreach ($new->childNodes as $newChild) {
if($newChild->nodeType != XML_ELEMENT_NODE) continue;
$found = null;
+ /** @var \DOMElement $oldChild */
foreach ($old->childNodes as $oldChild) {
if($oldChild->nodeType != XML_ELEMENT_NODE) continue;
if ($oldChild->nodeName == $newChild->nodeName) {
@@ -469,7 +469,7 @@ protected function setConfInst($varName, $varValue)
public static function getCoreConf($varName, $coreType = "ajaxplorer")
{
$ctx = Context::fromGlobalServices();
- $coreP = PluginsService::getInstance($ctx)->findPlugin("core", $coreType);
+ $coreP = PluginsService::getInstance($ctx)->getPluginByTypeName("core", $coreType);
if($coreP === false) return null;
$confs = $coreP->getConfigs();
if($ctx->hasUser()){
@@ -232,7 +232,7 @@ public static function migrateLegacyMeta(ContextInterface $ctx, $shareCenter, $s
*/
$currentContext = new Context($userName);
$currentContext->setRepositoryObject($parentRepositoryObject);
- $driverInstance = PluginsService::getInstance($currentContext)->findPlugin("access", $parentRepositoryObject->getAccessType());
+ $driverInstance = PluginsService::getInstance($currentContext)->getPluginByTypeName("access", $parentRepositoryObject->getAccessType());
if(empty($driverInstance)){
print("\n-- ERROR: Cannot find driver instance!");
continue;
@@ -126,7 +126,7 @@ public static function loadMinisite($data, $hash = '', $error = null)
$html = str_replace('AJXP_HASH_LOAD_ERROR', isSet($error)?$error:'', $html);
$html = str_replace("AJXP_TEMPLATE_NAME", $templateName, $html);
$html = str_replace("AJXP_LINK_HASH", $hash, $html);
- $guiConfigs = PluginsService::getInstance($ctx)->findPluginById("gui.ajax")->getConfigs();
+ $guiConfigs = PluginsService::getInstance($ctx)->getPluginById("gui.ajax")->getConfigs();
$html = str_replace("AJXP_THEME", $guiConfigs["GUI_THEME"] , $html);
if(isSet($_GET["dl"]) && isSet($_GET["file"])){
@@ -307,7 +307,7 @@ public function nodeChangeBookmarkMetadata($fromNode=null, $toNode=null, $copy=f
************************/
public static function filterXml(&$value)
{
- $instance = PluginsService::getInstance(Context::emptyContext())->findPlugin("gui", "ajax");
+ $instance = PluginsService::getInstance(Context::emptyContext())->getPluginByTypeName("gui", "ajax");
if($instance === false) return null;
$confs = $instance->getConfigs();
$theme = $confs["GUI_THEME"];

0 comments on commit 7098f84

Please sign in to comment.