mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	
							parent
							
								
									426858cb00
								
							
						
					
					
						commit
						ee0bc27bc7
					
				@ -12,10 +12,7 @@ namespace Mage\Command\BuiltIn;
 | 
			
		||||
 | 
			
		||||
use Mage\Command\AbstractCommand;
 | 
			
		||||
use Mage\Console;
 | 
			
		||||
 | 
			
		||||
use Phar;
 | 
			
		||||
use RecursiveIteratorIterator;
 | 
			
		||||
use RecursiveDirectoryIterator;
 | 
			
		||||
use Mage\Compiler;
 | 
			
		||||
 | 
			
		||||
use Exception;
 | 
			
		||||
 | 
			
		||||
@ -27,48 +24,14 @@ use Exception;
 | 
			
		||||
class CompileCommand extends AbstractCommand
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Compiles Magallanes into a PHAR executable
 | 
			
		||||
     * @see \Mage\Compile::compile()
 | 
			
		||||
     */
 | 
			
		||||
    public function run ()
 | 
			
		||||
    {
 | 
			
		||||
    	if (ini_get('phar.readonly')) {
 | 
			
		||||
    		Console::output('The <purple>php.ini</purple> variable <light_red>phar.readonly</light_red> must be enabled.', 1, 2);
 | 
			
		||||
    		return;
 | 
			
		||||
    	}
 | 
			
		||||
 | 
			
		||||
        Console::output('Compiling <dark_gray>Magallanes</dark_gray>... ', 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\n<?php Phar::mapPhar('mage.phar'); require 'phar://mage.phar/mage'; __HALT_COMPILER();");
 | 
			
		||||
 | 
			
		||||
        $phar->stopBuffering();
 | 
			
		||||
 | 
			
		||||
        unset($phar);
 | 
			
		||||
 | 
			
		||||
        chmod($file, 0755);
 | 
			
		||||
        $compiler = new Compiler;
 | 
			
		||||
        $compiler->compile();
 | 
			
		||||
 | 
			
		||||
        Console::output('Mage compiled successfully');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										63
									
								
								Mage/Compiler.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								Mage/Compiler.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,63 @@
 | 
			
		||||
<?php
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the Magallanes package.
 | 
			
		||||
*
 | 
			
		||||
* (c) Andrés Montañez <andres@andresmontanez.com>
 | 
			
		||||
*
 | 
			
		||||
* 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<ismaambrosi@gmail.com>
 | 
			
		||||
 */
 | 
			
		||||
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\n<?php Phar::mapPhar('mage.phar'); require 'phar://mage.phar/mage'; __HALT_COMPILER();");
 | 
			
		||||
 | 
			
		||||
        $phar->stopBuffering();
 | 
			
		||||
 | 
			
		||||
        unset($phar);
 | 
			
		||||
 | 
			
		||||
        chmod($file, 0755);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user