summaryrefslogtreecommitdiffstats
path: root/phpspec-autoload.php
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2015-06-29 15:41:13 +0200
committerRemi Collet <fedora@famillecollet.com>2015-06-29 15:41:13 +0200
commiteecd3f0263fa1e9d95c8961604ec80f3cfc6c70e (patch)
treee1bc0292492dad7426784405b2532d243dec8aa9 /phpspec-autoload.php
parentaa4c1536fd1956a51a161fe5e6bf3dcf25347413 (diff)
: better autoloader
Diffstat (limited to 'phpspec-autoload.php')
-rw-r--r--phpspec-autoload.php38
1 files changed, 22 insertions, 16 deletions
diff --git a/phpspec-autoload.php b/phpspec-autoload.php
index 47f19c5..1fb529a 100644
--- a/phpspec-autoload.php
+++ b/phpspec-autoload.php
@@ -1,23 +1,29 @@
<?php
-/* not namespaced, use classs-map */
-require_once 'phpspec/php-diff/autoload.php';
-/* prophecy and its dependencies */
-require_once 'Prophecy/autoload.php';
+/* Autoloader for phpspec/phpspec and its dependencies */
$vendorDir = '/usr/share/php';
-require_once $vendorDir . '/Symfony/Component/ClassLoader/UniversalClassLoader.php';
-use Symfony\Component\ClassLoader\UniversalClassLoader;
+// Use Symfony autoloader
+if (!isset($fedoraClassLoader) || !($fedoraClassLoader instanceof \Symfony\Component\ClassLoader\ClassLoader)) {
+ if (!class_exists('Symfony\\Component\\ClassLoader\\ClassLoader', false)) {
+ require_once $vendorDir . '/Symfony/Component/ClassLoader/ClassLoader.php';
+ }
+
+ $fedoraClassLoader = new \Symfony\Component\ClassLoader\ClassLoader();
+ $fedoraClassLoader->register();
+}
+
+$fedoraClassLoader->addPrefixes(array(
+ 'Symfony\\Component\\' => $vendorDir,
+ 'PhpSpec\\' => dirname(__DIR__),
+));
-$loader = new UniversalClassLoader();
-$ns = array(
- 'Doctrine\\Instantiator' => $vendorDir,
- 'SebastianBergmann' => $vendorDir,
- 'Symfony\\Component' => $vendorDir,
- 'PhpSpec' => dirname(__DIR__),
-);
/* spec tree in current dir, when exists */
if (is_dir(getcwd().'/spec')) {
- $ns['spec'] = getcwd();
+ $fedoraClassLoader->addPrefix('spec', getcwd());
}
-$loader->registerNamespaces($ns);
-$loader->register();
+
+// Depdencies (Rely on include_path as in PHPUnit dependencies + circular dependencies)
+require_once 'phpspec/php-diff/autoload.php';
+require_once 'Prophecy/autoload.php';
+require_once 'SebastianBergmann/Exporter/autoload.php';
+require_once 'Doctrine/Instantiator/autoload.php';