Browse Source

Merge pull request #6 from iambrosi/compiler

New PHAR compiler for the library
1.0
Andrés Montañez 12 years ago
parent
commit
7d8bf35df4
  1. 52
      Mage/Compiler.php
  2. 40
      Mage/Console.php
  3. 22
      Mage/Task/Compile.php

52
Mage/Compiler.php

@ -0,0 +1,52 @@
<?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);
chmod($file, 0755);
}
}

40
Mage/Console.php

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