diff options
-rwxr-xr-x | php-symfony4-generate-autoloaders.php | 109 | ||||
-rw-r--r-- | php-symfony4.spec | 23 |
2 files changed, 113 insertions, 19 deletions
diff --git a/php-symfony4-generate-autoloaders.php b/php-symfony4-generate-autoloaders.php index 557ff68..232435e 100755 --- a/php-symfony4-generate-autoloaders.php +++ b/php-symfony4-generate-autoloaders.php @@ -8,11 +8,18 @@ require_once '__PHPDIR__/Fedora/Autoloader/autoload.php'; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; +use Symfony\Component\Process\Exception\ProcessFailedException; +use Symfony\Component\Process\Process; $finder = new Finder(); -$finder->in(SYMFONY_SOURCE_DIR)->name('composer.json')->sortByName(); +$finder + ->in(SYMFONY_SOURCE_DIR) + ->notPath('Tests') + ->name('composer.json') + ->sortByName(); foreach ($finder as $composerFile) { + fprintf(STDERR, 'generating autoloader from %s'.PHP_EOL, $composerFile); $autoloadGenerator = new AutoloadGenerator($composerFile); echo $autoloadGenerator->getFilename().PHP_EOL; echo $autoloadGenerator->getDevFilename().PHP_EOL; @@ -359,11 +366,17 @@ final class AutoloadGenerator { private $devFilename = null; public function __construct(SplFileInfo $composerFile) { + $composerPath = $composerFile->getPath(); $composerJson = static::composerJson($composerFile); // autoload.php $content = static::content( - $composerJson, + $composerPath, + $composerJson['name'], + isset($composerJson['autoload']['psr-0']) ? $composerJson['autoload']['psr-0'] : [], + isset($composerJson['autoload']['psr-4']) ? $composerJson['autoload']['psr-4'] : [], + isset($composerJson['autoload']['files']) ? $composerJson['autoload']['files'] : [], + isset($composerJson['autoload']['classmap']) ? $composerJson['autoload']['classmap'] : [], static::dependencyAutoloaders($composerJson, 'require'), static::dependencyAutoloaders($composerJson, 'suggest') ); @@ -377,7 +390,12 @@ final class AutoloadGenerator { // autoload-dev.php $content = static::content( - $composerJson, + $composerPath, + $composerJson['name'], + [], + [], + [], + [], static::dependencyAutoloaders($composerJson, 'require-dev'), [], true @@ -458,8 +476,18 @@ final class AutoloadGenerator { : sprintf("%s.'/%s'", $prefix, $path); } - public function content($composerJson, array $dependencyAutoloadersRequired, array $dependencyAutoloadersOptional = [], $dev = false) { - $pkg = explode('/', $composerJson['name'])[1]; + public function content( + $path, + $name, + array $psr0, + array $psr4, + array $files, + array $classmap, + array $dependencyAutoloadersRequired, + array $dependencyAutoloadersOptional, + $dev = false + ) { + $pkg = explode('/', $name)[1]; $content = <<<AUTOLOAD <?php @@ -495,22 +523,89 @@ AUTOLOAD; } } + // PSR-0 + if (!empty($psr0)) { + $content .= PHP_EOL.'// Self PSR-0'.PHP_EOL; + + foreach ($psr0 as $namespace => $directory) { + $content .= sprintf( + "\\Fedora\\Autoloader\\Autoload::addPsr0('%s', %s, true);".PHP_EOL, + str_replace('\\', '\\\\', $namespace), + $directory ? "'$directory'" : '__DIR__' + ); + } + } + + // PSR-4 + if (!empty($psr4)) { + $content .= PHP_EOL.'// Self PSR-4'.PHP_EOL; + + foreach ($psr4 as $namespace => $directory) { + $content .= sprintf( + "\\Fedora\\Autoloader\\Autoload::addPsr4('%s', %s, true);".PHP_EOL, + str_replace('\\', '\\\\', $namespace), + $directory ? "'$directory'" : '__DIR__' + ); + } + } + + // Files + if (!empty($files)) { + $content .= PHP_EOL.'// Self files'.PHP_EOL; + + foreach ($files as $file) { + $content .= sprintf( + "require_once __DIR__.'/$file';".PHP_EOL, + $file + ); + } + } + + // Classmap + if (!empty($classmap)) { + $cmd = array_merge( + [ + 'phpab', + '--template', 'fedora', + '--output', 'autoload.classmap.php', + ], + $classmap + ); + + $process = new Process($cmd, $path); + $process->run(); + + if (!$process->isSuccessful()) { + throw new ProcessFailedException($process); + } + + $content .= <<<SELF_CLASSMAP + +// Self classmap +require_once __DIR__.'/autoload.classmap.php'; + +SELF_CLASSMAP; + } + + // Required dependencies if (!empty($dependencyAutoloadersRequired)) { $dependencyAutoloadersRequiredString = implode(",\n ", $dependencyAutoloadersRequired); $content .= <<<DEPENDENCY_AUTOLOADERS_REQUIRED - +// Required dependencies \Fedora\Autoloader\Dependencies::required([ $dependencyAutoloadersRequiredString ]); + DEPENDENCY_AUTOLOADERS_REQUIRED; } + // Optional dependencies if (!empty($dependencyAutoloadersOptional)) { $dependencyAutoloadersOptionalString = implode(",\n ", $dependencyAutoloadersOptional); $content .= <<<DEPENDENCY_AUTOLOADERS_REQUIRED - +// Optional dependencies \Fedora\Autoloader\Dependencies::optional([ $dependencyAutoloadersOptionalString ]); diff --git a/php-symfony4.spec b/php-symfony4.spec index d8c6326..af4485d 100644 --- a/php-symfony4.spec +++ b/php-symfony4.spec @@ -118,7 +118,7 @@ Name: php-%{composer_project}4 Version: %{github_version} -Release: 1%{?github_prerelease:.%{github_prerelease}}%{?dist} +Release: 2%{?github_prerelease:.%{github_prerelease}}%{?dist} Summary: Symfony PHP framework (version 4) # MIT and CC-BY-SA: @@ -171,7 +171,7 @@ BuildRequires: php-composer(ocramius/proxy-manager) >= %{proxy_manager_min_ver} BuildRequires: php-composer(phpdocumentor/reflection-docblock) < %{phpdocumentor_reflection_docblock_max_ver} BuildRequires: php-composer(phpdocumentor/reflection-docblock) >= %{phpdocumentor_reflection_docblock_min_ver} BuildConflicts: php-composer(phpdocumentor/reflection-docblock) = 3.2.0 -BuildRequires: php-composer(phpunit/phpunit) +BuildRequires: phpunit7 BuildRequires: php-composer(psr/cache) < %{psr_cache_max_ver} BuildRequires: php-composer(psr/cache) >= %{psr_cache_min_ver} BuildRequires: php-composer(psr/container) < %{psr_container_max_ver} @@ -220,7 +220,7 @@ BuildRequires: php-tokenizer BuildRequires: php-xml BuildRequires: php-xmlreader ## Autoloader -BuildRequires: php-composer(fedora/autoloader) +BuildRequires: php-fedora-autoloader-devel # Conflicts BuildConflicts: php-composer(phpdocumentor/type-resolver) < 0.3.0 @@ -228,10 +228,7 @@ BuildConflicts: php-composer(phpdocumentor/type-resolver) < 0.3.0 Requires: php-composer(%{composer_vendor}/doctrine-bridge) = %{version} Requires: php-composer(%{composer_vendor}/monolog-bridge) = %{version} #Requires: php-composer(%%{composer_vendor}/phpunit-bridge) = %%{version} -%if 0%{?fedora} >= 26 || 0%{?rhel} >= 8 -# this requires ZF and thus PHP 7 Requires: php-composer(%{composer_vendor}/proxy-manager-bridge) = %{version} -%endif Requires: php-composer(%{composer_vendor}/twig-bridge) = %{version} # Bundles Requires: php-composer(%{composer_vendor}/debug-bundle) = %{version} @@ -1957,10 +1954,6 @@ if (!defined('FEDORA_SYMFONY4_DIR')) { define('FEDORA_SYMFONY4_DIR', __DIR__); } -\Fedora\Autoloader\Autoload::addPsr4('Symfony\\Bridge\\', FEDORA_SYMFONY4_DIR.'/Bridge', true); -\Fedora\Autoloader\Autoload::addPsr4('Symfony\\Bundle\\', FEDORA_SYMFONY4_DIR.'/Bundle', true); -\Fedora\Autoloader\Autoload::addPsr4('Symfony\\Component\\', FEDORA_SYMFONY4_DIR.'/Component', true); - \Fedora\Autoloader\Dependencies::required([ '%{phpdir}/Composer/autoload.php', ]); @@ -2080,12 +2073,12 @@ for PKG in %{buildroot}%{symfony4_dir}/*/*; do cat << BOOTSTRAP | tee bootstrap.php <?php require_once '${PKG}/autoload-dev.php'; -require_once '%{buildroot}%{symfony4_dir}/Bridge/PhpUnit/bootstrap.php'; +require_once '%{buildroot}%{symfony4_dir}/Bridge/PhpUnit/autoload.php'; require_once '%{buildroot}%{symfony4_dir}/vendor/autoload.php'; BOOTSTRAP %{_bindir}/php -d include_path=.:${PSR0}:%{buildroot}%{phpdir}:%{phpdir} \ - %{_bindir}/phpunit --exclude-group benchmark $PKG || RET=1 + %{_bindir}/phpunit7 --exclude-group benchmark $PKG || RET=1 fi done exit $RET @@ -2921,6 +2914,12 @@ exit $RET # ############################################################################## %changelog +* Tue Nov 5 2019 Remi Collet <remi@remirepo.net> - 4.2.11-3 +- switch to phpunit7 + +* Sat Sep 14 2019 Shawn Iwinski <shawn.iwinski@gmail.com> - 4.2.11-2 +- Update autoloader generator to include self PSR-0, PSR-4, files, and classmap + * Tue Aug 20 2019 Remi Collet <remi@remirepo.net> - 4.2.11-1 - update to 4.2.11 |