From 7c5be1ee6a3c1f699bab9a8a11680c9d13af3817 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 26 Jun 2015 10:23:15 +0200 Subject: rewite autoloader --- php-bartlett-PHP-Reflect-3.0.0-rpm.patch | 143 ------------------------------ php-bartlett-PHP-Reflect-3.1.1-rpm.patch | 144 +++++++++++++++++++++++++++++++ php-bartlett-PHP-Reflect-autoload.php | 46 ++++++++++ php-bartlett-PHP-Reflect.spec | 29 ++++--- 4 files changed, 209 insertions(+), 153 deletions(-) delete mode 100644 php-bartlett-PHP-Reflect-3.0.0-rpm.patch create mode 100644 php-bartlett-PHP-Reflect-3.1.1-rpm.patch create mode 100644 php-bartlett-PHP-Reflect-autoload.php diff --git a/php-bartlett-PHP-Reflect-3.0.0-rpm.patch b/php-bartlett-PHP-Reflect-3.0.0-rpm.patch deleted file mode 100644 index 80e32f4..0000000 --- a/php-bartlett-PHP-Reflect-3.0.0-rpm.patch +++ /dev/null @@ -1,143 +0,0 @@ -diff -up ./bin/phpreflect.json.dist.rpm ./bin/phpreflect.json.dist ---- ./bin/phpreflect.json.dist.rpm 2015-05-11 12:55:49.000000000 +0200 -+++ ./bin/phpreflect.json.dist 2015-05-11 13:22:14.660514268 +0200 -@@ -6,6 +6,19 @@ - } - ], - "plugins": [ -+ { -+ "name": "Cache", -+ "class": "Bartlett\\Reflect\\Plugin\\CachePlugin", -+ "options": { -+ "adapter": "DoctrineCacheAdapter", -+ "backend": { -+ "class": "Doctrine\\Common\\Cache\\FilesystemCache", -+ "args": [ -+ "%{HOME}/.cache/php-reflect" -+ ] -+ } -+ } -+ } - ], - "analysers": [ - ], -diff -up ./bin/phpreflect.rpm ./bin/phpreflect ---- ./bin/phpreflect.rpm 2015-06-18 13:30:46.000000000 +0200 -+++ ./bin/phpreflect 2015-06-21 20:10:01.185883366 +0200 -@@ -5,19 +5,35 @@ $appName = 'phpReflect'; - if (\Phar::running()) { - $vendorDir = 'phar://' . strtolower($appName) . '.phar/vendor'; - } else { -- $baseDir = dirname(__DIR__); -- $vendorDir = $baseDir . '/vendor'; -- -- if (!file_exists($vendorDir . '/autoload.php')) { -- $vendorDir = dirname(dirname($baseDir)); -- } -+ $vendorDir = '/usr/share/php'; -+ putenv('BARTLETT_COMPATINFO_DB=/usr/share/php-bartlett-PHP-CompatInfo/compatinfo.sqlite'); - - if (!getenv("BARTLETTRC")) { - putenv("BARTLETTRC=" . strtolower($appName) . '.json'); - } - } --$loader = require_once $vendorDir . '/autoload.php'; --$loader->setUseIncludePath(true); -+ -+require_once $vendorDir . '/PhpParser/Autoloader.php'; -+PhpParser\Autoloader::register(); -+ -+require_once $vendorDir . '/Symfony/Component/ClassLoader/UniversalClassLoader.php'; -+require_once $vendorDir . '/SebastianBergmann/Version/autoload.php'; -+ -+use Symfony\Component\ClassLoader\UniversalClassLoader; -+ -+$loader = new UniversalClassLoader(); -+$loader->registerNamespaces(array( -+ 'Symfony\\Component' => $vendorDir, -+ 'Doctrine\\Common' => $vendorDir, -+ 'phpDocumentor\\Reflection' => $vendorDir, -+ 'Seld\\JsonLint' => $vendorDir, -+ 'JsonSchema' => $vendorDir, -+ 'Psr\\Log' => $vendorDir, -+ 'Monolog' => $vendorDir, -+ 'Bartlett' => $vendorDir, -+)); -+$loader->useIncludePath(true); -+$loader->register(); - - if (\Phar::running()) { - if ($home) { -@@ -40,5 +56,5 @@ use Bartlett\Reflect\Console\Application - - Environment::setScanDir(); - --$application = new Application($appName, '3.1'); -+$application = new Application($appName, '@package_version@'); - $application->run(); -diff -up ./src/Bartlett/Reflect/Console/Application.php.rpm ./src/Bartlett/Reflect/Console/Application.php ---- ./src/Bartlett/Reflect/Console/Application.php.rpm 2015-05-11 12:55:49.000000000 +0200 -+++ ./src/Bartlett/Reflect/Console/Application.php 2015-05-11 13:22:14.661514273 +0200 -@@ -82,7 +82,7 @@ class Application extends BaseApplicatio - $jsonFile = './' . getenv("BARTLETTRC"); - } - -- parent::__construct($appName, '@package_version@'); -+ parent::__construct($appName, $appVersion); - $this->release = $appVersion; - - $defaultAnalyser = (strcasecmp($appName, 'phpcompatinfo') === 0) -diff -up ./tests/bootstrap.php.rpm ./tests/bootstrap.php ---- ./tests/bootstrap.php.rpm 2015-05-11 12:55:49.000000000 +0200 -+++ ./tests/bootstrap.php 2015-05-11 13:22:14.661514273 +0200 -@@ -1,11 +1,9 @@ - addClassMap( -- array( -+$tab = array( - 'Bartlett\Tests\Reflect\Analyser\FooAnalyser' - => __DIR__ . '/Analyser/FooAnalyser.php', - 'Bartlett\Tests\Reflect\Analyser\BarAnalyser' -@@ -14,5 +12,24 @@ $loader->addClassMap( - => __DIR__ . '/Model/GenericModelTest.php', - 'Bartlett\Tests\Reflect\Environment\YourLogger' - => __DIR__ . '/Environment/YourLogger.php', -- ) - ); -+require_once $vendorDir . '/PhpParser/Autoloader.php'; -+PhpParser\Autoloader::register(); -+ -+require_once $vendorDir . '/Symfony/Component/ClassLoader/UniversalClassLoader.php'; -+ -+use Symfony\Component\ClassLoader\UniversalClassLoader; -+ -+$loader = new UniversalClassLoader(); -+$loader->registerNamespaces(array( -+ 'Bartlett\\Tests\\Reflect' => $baseDir . '/tests', -+ 'Bartlett\\UmlWriter' => $vendorDir, -+ 'Bartlett' => $baseDir . '/src', -+ 'Monolog' => $vendorDir, -+)); -+$loader->useIncludePath(true); -+$loader->register(); -+ -+foreach ($tab as $class => $file) { -+ require_once $file; -+} -diff -up ./tests/Environment/YourLogger.php.rpm ./tests/Environment/YourLogger.php ---- ./tests/Environment/YourLogger.php.rpm 2015-05-11 12:55:49.000000000 +0200 -+++ ./tests/Environment/YourLogger.php 2015-05-11 13:22:14.661514273 +0200 -@@ -14,6 +14,7 @@ class YourLogger extends Logger - if (!file_exists($tempDir)) { - mkdir($tempDir, 0755, true); - } -+ date_default_timezone_set('UTC'); - $filename = sprintf('phpreflect-%s.log', date('Ymd')); - - $stream = new RotatingFileHandler("$tempDir/$filename", 30); diff --git a/php-bartlett-PHP-Reflect-3.1.1-rpm.patch b/php-bartlett-PHP-Reflect-3.1.1-rpm.patch new file mode 100644 index 0000000..c4efe0c --- /dev/null +++ b/php-bartlett-PHP-Reflect-3.1.1-rpm.patch @@ -0,0 +1,144 @@ +diff -up ./bin/phpreflect.json.dist.rpm ./bin/phpreflect.json.dist +--- ./bin/phpreflect.json.dist.rpm 2015-06-18 13:30:46.000000000 +0200 ++++ ./bin/phpreflect.json.dist 2015-06-26 09:18:15.577663962 +0200 +@@ -6,6 +6,19 @@ + } + ], + "plugins": [ ++ { ++ "name": "Cache", ++ "class": "Bartlett\\Reflect\\Plugin\\CachePlugin", ++ "options": { ++ "adapter": "DoctrineCacheAdapter", ++ "backend": { ++ "class": "Doctrine\\Common\\Cache\\FilesystemCache", ++ "args": [ ++ "%{HOME}/.cache/php-reflect" ++ ] ++ } ++ } ++ } + ], + "analysers": [ + ], +diff -up ./bin/phpreflect.rpm ./bin/phpreflect +--- ./bin/phpreflect.rpm 2015-06-18 13:30:46.000000000 +0200 ++++ ./bin/phpreflect 2015-06-26 10:06:59.277781055 +0200 +@@ -2,35 +2,16 @@ + setUseIncludePath(true); +- +-if (\Phar::running()) { +- if ($home) { +- // when optional resources are not embedded in phar distribution, +- // avoid PHP Warnings, and lookup first in global vendor dir (COMPOSER_HOME) if exists +- $classMapfiltered = $fallbackClassMap($loader->getClassMap(), 'Net_Growl'); +- $loader->addClassMap($classMapfiltered); +- +- // try to find PEAR Net_Growl classes package in folder $fallbackNetGrowlDir (see phar-stub.php) +- $loader->add(false, $fallbackNetGrowlDir); +- } ++if (!getenv("BARTLETTRC")) { ++ putenv("BARTLETTRC=" . strtolower($appName) . '.json'); + } + ++require_once $vendorDir . '/Bartlett/Reflect/autoload.php'; ++ + if (PHP_SAPI !== 'cli') { + return; + } +@@ -40,5 +21,5 @@ use Bartlett\Reflect\Console\Application + + Environment::setScanDir(); + +-$application = new Application($appName, '3.1'); ++$application = new Application($appName, '@package_version@'); + $application->run(); +diff -up ./src/Bartlett/Reflect/Console/Application.php.rpm ./src/Bartlett/Reflect/Console/Application.php +--- ./src/Bartlett/Reflect/Console/Application.php.rpm 2015-06-18 13:30:46.000000000 +0200 ++++ ./src/Bartlett/Reflect/Console/Application.php 2015-06-26 09:18:15.584663991 +0200 +@@ -42,7 +42,7 @@ use Symfony\Component\EventDispatcher\Ev + * @package PHP_Reflect + * @author Laurent Laville + * @license http://www.opensource.org/licenses/bsd-license.php BSD License +- * @version Release: @package_version@ ++ * @version Release: 3.1.1 + * @link http://php5.laurent-laville.org/reflect/ + * @since Class available since Release 3.0.0-alpha1 + */ +@@ -82,7 +82,7 @@ class Application extends BaseApplicatio + $jsonFile = './' . getenv("BARTLETTRC"); + } + +- parent::__construct($appName, '@package_version@'); ++ parent::__construct($appName, $appVersion); + $this->release = $appVersion; + + $defaultAnalyser = (strcasecmp($appName, 'phpcompatinfo') === 0) +diff -up ./tests/bootstrap.php.rpm ./tests/bootstrap.php +--- ./tests/bootstrap.php.rpm 2015-06-18 13:30:46.000000000 +0200 ++++ ./tests/bootstrap.php 2015-06-26 10:07:14.589844514 +0200 +@@ -1,11 +1,9 @@ + addClassMap( +- array( ++$tab = array( + 'Bartlett\Tests\Reflect\Analyser\FooAnalyser' + => __DIR__ . '/Analyser/FooAnalyser.php', + 'Bartlett\Tests\Reflect\Analyser\BarAnalyser' +@@ -14,5 +12,17 @@ $loader->addClassMap( + => __DIR__ . '/Model/GenericModelTest.php', + 'Bartlett\Tests\Reflect\Environment\YourLogger' + => __DIR__ . '/Environment/YourLogger.php', +- ) + ); ++ ++require_once 'Bartlett/Reflect/autoload.php'; ++$fedoraClassLoader->addPrefix('Bartlett\\Tests\\Reflect', $baseDir . '/tests'); ++ ++// Needed when installed for 'Bartlett\CompatInfo\Analyser\CompatibilityAnalyser' ++if (is_file('/usr/share/php-bartlett-PHP-CompatInfo/compatinfo.sqlite')) { ++ putenv("BARTLETT_COMPATINFO_DB=/usr/share/php-bartlett-PHP-CompatInfo/compatinfo.sqlite"); ++} ++//print_r($fedoraClassLoader->getPrefixes()); ++ ++foreach ($tab as $class => $file) { ++ require_once $file; ++} +diff -up ./tests/Environment/YourLogger.php.rpm ./tests/Environment/YourLogger.php +--- ./tests/Environment/YourLogger.php.rpm 2015-06-18 13:30:46.000000000 +0200 ++++ ./tests/Environment/YourLogger.php 2015-06-26 09:18:15.578663966 +0200 +@@ -14,6 +14,7 @@ class YourLogger extends Logger + if (!file_exists($tempDir)) { + mkdir($tempDir, 0755, true); + } ++ date_default_timezone_set('UTC'); + $filename = sprintf('phpreflect-%s.log', date('Ymd')); + + $stream = new RotatingFileHandler("$tempDir/$filename", 30); diff --git a/php-bartlett-PHP-Reflect-autoload.php b/php-bartlett-PHP-Reflect-autoload.php new file mode 100644 index 0000000..9fe6a64 --- /dev/null +++ b/php-bartlett-PHP-Reflect-autoload.php @@ -0,0 +1,46 @@ +register(); +} +$fedoraClassLoader->addPrefixes(array( + 'Symfony\\Component' => $vendorDir, + 'JsonSchema' => $vendorDir, + 'Seld\\JsonLint' => $vendorDir, + 'Bartlett' => dirname(dirname(__DIR__)), +)); + +// Mandatory dependencies +require_once $vendorDir . '/PhpParser/Autoloader.php'; +PhpParser\Autoloader::register(); +require_once $vendorDir . '/SebastianBergmann/Version/autoload.php'; +require_once $vendorDir . '/Doctrine/Common/Collections/autoload.php'; +require_once $vendorDir . '/Doctrine/Common/Cache/autoload.php'; +require_once $vendorDir . '/phpDocumentor/Reflection/DocBlock/autoload.php'; + +// Needed when installed for 'Bartlett\CompatInfo\Analyser\CompatibilityAnalyser' +if (is_dir($vendorDir . '/Bartlett/CompatInfo')) { + $fedoraClassLoader->addPrefix('Bartlett\\CompatInfo', $vendorDir); +} + +// Optional dependencies +if (file_exists($vendorDir . '/Bartlett/UmlWriter/autoload.php')) { + require_once $vendorDir . '/Bartlett/UmlWriter/autoload.php'; +} +if (is_dir($vendorDir . '/Psr/Log')) { + $fedoraClassLoader->addPrefix('Psr\\Log', $vendorDir); +} +if (is_dir($vendorDir . '/Monolog')) { + $fedoraClassLoader->addPrefix('Monolog', $vendorDir); +} diff --git a/php-bartlett-PHP-Reflect.spec b/php-bartlett-PHP-Reflect.spec index 34b46ae..8e192c1 100644 --- a/php-bartlett-PHP-Reflect.spec +++ b/php-bartlett-PHP-Reflect.spec @@ -21,7 +21,7 @@ Name: php-bartlett-PHP-Reflect Version: 3.1.1 -%global specrel 2 +%global specrel 3 Release: %{?gh_date:0.%{specrel}.%{?prever}%{!?prever:%{gh_date}git%{gh_short}}}%{!?gh_date:%{specrel}}%{?dist} Summary: Adds the ability to reverse-engineer PHP @@ -31,8 +31,10 @@ URL: http://php5.laurent-laville.org/reflect/ Source0: https://github.com/%{gh_owner}/%{gh_project}/archive/%{gh_commit}/%{gh_project}-%{version}%{?prever}-%{gh_short}.tar.gz # Autoloader for RPM - die composer ! +Source1: %{name}-autoload.php + # Enable cache plugin -Patch0: %{name}-3.0.0-rpm.patch +Patch0: %{name}-3.1.1-rpm.patch BuildArch: noarch BuildRequires: php(language) >= 5.3 @@ -42,7 +44,6 @@ BuildRequires: %{_bindir}/phpunit BuildRequires: php-composer(sebastian/version) >= 1.0 BuildRequires: php-composer(nikic/php-parser) >= 1.2.2 BuildRequires: php-composer(doctrine/collections) >= 1.2 -BuildRequires: php-composer(symfony/class-loader) >= 2.5 BuildRequires: php-composer(symfony/event-dispatcher) >= 2.5 BuildRequires: php-composer(symfony/finder) >= 2.5 BuildRequires: php-composer(symfony/console) >= 2.5 @@ -52,7 +53,10 @@ BuildRequires: php-composer(phpdocumentor/reflection-docblock) >= 2.0 BuildRequires: php-composer(seld/jsonlint) >= 1.1 BuildRequires: php-composer(justinrainbow/json-schema) >= 1.3 BuildRequires: php-composer(monolog/monolog) >= 1.10 -BuildRequires: php-composer(bartlett/umlwriter) >= 1.0 +# For our patch / autoloader +BuildRequires: php-doctrine-collections >= 1.3.0-2 +BuildRequires: php-doctrine-cache >= 1.4.1 +BuildRequires: php-composer(symfony/class-loader) >= 2.5 %endif # From composer.json, "require": { @@ -122,9 +126,11 @@ Requires: php-composer(psr/log) >= 1.0 Requires: php-composer(bartlett/umlwriter) >= 1.0 Requires: php-composer(bartlett/umlwriter) < 2 %endif -# For our patch +# For our patch / autoloader Requires: php-composer(symfony/class-loader) >= 2.5 Requires: php-composer(symfony/class-loader) < 3 +Requires: php-doctrine-collections >= 1.3.0-2 +Requires: php-doctrine-cache >= 1.4.1 Obsoletes: php-channel-bartlett <= 1.3 @@ -142,6 +148,7 @@ Documentation: http://php5.laurent-laville.org/reflect/manual/current/en/ %setup -q -n %{gh_project}-%{gh_commit} %patch0 -p1 -b .rpm +cp %{SOURCE1} src/Bartlett/Reflect/autoload.php sed -e 's/@package_version@/%{version}%{?prever}/' \ -i $(find src -name \*.php) bin/phpreflect @@ -162,12 +169,11 @@ install -D -p -m 644 bin/phpreflect.1 %{buildroot}%{_mandir}/man1/phpref %check %if %{with_tests} -# Required when bartlett/php-compatinfo installed (local build) -export BARTLETT_COMPATINFO_DB=%{_datadir}/php-bartlett-PHP-CompatInfo/compatinfo.sqlite - -# Version 3.0.0 : OK, but incomplete, skipped, or risky tests! +# Version 3.1.1 : OK, but incomplete, skipped, or risky tests! # Tests: 122, Assertions: 123, Incomplete: 3. -%{_bindir}/phpunit -v +%{_bindir}/phpunit \ + --include-path=%{buildroot}%{_datadir}/php \ + --verbose %else : Test suite disabled %endif @@ -191,6 +197,9 @@ fi %changelog +* Fri Jun 26 2015 Remi Collet - 3.1.1-3 +- rewrite autoloader + * Sun Jun 21 2015 Remi Collet - 3.1.1-2 - fix autoloader -- cgit