Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-10-13 06:21:24 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-10-13 06:21:24 +0400
commit9f4ba4eea6c85a92b87fbad6f0556ee5d8551762 (patch)
tree0225fe694c5d6b15ca9ba9d528e16f03ce4249bd /core
parentc87dc623acf264d7559991cfc66cefa85bba4f1f (diff)
refs #5940 moved files into a subfolder framework, added autoloader to remove duplicated code to load autoload.php and to be able to register more autoloaders (eg for test files) on demand. This I got read of many includes that had to be updated all the time and that had to be updated all the time when moving iles
Diffstat (limited to 'core')
-rw-r--r--core/Loader.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/core/Loader.php b/core/Loader.php
new file mode 100644
index 0000000000..932c89d5bd
--- /dev/null
+++ b/core/Loader.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+
+namespace Piwik;
+
+/**
+ * Initializes the Composer Autoloader
+ * @package Piwik
+ */
+class Loader
+{
+ public static function init()
+ {
+ return self::getLoader();
+ }
+
+ /**
+ * @return \Composer\Autoload\ClassLoader
+ */
+ private static function getLoader()
+ {
+ if (file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php')) {
+ $path = PIWIK_INCLUDE_PATH . '/vendor/autoload.php'; // Piwik is the main project
+ } else {
+ $path = PIWIK_INCLUDE_PATH . '/../../autoload.php'; // Piwik is installed as a dependency
+ }
+
+ $loader = require $path;
+
+ return $loader;
+ }
+
+ public static function registerTestNamespace()
+ {
+ $prefix = 'Piwik\\Tests\\';
+ $paths = PIWIK_INCLUDE_PATH . '/tests/PHPUnit';
+
+ $loader = self::getLoader();
+ $loader->addPsr4($prefix, $paths, $prepend = false);
+ }
+}