From 426858cb00e2f0df2e0bad989d27724ca5a8cbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Thu, 7 Nov 2013 19:45:52 -0200 Subject: [PATCH] Tweaks on Compile. --- Mage/Command/BuiltIn/CompileCommand.php | 47 ++++++++++++++++-- Mage/Compiler.php | 63 ------------------------- 2 files changed, 42 insertions(+), 68 deletions(-) delete mode 100644 Mage/Compiler.php diff --git a/Mage/Command/BuiltIn/CompileCommand.php b/Mage/Command/BuiltIn/CompileCommand.php index c6bef80..0892cd7 100644 --- a/Mage/Command/BuiltIn/CompileCommand.php +++ b/Mage/Command/BuiltIn/CompileCommand.php @@ -12,7 +12,10 @@ namespace Mage\Command\BuiltIn; use Mage\Command\AbstractCommand; use Mage\Console; -use Mage\Compiler; + +use Phar; +use RecursiveIteratorIterator; +use RecursiveDirectoryIterator; use Exception; @@ -24,14 +27,48 @@ use Exception; class CompileCommand extends AbstractCommand { /** - * @see \Mage\Compile::compile() + * Compiles Magallanes into a PHAR executable */ public function run () { - Console::output('Compiling Magallanes... ', 1, 0); + if (ini_get('phar.readonly')) { + Console::output('The php.ini variable phar.readonly must be enabled.', 1, 2); + return; + } - $compiler = new Compiler; - $compiler->compile(); + Console::output('Compiling Magallanes... ', 1, 0); + $file = 'mage.phar'; + + if (file_exists($file)) { + unlink($file); + } + + $phar = new Phar($file, 0, 'mage.phar'); + $phar->setSignatureAlgorithm(Phar::SHA1); + + $phar->startBuffering(); + + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__), RecursiveIteratorIterator::CHILD_FIRST); + /** @var $path SplFileInfo */ + foreach ($iterator as $path) { + if ($path->isFile()) { + $phar->addFromString(str_replace(dirname(__DIR__).'/', '', $path->getPathname()), file_get_contents($path)); + } + } + + $phar->addFromString('mage', str_replace( + '$baseDir = dirname(dirname(__FILE__));', + '$baseDir = __DIR__;', + file_get_contents(__DIR__.'/../bin/mage') + )); + + $phar->setStub("#!/usr/bin/env php\nstopBuffering(); + + unset($phar); + + chmod($file, 0755); Console::output('Mage compiled successfully'); } diff --git a/Mage/Compiler.php b/Mage/Compiler.php deleted file mode 100644 index 7a30cc7..0000000 --- a/Mage/Compiler.php +++ /dev/null @@ -1,63 +0,0 @@ - -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ - -namespace Mage; - -use Phar; -use RecursiveIteratorIterator; -use RecursiveDirectoryIterator; - -/** - * Compiles the library into a .phar file - * - * @author Ismael Ambrosi - */ -class Compiler -{ - - /** - * Compiles the library - * - * @param string $file - */ - public function compile($file = 'mage.phar') - { - if (file_exists($file)) { - unlink($file); - } - - $phar = new Phar($file, 0, 'mage.phar'); - $phar->setSignatureAlgorithm(Phar::SHA1); - - $phar->startBuffering(); - - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__), RecursiveIteratorIterator::CHILD_FIRST); - /** @var $path SplFileInfo */ - foreach ($iterator as $path) { - if ($path->isFile()) { - $phar->addFromString(str_replace(dirname(__DIR__).'/', '', $path->getPathname()), file_get_contents($path)); - } - } - - $phar->addFromString('mage', str_replace( - '$baseDir = dirname(dirname(__FILE__));', - '$baseDir = __DIR__;', - file_get_contents(__DIR__.'/../bin/mage') - )); - - $phar->setStub("#!/usr/bin/env php\nstopBuffering(); - - unset($phar); - - chmod($file, 0755); - } -}