diff -Nru phpab-1.24.1/CHANGELOG.md phpab-1.25.0/CHANGELOG.md --- phpab-1.24.1/CHANGELOG.md 2017-06-26 07:50:31.000000000 +0000 +++ phpab-1.25.0/CHANGELOG.md 2018-07-01 13:38:49.000000000 +0000 @@ -1,5 +1,9 @@ # Changelog +## Release 1.25.0 +* Add support for generating static files to use for opcache warming (-w, optionally with --reset) +* Minor internal cleanup + ## Release 1.24.1 * Merge PR [#78](https://github.com/theseer/Autoload/pull/78): Restore PHP 5.3 compatibility [Remi] diff -Nru phpab-1.24.1/debian/changelog phpab-1.25.0/debian/changelog --- phpab-1.24.1/debian/changelog 2017-10-24 22:13:09.000000000 +0000 +++ phpab-1.25.0/debian/changelog 2018-07-12 05:49:17.000000000 +0000 @@ -1,3 +1,29 @@ +phpab (1.25.0-1build4) cosmic; urgency=medium + + * Rebuild against new phpunit7 bootstrapped stack. + + -- Gianfranco Costamagna Thu, 12 Jul 2018 07:49:17 +0200 + +phpab (1.25.0-1build3) cosmic; urgency=medium + + * Rebuild against new phpunit7 bootstrap. + + -- Gianfranco Costamagna Thu, 12 Jul 2018 00:00:53 +0200 + +phpab (1.25.0-1) unstable; urgency=medium + + * Team upload + + [ Arne Blankerts ] + * Add opcache warming mode feature + * Update changelog + + [ David Prévot ] + * Move project repository to salsa.d.o + * Update Standards-Version to 4.1.5 + + -- David Prévot Sat, 07 Jul 2018 19:15:01 -1000 + phpab (1.24.1-1) unstable; urgency=medium * Team upload diff -Nru phpab-1.24.1/debian/control phpab-1.25.0/debian/control --- phpab-1.24.1/debian/control 2017-10-24 22:13:09.000000000 +0000 +++ phpab-1.25.0/debian/control 2018-07-08 05:10:54.000000000 +0000 @@ -9,9 +9,9 @@ php-zeta-console-tools, phpunit, pkg-php-tools (>= 1.7~) -Standards-Version: 4.1.1 -Vcs-Browser: http://anonscm.debian.org/cgit/pkg-php/phpab.git -Vcs-Git: git://anonscm.debian.org/pkg-php/phpab.git +Standards-Version: 4.1.5 +Vcs-Browser: https://salsa.debian.org/php-team/pear/phpab +Vcs-Git: https://salsa.debian.org/php-team/pear/phpab.git Homepage: https://github.com/theseer/Autoload Package: phpab diff -Nru phpab-1.24.1/README.md phpab-1.25.0/README.md --- phpab-1.24.1/README.md 2017-06-26 07:50:31.000000000 +0000 +++ phpab-1.25.0/README.md 2018-07-01 13:38:49.000000000 +0000 @@ -130,14 +130,14 @@ This usually also happens after pulling from a repo or when switchting branches. Using a git `post-checkout` hook placed in `.git/hooks/post-update` this can be automated for most cases. -####Basic Sample: +#### Basic Sample: ```bash #!/bin/bash phpab -c -o src/autoload.inc.php src ``` -####Sample using an `ant build.xml` file. +#### Sample using an `ant build.xml` file. ```bash #!/bin/bash diff -Nru phpab-1.24.1/src/autoload.php phpab-1.25.0/src/autoload.php --- phpab-1.24.1/src/autoload.php 2017-06-26 07:50:31.000000000 +0000 +++ phpab-1.25.0/src/autoload.php 2018-07-01 13:38:49.000000000 +0000 @@ -109,6 +109,7 @@ 'theseer\\autoload\\cache' => '/Cache.php', 'theseer\\autoload\\cacheentry' => '/CacheEntry.php', 'theseer\\autoload\\cacheexception' => '/Cache.php', + 'theseer\\autoload\\cachewarminglistrenderer' => '/CacheWarmingListRenderer.php', 'theseer\\autoload\\cachingparser' => '/CachingParser.php', 'theseer\\autoload\\classdependencysorter' => '/DependencySorter.php', 'theseer\\autoload\\classdependencysorterexception' => '/DependencySorter.php', @@ -130,7 +131,9 @@ 'theseer\\autoload\\pathcomparator' => '/PathComparator.php', 'theseer\\autoload\\pharbuilder' => '/PharBuilder.php', 'theseer\\autoload\\sourcefile' => '/SourceFile.php', + 'theseer\\autoload\\staticlistrenderer' => '/StaticListRenderer.php', 'theseer\\autoload\\staticrenderer' => '/StaticRenderer.php', + 'theseer\\autoload\\staticrequirelistrenderer' => '/StaticRequireListRenderer.php', 'theseer\\autoload\\version' => '/Version.php', 'theseer\\directoryscanner\\directoryscanner' => '/../vendor/theseer/directoryscanner/src/directoryscanner.php', 'theseer\\directoryscanner\\exception' => '/../vendor/theseer/directoryscanner/src/directoryscanner.php', diff -Nru phpab-1.24.1/src/CacheWarmingListRenderer.php phpab-1.25.0/src/CacheWarmingListRenderer.php --- phpab-1.24.1/src/CacheWarmingListRenderer.php 1970-01-01 00:00:00.000000000 +0000 +++ phpab-1.25.0/src/CacheWarmingListRenderer.php 2018-07-01 13:38:49.000000000 +0000 @@ -0,0 +1,39 @@ +addReset = $addReset; + $this->indent = $indent; + $this->linebreak = $linebreak; + } + + /** + * @return string + */ + public function render(array $list) { + $line = $this->indent . 'opcache_compile_file('; + $glue = ');' . $this->linebreak . $line; + + $firstLine = $this->addReset ? $this->indent . 'opcache_reset();' . $this->linebreak : ''; + return $firstLine . $line . implode($glue, $list) . ');'; + + } +} diff -Nru phpab-1.24.1/src/CLI.php phpab-1.25.0/src/CLI.php --- phpab-1.24.1/src/CLI.php 2017-06-26 07:50:31.000000000 +0000 +++ phpab-1.25.0/src/CLI.php 2018-07-01 13:38:49.000000000 +0000 @@ -53,14 +53,17 @@ const RC_DUPLICATES_ERROR = 5; private $pharOption; + private $staticOption; private $helpOption; private $versionOption; + private $onceOption; /** * @var Factory */ private $factory; + public function __construct(Factory $factory) { $this->factory = $factory; } @@ -212,6 +215,14 @@ if ($input->getOption('once')->value) { $config->setOnceMode(TRUE); } + + if ($input->getOption('warm')->value) { + $config->setWarmMode(TRUE); + } + if ($input->getOption('reset')->value) { + $config->setResetMode(TRUE); + } + if ($input->getOption('follow')->value) { $config->setFollowSymlinks(TRUE); } @@ -282,7 +293,10 @@ -t, --template Path to code template to use -o, --output Output file for generated code (default: STDOUT) + -p, --phar Create a phar archive (requires -o ) + --all Include all files in given directory when creating a phar + --alias Specify explicit internal phar alias filename (default: output filename) --hash Force given hash algorithm (SHA-1, SHA-256 or SHA-512) (requires -p, conflicts with --key) --bzip2 Compress phar archive using bzip2 (requires -p) (bzip2 required) --gz Compress phar archive using gzip (requires -p) (gzip required) @@ -290,6 +304,9 @@ -c, --compat Generate PHP 5.2 compatible code -s, --static Generate a static require file + + -w, --warm Generate a static opcache warming file + --reset Add opcache reset call when generating opcache warming file -1, --prepend Register as first autoloader (prepend to stack, default: append) -d, --no-exception Do not throw exception on registration problem (default: throw exception) @@ -308,8 +325,6 @@ --tolerant Ignore Class Redeclarations in the same file --once Use require_once instead of require when creating a static require file - --all Include all files in given directory when creating a phar - --alias Specify explicit internal phar alias filename (default: output filename) --trusting Do not check mimetype of files prior to parsing (default) --paranoid Do check mimetype of files prior to parsing @@ -340,7 +355,7 @@ $this->helpOption->shorthelp = 'Prints this usage information'; $input->registerOption( new \ezcConsoleOption( - '', 'cache', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, + NULL, 'cache', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Enable cache and set cache filename' )); @@ -357,28 +372,28 @@ )); $input->registerOption( new \ezcConsoleOption( - '', 'all', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, + NULL, 'all', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Add all files from src dir to phar', NULL, array( new \ezcConsoleOptionRule( $input->getOption( 'p' ) ) ) )); $input->registerOption( new \ezcConsoleOption( - '', 'alias', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, + NULL, 'alias', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Provide explicit internal alias filename for phar', NULL, array( new \ezcConsoleOptionRule( $input->getOption( 'p' ) ) ) )); $bzip2 = $input->registerOption( new \ezcConsoleOption( - '', 'bzip2', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, + NULL, 'bzip2', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Compress files phar with bzip2', NULL, array( new \ezcConsoleOptionRule( $input->getOption( 'p' ) ) ) )); $gzip = $input->registerOption( new \ezcConsoleOption( - '', 'gzip', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, + NULL, 'gzip', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Compress files phar with gzip', NULL, array( new \ezcConsoleOptionRule( $input->getOption( 'p' ) ) ), @@ -387,14 +402,14 @@ $bzip2->addExclusion(new \ezcConsoleOptionRule($gzip)); $input->registerOption( new \ezcConsoleOption( - '', 'key', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, + NULL, 'key', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Keyfile to use for signing phar archive', NULL, array( new \ezcConsoleOptionRule( $input->getOption( 'p' ) ) ) )); $this->outputOption = $input->registerOption( new \ezcConsoleOption( - '', 'hash', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, + NULL, 'hash', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Force given hash algorithm (SHA-1, SHA-256 or SHA-512) (requires -p)', NULL, array( new \ezcConsoleOptionRule( $input->getOption( 'p' ) ) ), @@ -407,12 +422,12 @@ )); $input->registerOption( new \ezcConsoleOption( - '', 'blacklist', \ezcConsoleInput::TYPE_STRING, NULL, TRUE, + NULL, 'blacklist', \ezcConsoleInput::TYPE_STRING, NULL, TRUE, 'Name pattern to exclude' )); $input->registerOption( new \ezcConsoleOption( - '', 'whitelist', \ezcConsoleInput::TYPE_STRING, '*', TRUE, + NULL, 'whitelist', \ezcConsoleInput::TYPE_STRING, '*', TRUE, 'Name pattern to include (default: *)' )); @@ -432,7 +447,7 @@ )); $input->registerOption( new \ezcConsoleOption( - '', 'follow', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, + NULL, 'follow', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Enables following symbolic links', NULL, array(), @@ -440,27 +455,27 @@ )); $input->registerOption( new \ezcConsoleOption( - '', 'format', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, + NULL, 'format', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Dateformat string for timestamp' )); $input->registerOption( new \ezcConsoleOption( - '', 'linebreak', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, + NULL, 'linebreak', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Linebreak style (CR, CR/LF or LF)' )); $input->registerOption( new \ezcConsoleOption( - '', 'indent', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, + NULL, 'indent', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'String used for indenting (default: 3 spaces)' )); $this->lintOption = $input->registerOption( new \ezcConsoleOption( - '', 'lint', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, + NULL, 'lint', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Run lint on generated code' )); $input->registerOption( new \ezcConsoleOption( - '', 'lint-php', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, + NULL, 'lint-php', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'PHP binary path for linting (default: /usr/bin/php or c:\\php\\php.exe)', NULL, array( new \ezcConsoleOptionRule( $input->getOption( 'lint' ) ) ) @@ -477,16 +492,16 @@ )); $input->registerOption( new \ezcConsoleOption( - '', 'tolerant', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, + NULL, 'tolerant', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Ignore Class Redeclarations in the same file' )); $trusting = $input->registerOption( new \ezcConsoleOption( - '', 'trusting', \ezcConsoleInput::TYPE_NONE, TRUE, FALSE, + NULL, 'trusting', \ezcConsoleInput::TYPE_NONE, TRUE, FALSE, 'Do not check mimetype of files prior to parsing' )); $paranoid = $input->registerOption( new \ezcConsoleOption( - '', 'paranoid', \ezcConsoleInput::TYPE_NONE, FALSE, FALSE, + NULL, 'paranoid', \ezcConsoleInput::TYPE_NONE, FALSE, FALSE, 'Do check mimetype of files prior to parsing', NULL, array(), @@ -495,7 +510,7 @@ $trusting->addExclusion(new \ezcConsoleOptionRule($paranoid)); $this->onceOption = $input->registerOption( new \ezcConsoleOption( - '', 'once', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, + NULL, 'once', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Use require_once in static require mode', NULL, array( new \ezcConsoleOptionRule( $input->getOption( 's' ) ) ) @@ -529,6 +544,26 @@ 'Assign variable' )); + $warm = $input->registerOption( new \ezcConsoleOption( + 'w','warm', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, + 'generate opcache warming file', + NULL, + array(), + array( + new \ezcConsoleOptionRule($this->pharOption), + new \ezcConsoleOptionRule($this->staticOption) + ) + )); + + $input->registerOption( new \ezcConsoleOption( + NULL,'reset', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, + 'add reset call to generated opcache warming file', + NULL, + array( + new \ezcConsoleOptionRule($warm) + ) + )); + $input->argumentDefinition = new \ezcConsoleArguments(); $input->argumentDefinition[0] = new \ezcConsoleArgument('directory'); $input->argumentDefinition[0]->shorthelp = 'The directory to process.'; diff -Nru phpab-1.24.1/src/Config.php phpab-1.25.0/src/Config.php --- phpab-1.24.1/src/Config.php 2017-06-26 07:50:31.000000000 +0000 +++ phpab-1.25.0/src/Config.php 2018-07-01 13:38:49.000000000 +0000 @@ -55,9 +55,11 @@ private $php; private $compatMode = FALSE; private $staticMode = FALSE; + private $warmMode = FALSE; private $tolerant = FALSE; private $trusting = TRUE; private $once = FALSE; + private $reset = FALSE; private $lowercase = TRUE; private $dateFormat; private $variable = array(); @@ -166,7 +168,7 @@ } return $this->indent; } - if ($this->isStaticMode()) { + if ($this->isStaticMode() || $this->isWarmMode()) { return ''; } return str_repeat(' ', $this->isCompatMode() ? 12 : 16); @@ -282,12 +284,30 @@ public function setStaticMode($staticMode) { $this->staticMode = (boolean)$staticMode; + $this->warmMode = FALSE; } public function isStaticMode() { return $this->staticMode; } + public function setWarmMode($warmMode) { + $this->warmMode = (boolean)$warmMode; + $this->staticMode = FALSE; + } + + public function isWarmMode() { + return $this->warmMode; + } + + public function setResetMode($resetMode) { + $this->reset = (boolean)$resetMode; + } + + public function isResetMode() { + return $this->reset; + } + public function setTemplate($template) { $this->template = $template; } @@ -322,7 +342,7 @@ } else { $tplFile = 'phar.php.tpl'; } - } elseif ($this->isStaticMode()) { + } elseif ($this->isStaticMode() || $this->isWarmMode()) { $tplFile = 'static.php.tpl'; $tplType = '.'; } diff -Nru phpab-1.24.1/src/Factory.php phpab-1.25.0/src/Factory.php --- phpab-1.24.1/src/Factory.php 2017-06-26 07:50:31.000000000 +0000 +++ phpab-1.25.0/src/Factory.php 2018-07-01 13:38:49.000000000 +0000 @@ -163,12 +163,23 @@ $isPhar = $this->config->isPharMode(); $isCompat = $this->config->isCompatMode(); $isOnce = $this->config->isOnceMode(); + $isWarm = $this->config->isWarmMode(); + $isReset = $this->config->isResetMode(); - if ($isStatic === TRUE) { - $renderer = new StaticRenderer($result->getUnits()); + if ($isWarm === TRUE) { + $renderer = new StaticRenderer( + $result->getUnits(), + $this->getCacheWarmingListRenderer($isReset) + ); + $renderer->setDependencies($result->getDependencies()); + $renderer->setPharMode($isPhar); + } else if ($isStatic === TRUE) { + $renderer = new StaticRenderer( + $result->getUnits(), + $this->getStaticRequireListRenderer($isOnce) + ); $renderer->setDependencies($result->getDependencies()); $renderer->setPharMode($isPhar); - $renderer->setRequireOnce($isOnce); } else { $renderer = new AutoloadRenderer($result->getUnits()); if ($this->config->usePrepend()) { @@ -202,6 +213,22 @@ return $renderer; } + private function getStaticRequireListRenderer($useOnce) { + return new StaticRequireListRenderer( + $useOnce, + $this->config->getIndent(), + $this->config->getLinebreak() + ); + } + + private function getCacheWarmingListRenderer($addReset) { + return new CacheWarmingListRenderer( + $addReset, + $this->config->getIndent(), + $this->config->getLinebreak() + ); + } + } } diff -Nru phpab-1.24.1/src/StaticListRenderer.php phpab-1.25.0/src/StaticListRenderer.php --- phpab-1.24.1/src/StaticListRenderer.php 1970-01-01 00:00:00.000000000 +0000 +++ phpab-1.25.0/src/StaticListRenderer.php 2018-07-01 13:38:49.000000000 +0000 @@ -0,0 +1,10 @@ +renderHelper = $renderHelper; + } /** * Setter for Dependency Array @@ -72,9 +82,9 @@ * @param boolean $mode */ public function setRequireOnce($mode) { - $this->require = (boolean)$mode ? 'require_once' : 'require'; } + /** * @param string $template * @@ -90,12 +100,15 @@ $entries = $this->sortByDependency(); - $replace = array_merge($this->variables, array( - '___CREATED___' => date( $this->dateformat, $this->timestamp ? $this->timestamp : time()), - '___FILELIST___' => join( $this->linebreak . $this->indent, $entries), - '___BASEDIR___' => $baseDir, - '___AUTOLOAD___' => uniqid('autoload', true) - )); + $replace = array_merge( + $this->variables, + array( + '___CREATED___' => date( $this->dateformat, $this->timestamp ? $this->timestamp : time()), + '___FILELIST___' => $this->renderHelper->render($entries), + '___BASEDIR___' => $baseDir, + '___AUTOLOAD___' => uniqid('autoload', true) + ) + ); return str_replace(array_keys($replace), array_values($replace), $template); } @@ -114,10 +127,11 @@ if (!empty($this->baseDir) && strpos($fname, $this->baseDir)===0) { $fname = str_replace($this->baseDir, '', $fname); } - $entries[] = $this->require . " ___BASEDIR___'$fname';"; + $entries[] = "___BASEDIR___'$fname'"; } return $entries; } + } } diff -Nru phpab-1.24.1/src/StaticRequireListRenderer.php phpab-1.25.0/src/StaticRequireListRenderer.php --- phpab-1.24.1/src/StaticRequireListRenderer.php 1970-01-01 00:00:00.000000000 +0000 +++ phpab-1.25.0/src/StaticRequireListRenderer.php 2018-07-01 13:38:49.000000000 +0000 @@ -0,0 +1,33 @@ +useOnce = $useOnce; + $this->indent = $indent; + $this->linebreak = $linebreak; + } + + /** + * @return string + */ + public function render(array $list) { + $require = (boolean)$this->useOnce ? 'require_once' : 'require'; + $glue = ';' . $this->linebreak . $this->indent . $require . ' '; + + return $this->indent . $require . ' ' . implode($glue, $list) . ';'; + } +}