Browse Source

New PHAR compiler for the library

1.0
Ismael Ambrosi 12 years ago
parent
commit
c44879dc22
  1. 50
      Mage/Compiler.php
  2. 40
      Mage/Console.php
  3. 22
      Mage/Task/Compile.php

50
Mage/Compiler.php

@ -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);
}
}

40
Mage/Console.php

@ -25,22 +25,25 @@ class Mage_Console
if ($this->_args[0] == 'deploy') { if ($this->_args[0] == 'deploy') {
$this->_action = 'deploy'; $this->_action = 'deploy';
} else if ($this->_args[0] == 'releases') { } else if ($this->_args[0] == 'releases') {
$this->_action = 'releases'; $this->_action = 'releases';
} 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';
} else if ($this->_args[0] == 'install') { } else if ($this->_args[0] == 'install') {
$this->_action = 'install'; $this->_action = 'install';
} else if ($this->_args[0] == 'upgrade') { } else if ($this->_args[0] == 'upgrade') {
$this->_action = 'upgrade'; $this->_action = 'upgrade';
} else if ($this->_args[0] == 'version') { } else if ($this->_args[0] == 'version') {
$this->_action = 'version'; $this->_action = 'version';
} else if ($this->_args[0] == 'init') { } else if ($this->_args[0] == 'init') {
@ -126,10 +129,10 @@ class Mage_Console
$config->loadSCM(); $config->loadSCM();
// Logging // Logging
$showGrettings = true; $showGrettings = true;
if (in_array($this->getAction(), array('install', 'upgrade', 'version'))) { if (in_array($this->getAction(), array('install', 'upgrade', 'version'))) {
self::$_logEnabled = false; self::$_logEnabled = false;
$showGrettings = false; $showGrettings = false;
} else { } else {
self::$_logEnabled = $config->general('logging', false); self::$_logEnabled = $config->general('logging', false);
} }
@ -145,19 +148,19 @@ class Mage_Console
$task->run($config); $task->run($config);
break; break;
case 'releases': case 'releases':
$task = new Mage_Task_Releases; $task = new Mage_Task_Releases;
switch ($this->_args[1]) { switch ($this->_args[1]) {
case 'list': case 'list':
$task->setAction($this->_args[1]); $task->setAction($this->_args[1]);
break; break;
case 'rollback': case 'rollback':
$task->setAction($this->_args[1]); $task->setAction($this->_args[1]);
$task->setRelease($this->_args[2]); $task->setRelease($this->_args[2]);
break; break;
} }
$task->run($config); $task->run($config);
break; break;
case 'update'; case 'update';
@ -165,14 +168,19 @@ 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();
break; break;
case 'upgrade'; case 'upgrade';
$task = new Mage_Task_Upgrade; $task = new Mage_Task_Upgrade;
$task->run(); $task->run();
break; break;
case 'init'; case 'init';
@ -195,8 +203,8 @@ class Mage_Console
} }
break; break;
case 'version'; case 'version';
$this->showVersion(); $this->showVersion();
break; break;
default: default:

22
Mage/Task/Compile.php

@ -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…
Cancel
Save