Commit b60a9e04 by Scott

Move old PSR-0 classes

parent 763f2726
...@@ -54,7 +54,7 @@ if ($isCore) { ...@@ -54,7 +54,7 @@ if ($isCore) {
$versionResponse = qa_lang_html('admin/version_latest_unknown'); $versionResponse = qa_lang_html('admin/version_latest_unknown');
} }
} else { } else {
$metadataUtil = new Q2A_Util_Metadata(); $metadataUtil = new \Q2A\Util\Metadata();
$metadata = $metadataUtil->fetchFromUrl($uri); $metadata = $metadataUtil->fetchFromUrl($uri);
if (strlen(@$metadata['version']) > 0) { if (strlen(@$metadata['version']) > 0) {
......
...@@ -122,7 +122,7 @@ function qa_admin_language_options() ...@@ -122,7 +122,7 @@ function qa_admin_language_options()
$options = array('' => 'English (US)'); $options = array('' => 'English (US)');
// find all language folders // find all language folders
$metadataUtil = new Q2A_Util_Metadata(); $metadataUtil = new \Q2A\Util\Metadata();
foreach (glob(QA_LANG_DIR . '*', GLOB_ONLYDIR) as $directory) { foreach (glob(QA_LANG_DIR . '*', GLOB_ONLYDIR) as $directory) {
$code = basename($directory); $code = basename($directory);
$metadata = $metadataUtil->fetchFromAddonPath($directory); $metadata = $metadataUtil->fetchFromAddonPath($directory);
...@@ -147,7 +147,7 @@ function qa_admin_theme_options() ...@@ -147,7 +147,7 @@ function qa_admin_theme_options()
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$metadataUtil = new Q2A_Util_Metadata(); $metadataUtil = new \Q2A\Util\Metadata();
foreach (glob(QA_THEME_DIR . '*', GLOB_ONLYDIR) as $directory) { foreach (glob(QA_THEME_DIR . '*', GLOB_ONLYDIR) as $directory) {
$theme = basename($directory); $theme = basename($directory);
$metadata = $metadataUtil->fetchFromAddonPath($directory); $metadata = $metadataUtil->fetchFromAddonPath($directory);
...@@ -898,7 +898,7 @@ function qa_admin_addon_metadata($contents, $fields) ...@@ -898,7 +898,7 @@ function qa_admin_addon_metadata($contents, $fields)
*/ */
function qa_admin_plugin_directory_hash($directory) function qa_admin_plugin_directory_hash($directory)
{ {
$pluginManager = new Q2A_Plugin_PluginManager(); $pluginManager = new \Q2A\Plugin\PluginManager();
$hashes = $pluginManager->getHashesForPlugins(array($directory)); $hashes = $pluginManager->getHashesForPlugins(array($directory));
return reset($hashes); return reset($hashes);
......
...@@ -1563,7 +1563,7 @@ function qa_db_upgrade_tables() ...@@ -1563,7 +1563,7 @@ function qa_db_upgrade_tables()
break; break;
case 64: case 64:
$pluginManager = new Q2A_Plugin_PluginManager(); $pluginManager = new \Q2A\Plugin\PluginManager();
$allPlugins = $pluginManager->getFilesystemPlugins(); $allPlugins = $pluginManager->getFilesystemPlugins();
$pluginManager->setEnabledPlugins($allPlugins); $pluginManager->setEnabledPlugins($allPlugins);
break; break;
......
...@@ -1037,7 +1037,7 @@ foreach ($showoptions as $optionname) { ...@@ -1037,7 +1037,7 @@ foreach ($showoptions as $optionname) {
qa_optionfield_make_select($optionfield, $themeoptions, $value, 'Classic'); qa_optionfield_make_select($optionfield, $themeoptions, $value, 'Classic');
$metadataUtil = new Q2A_Util_Metadata(); $metadataUtil = new \Q2A\Util\Metadata();
$themedirectory = QA_THEME_DIR . $value; $themedirectory = QA_THEME_DIR . $value;
$metadata = $metadataUtil->fetchFromAddonPath($themedirectory); $metadata = $metadataUtil->fetchFromAddonPath($themedirectory);
if (empty($metadata)) { if (empty($metadata)) {
......
...@@ -43,7 +43,7 @@ $qa_content['error'] = qa_admin_page_error(); ...@@ -43,7 +43,7 @@ $qa_content['error'] = qa_admin_page_error();
$qa_content['script_rel'][] = 'qa-content/qa-admin.js?' . QA_VERSION; $qa_content['script_rel'][] = 'qa-content/qa-admin.js?' . QA_VERSION;
$pluginManager = new Q2A_Plugin_PluginManager(); $pluginManager = new \Q2A\Plugin\PluginManager();
$pluginManager->cleanRemovedPlugins(); $pluginManager->cleanRemovedPlugins();
$enabledPlugins = $pluginManager->getEnabledPlugins(); $enabledPlugins = $pluginManager->getEnabledPlugins();
...@@ -116,7 +116,7 @@ foreach ($moduletypes as $type) { ...@@ -116,7 +116,7 @@ foreach ($moduletypes as $type) {
if (!empty($fileSystemPlugins)) { if (!empty($fileSystemPlugins)) {
$metadataUtil = new Q2A_Util_Metadata(); $metadataUtil = new \Q2A\Util\Metadata();
$sortedPluginFiles = array(); $sortedPluginFiles = array();
foreach ($fileSystemPlugins as $pluginDirectory) { foreach ($fileSystemPlugins as $pluginDirectory) {
......
...@@ -28,15 +28,11 @@ define('QA_BUILD_DATE', '2019-01-12'); ...@@ -28,15 +28,11 @@ define('QA_BUILD_DATE', '2019-01-12');
* Autoloads some Q2A classes so it's possible to use them without adding a require_once first. From * Autoloads some Q2A classes so it's possible to use them without adding a require_once first. From
* version 1.9 onwards we follow PSR-4. Classes are stored in qa-src/ which maps to the 'Q2A' namespace. * version 1.9 onwards we follow PSR-4. Classes are stored in qa-src/ which maps to the 'Q2A' namespace.
* So for example \Q2A\Storage\CacheFactory maps to qa-src/Storage/CacheFactory.php. * So for example \Q2A\Storage\CacheFactory maps to qa-src/Storage/CacheFactory.php.
* In version 1.7-1.8 we used PSR-0 so Q2A_Storage_CacheFactory would map to qa-include/Q2A/Storage/CacheFactory.php.
* *
* @param string $class * @param string $class
*/ */
function qa_autoload($class) function qa_autoload($class)
{ {
if (strpos($class, 'Q2A_') === 0)
require QA_INCLUDE_DIR . strtr($class, '_', '/') . '.php';
if (strpos($class, 'Q2A\\') === 0) { if (strpos($class, 'Q2A\\') === 0) {
require QA_BASE_DIR . 'qa-src/' . strtr(substr($class, 4), '\\', '/') . '.php'; require QA_BASE_DIR . 'qa-src/' . strtr(substr($class, 4), '\\', '/') . '.php';
} }
...@@ -260,7 +256,7 @@ function qa_initialize_constants_2() ...@@ -260,7 +256,7 @@ function qa_initialize_constants_2()
if (QA_DEBUG_PERFORMANCE) { if (QA_DEBUG_PERFORMANCE) {
global $qa_usage; global $qa_usage;
$qa_usage = new Q2A_Util_Usage; $qa_usage = new \Q2A\Util\Usage;
// ensure errors are displayed // ensure errors are displayed
@ini_set('display_errors', 'On'); @ini_set('display_errors', 'On');
} }
...@@ -386,7 +382,7 @@ function qa_register_core_modules() ...@@ -386,7 +382,7 @@ function qa_register_core_modules()
function qa_initialize_predb_plugins() function qa_initialize_predb_plugins()
{ {
global $qa_pluginManager; global $qa_pluginManager;
$qa_pluginManager = new Q2A_Plugin_PluginManager(); $qa_pluginManager = new \Q2A\Plugin\PluginManager();
$qa_pluginManager->readAllPluginMetadatas(); $qa_pluginManager->readAllPluginMetadatas();
$qa_pluginManager->loadPluginsBeforeDbInit(); $qa_pluginManager->loadPluginsBeforeDbInit();
...@@ -439,7 +435,7 @@ function qa_page_db_fail_handler($type, $errno = null, $error = null, $query = n ...@@ -439,7 +435,7 @@ function qa_page_db_fail_handler($type, $errno = null, $error = null, $query = n
* If $versiononly is true, only min version metadata is parsed. * If $versiononly is true, only min version metadata is parsed.
* Name, Description, Min Q2A & Min PHP are not currently used by themes. * Name, Description, Min Q2A & Min PHP are not currently used by themes.
* *
* @deprecated Deprecated from 1.7; Q2A_Util_Metadata class and metadata.json files should be used instead * @deprecated Deprecated from 1.7; \Q2A\Util\Metadata class and metadata.json files should be used instead
* @param string $contents * @param string $contents
* @param string $type * @param string $type
* @param bool|null $versiononly * @param bool|null $versiononly
......
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/Q2A/Plugin/PluginManager.php
Description: Keeps track of the installed plugins
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
...@@ -21,7 +16,12 @@ ...@@ -21,7 +16,12 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class Q2A_Plugin_PluginManager namespace Q2A\Plugin;
/**
* Keeps track of the installed plugins.
*/
class PluginManager
{ {
const PLUGIN_DELIMITER = ';'; const PLUGIN_DELIMITER = ';';
const OPT_ENABLED_PLUGINS = 'enabled_plugins'; const OPT_ENABLED_PLUGINS = 'enabled_plugins';
...@@ -40,7 +40,7 @@ class Q2A_Plugin_PluginManager ...@@ -40,7 +40,7 @@ class Q2A_Plugin_PluginManager
continue; continue;
} }
$metadataUtil = new Q2A_Util_Metadata(); $metadataUtil = new \Q2A\Util\Metadata();
$metadata = $metadataUtil->fetchFromAddonPath($pluginDirectory); $metadata = $metadataUtil->fetchFromAddonPath($pluginDirectory);
if (empty($metadata)) { if (empty($metadata)) {
// limit plugin parsing to first 8kB // limit plugin parsing to first 8kB
......
...@@ -3,10 +3,6 @@ ...@@ -3,10 +3,6 @@
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/Q2A/Util/Metadata.php
Description: Some useful metadata handling stuff
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
...@@ -20,7 +16,12 @@ ...@@ -20,7 +16,12 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class Q2A_Util_Metadata namespace Q2A\Util;
/**
* Some useful metadata handling stuff.
*/
class Metadata
{ {
const METADATA_FILE_JSON = 'metadata.json'; const METADATA_FILE_JSON = 'metadata.json';
......
...@@ -3,10 +3,6 @@ ...@@ -3,10 +3,6 @@
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/Q2A/Util/Usage.php
Description: Debugging stuff, currently used for tracking resource usage
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
...@@ -20,7 +16,12 @@ ...@@ -20,7 +16,12 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class Q2A_Util_Usage namespace Q2A\Util;
/**
* Debugging stuff, currently used for tracking resource usage.
*/
class Usage
{ {
private $stages; private $stages;
private $startUsage; private $startUsage;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment