From eecd3f0263fa1e9d95c8961604ec80f3cfc6c70e Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 29 Jun 2015 15:41:13 +0200 Subject: : better autoloader --- php-phpspec.spec | 14 ++++++++++---- phpspec-autoload.php | 38 ++++++++++++++++++++++---------------- phpspec-rpm.patch | 17 +++++++++++++---- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/php-phpspec.spec b/php-phpspec.spec index 66aa491..e45d5b8 100644 --- a/php-phpspec.spec +++ b/php-phpspec.spec @@ -13,7 +13,7 @@ Name: php-phpspec Version: 2.2.1 -Release: 1%{?dist} +Release: 3%{?dist} Summary: Specification-oriented BDD framework for PHP Group: Development/Libraries @@ -38,9 +38,10 @@ BuildRequires: php-composer(symfony/finder) >= 2.1 BuildRequires: php-composer(symfony/process) >= 2.1 BuildRequires: php-composer(symfony/yaml) >= 2.1 BuildRequires: php-composer(doctrine/instantiator) >= 1.0.1 -BuildRequires: php-composer(symfony/class-loader) # From composer.json, require-dev BuildRequires: php-composer(symfony/filesystem) >= 2.1 +# For our autoloader +BuildRequires: php-composer(symfony/class-loader) # From composer.json, require # "php": ">=5.3.3", @@ -122,14 +123,15 @@ install -Dpm755 bin/phpspec %{buildroot}%{_bindir}/phpspec %check export LANG=en_GB.utf8 + %{_bindir}/php \ - -d include_path=.:src:/usr/share/php \ + -d include_path=.:%{buildroot}%{_datadir}/php \ bin/phpspec \ run --format pretty --verbose --no-ansi %{_bindir}/phpunit \ --verbose \ - --bootstrap src/PhpSpec/autoload.php + --bootstrap %{buildroot}%{_datadir}/php/PhpSpec/autoload.php %clean @@ -147,6 +149,10 @@ rm -rf %{buildroot} %changelog +* Mon Jun 29 2015 Remi Collet - 2.2.1-3 +- switch to $fedoraClassLoader autoloader +- ensure /usr/share/php is in include_path + * Sat May 30 2015 Remi Collet - 2.2.1-1 - update to 2.2.1 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 @@ 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'; diff --git a/phpspec-rpm.patch b/phpspec-rpm.patch index d239a38..5a1d30d 100644 --- a/phpspec-rpm.patch +++ b/phpspec-rpm.patch @@ -1,6 +1,7 @@ ---- bin/phpspec.rpm 2015-04-19 06:39:34.900178171 +0200 -+++ bin/phpspec 2015-04-19 06:41:59.521743839 +0200 -@@ -5,22 +5,9 @@ +diff -up bin/phpspec.rpm bin/phpspec +--- bin/phpspec.rpm 2015-05-30 17:21:40.000000000 +0200 ++++ bin/phpspec 2015-06-29 15:29:46.783393891 +0200 +@@ -5,22 +5,18 @@ -if (is_file($autoload = getcwd() . '/vendor/autoload.php')) { - require $autoload; @@ -21,7 +22,15 @@ - 'php composer.phar install' . PHP_EOL - ); - exit(1); --} ++// Ensure correct include_path for RHSCL ++$inc = get_include_path(); ++$dirs = explode(':', $inc); ++if (!in_array('/usr/share/php', $dirs)) { ++ $dirs[] = '/usr/share/php'; ++ set_include_path(implode(':', $dirs)); + } ++unset ($inc, $dirs); ++ +require_once 'PhpSpec/autoload.php'; $app = new PhpSpec\Console\Application(PHPSPEC_VERSION); -- cgit