mirror of
https://github.com/hauke68/Magallanes.git
synced 2025-09-13 12:40:18 +02:00
New PHAR compiler for the library
This commit is contained in:
parent
db94f0320b
commit
c44879dc22
50
Mage/Compiler.php
Normal file
50
Mage/Compiler.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Mage_Compiler
|
||||||
|
*
|
||||||
|
* Compiles the library into a .phar file
|
||||||
|
*
|
||||||
|
* @author Ismael Ambrosi<ismaambrosi@gmail.com>
|
||||||
|
*/
|
||||||
|
class Mage_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.php')
|
||||||
|
));
|
||||||
|
|
||||||
|
$phar->setStub("#!/usr/bin/env php\n<?php Phar::mapPhar('mage.phar'); require 'phar://mage.phar/mage'; __HALT_COMPILER();");
|
||||||
|
|
||||||
|
$phar->stopBuffering();
|
||||||
|
|
||||||
|
unset($phar);
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,9 @@ class Mage_Console
|
|||||||
} else if ($this->_args[0] == 'update') {
|
} else if ($this->_args[0] == 'update') {
|
||||||
$this->_action = 'update';
|
$this->_action = 'update';
|
||||||
|
|
||||||
|
} else if ($this->_args[0] == 'compile') {
|
||||||
|
$this->_action = 'compile';
|
||||||
|
|
||||||
} else if ($this->_args[0] == 'add') {
|
} else if ($this->_args[0] == 'add') {
|
||||||
$this->_action = 'add';
|
$this->_action = 'add';
|
||||||
|
|
||||||
@ -165,6 +168,11 @@ class Mage_Console
|
|||||||
$task->run($config);
|
$task->run($config);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'compile';
|
||||||
|
$task = new Mage_Task_Compile;
|
||||||
|
$task->run($config);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'install';
|
case 'install';
|
||||||
$task = new Mage_Task_Install;
|
$task = new Mage_Task_Install;
|
||||||
$task->run();
|
$task->run();
|
||||||
|
22
Mage/Task/Compile.php
Normal file
22
Mage/Task/Compile.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Mage_Task_Compile
|
||||||
|
*
|
||||||
|
* @author Ismael Ambrosi<ismaambrosi@gmail.com>
|
||||||
|
*/
|
||||||
|
class Mage_Task_Compile
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @see Mage_Compile::compile()
|
||||||
|
*/
|
||||||
|
public function run ()
|
||||||
|
{
|
||||||
|
Mage_Console::output('Compiling <dark_gray>Magallanes</dark_gray>... ', 1, 0);
|
||||||
|
|
||||||
|
$compiler = new Mage_Compiler();
|
||||||
|
$compiler->compile();
|
||||||
|
|
||||||
|
Mage_Console::output('Mage compiled successfully');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user