Skip to content

Commit

Permalink
Merge [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutierrez committed Nov 7, 2013
2 parents 31655e7 + b69af31 commit ac9b7aa
Show file tree
Hide file tree
Showing 18 changed files with 716 additions and 311 deletions.
11 changes: 7 additions & 4 deletions Library/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ public static function boot()
*/
foreach (new DirectoryIterator(ZEPHIRPATH . 'Library/Commands') as $item) {
if (!$item->isDir()) {
require $item->getRealPath();
$className = str_replace('.php', '', $item->getBaseName()) . 'Command';
$command = new $className();
self::$_commands[$command->getCommands()] = $command;
require_once $item->getRealPath();
$className = 'Command' . str_replace('.php', '', $item->getBaseName());
$class = new ReflectionClass($className);
if (!$class->isAbstract() && !$class->isInterface()) {
$command = new $className();
self::$_commands[$command->getCommand()] = $command;
}
}
}

Expand Down
60 changes: 60 additions & 0 deletions Library/Commands/Abstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/*
+--------------------------------------------------------------------------+
| Zephir Language |
+--------------------------------------------------------------------------+
| Copyright (c) 2013 Zephir Team and contributors |
+--------------------------------------------------------------------------+
| This source file is subject the MIT license, that is bundled with |
| this package in the file LICENSE, and is available through the |
| world-wide-web at the following url: |
| http://zephir-lang.com/license.html |
| |
| If you did not receive a copy of the MIT license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+--------------------------------------------------------------------------+
*/

require_once __DIR__ . '/Interface.php';
/**
* CommandAbstract
*
* Provides a superclass for commands
*/
abstract class CommandAbstract implements CommandInterface
{

/**
* Command provided by this command
*
* @return string
*/
abstract public function getCommand();

/**
* Command usage
*
* @return string
*/
abstract public function getUsage();

/**
* @return string
*/
abstract public function getDescription();

/**
* Executes the command
*
* Config $config
* Logger $logger
*/
public function execute(Config $config, Logger $logger)
{
$compiler = new Compiler($config, $logger);
$command = $this->getCommand();
$compiler->$command($this);
}
}
55 changes: 55 additions & 0 deletions Library/Commands/Clean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
+--------------------------------------------------------------------------+
| Zephir Language |
+--------------------------------------------------------------------------+
| Copyright (c) 2013 Zephir Team and contributors |
+--------------------------------------------------------------------------+
| This source file is subject the MIT license, that is bundled with |
| this package in the file LICENSE, and is available through the |
| world-wide-web at the following url: |
| http://zephir-lang.com/license.html |
| |
| If you did not receive a copy of the MIT license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+--------------------------------------------------------------------------+
*/

/**
* CleanCommand
*
* Produce the extension installation
*/
class CommandClean extends CommandAbstract
{

/**
* Command provided by this command
*
* @return string
*/
public function getCommand()
{
return 'clean';
}

/**
* Command usage
*
* @return string
*/
public function getUsage()
{
return 'clean';
}

/**
* @return string
*/
public function getDescription()
{
return 'Clean the extension code';
}
}
22 changes: 4 additions & 18 deletions Library/Commands/Compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
*
* Produce the extension installation
*/
class CompileCommand
class CommandCompile extends CommandAbstract
{

/**
* Commands provided by this command
*
* @return array|string
*/
public function getCommands()
public function getCommand()
{
return 'compile';
}
Expand All @@ -42,28 +42,14 @@ public function getCommands()
*/
public function getUsage()
{
return 'init [namespace]';
return 'compile';
}

/**
* @return string
*/
public function getDescription()
{
return 'Initializes a Zephir extension';
}

/**
* Executes the command
*
* Config $config
* Logger $logger
*/
public function execute(Config $config, Logger $logger)
{
$compiler = new Compiler();
$compiler->compile($config, $logger);
$compiler->install($config, $logger);
return 'Compile a Zephir extension';
}

}
23 changes: 5 additions & 18 deletions Library/Commands/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
*/

/**
* GenerateCommand
* CommandGenerate
*
* Generate the code without compiling it
*/
class GenerateCommand
class CommandGenerate extends CommandAbstract
{

/**
* Commands provided by this command
* Command provided by this command
*
* @return array|string
*/
public function getCommands()
public function getCommand()
{
return 'generate';
}
Expand All @@ -50,19 +50,6 @@ public function getUsage()
*/
public function getDescription()
{
return 'Compiles the extension without install it';
return 'Generates C code from the Zephir code';
}

/**
* Executes the command
*
* Config $config
* Logger $logger
*/
public function execute(Config $config, Logger $logger)
{
$compiler = new Compiler();
$compiler->compile($config, $logger);
}

}
17 changes: 7 additions & 10 deletions Library/Commands/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/

/**
* HelpCommand
* CommandHelp
*
* Shows compiler help
*/
class HelpCommand
class CommandHelp extends CommandAbstract
{
const LOGO ='
_____ __ _
Expand All @@ -34,11 +34,11 @@ class HelpCommand
';

/**
* Commands provided by this command
* Command provided by this command
*
* @return array|string
* @return string
*/
public function getCommands()
public function getCommand()
{
return 'help';
}
Expand All @@ -58,7 +58,7 @@ public function getUsage()
*/
public function getDescription()
{
return 'Displays help';
return 'Displays this help';
}

/**
Expand All @@ -69,9 +69,8 @@ public function getDescription()
*/
public function execute(Config $config, Logger $logger)
{

echo self::LOGO, PHP_EOL;
echo "zephir version " , VersionCommand::VERSION, PHP_EOL, PHP_EOL;
echo "zephir version " , CommandVersion::VERSION, PHP_EOL, PHP_EOL;
echo "Usage: ", PHP_EOL;
echo "\tcommand [options]", PHP_EOL;
echo PHP_EOL;
Expand All @@ -84,7 +83,5 @@ public function execute(Config $config, Logger $logger)
echo sprintf("\t%-20s%s\n", "-fno-([a-z0-9\-]+)", "Setting options to Compiler");
echo sprintf("\t%-20s%s\n", "-W([a-z0-9\-]+)", "Setting warning options to Compiler");
echo PHP_EOL;

}

}
33 changes: 17 additions & 16 deletions Library/Commands/Initialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
*/

/**
* InitializeCommand
* CommandInitialize
*
* Shows Zephir version
* Initialize a zephir extension
*/
class InitializeCommand
class CommandInitialize extends CommandAbstract
{

private $_namespace;

/**
* Commands provided by this command
* Command provided by this command
*
* @return array|string
* @return string
*/
public function getCommands()
public function getCommand()
{
return 'init';
}
Expand All @@ -53,16 +54,16 @@ public function getDescription()
return 'Initializes a Zephir extension';
}

/**
* Executes the command
*
* Config $config
* Logger $logger
*/
public function execute(Config $config, Logger $logger)
public function getNamespace()
{
$compiler = new Compiler();
$compiler->init($config, $logger);
return $this->_namespace;
}

public function execute(Config $config, Logger $logger)
{
if (isset($_SERVER['argv'][2])) {
$this->_namespace = strtolower(preg_replace('/[^0-9a-zA-Z]/', '', $_SERVER['argv'][2]));
}
parent::execute($config, $logger);
}
}
25 changes: 6 additions & 19 deletions Library/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
*/

/**
* InstallCommand
* CommandInstall
*
* Produce the extension installation
*/
class InstallCommand
class CommandInstall extends CommandAbstract
{

/**
* Commands provided by this command
* Command provided by this command
*
* @return array|string
* @return string
*/
public function getCommands()
public function getCommand()
{
return 'install';
}
Expand All @@ -50,19 +50,6 @@ public function getUsage()
*/
public function getDescription()
{
return 'Installs the extension';
}

/**
* Executes the command
*
* Config $config
* Logger $logger
*/
public function execute(Config $config, Logger $logger)
{
$compiler = new Compiler();
$compiler->install($config, $logger);
return 'Installs the extension (requires root password)';
}

}
Loading

0 comments on commit ac9b7aa

Please sign in to comment.