Browse Source

Issue #51

Possibility of custom commands.
1.0
Andrés Montañez 10 years ago
parent
commit
de51ce2b04
  1. 5
      Mage/Autoload.php
  2. 10
      Mage/Command/Factory.php

5
Mage/Autoload.php

@ -31,6 +31,11 @@ class Autoload
if (strpos($className, 'Task\\') === 0) { if (strpos($className, 'Task\\') === 0) {
$baseDir = getcwd() . '/.mage/tasks'; $baseDir = getcwd() . '/.mage/tasks';
$postfix = substr($postfix, 5); $postfix = substr($postfix, 5);
} else if (strpos($className, 'Command\\') === 0) {
$baseDir = getcwd() . '/.mage/commands';
$postfix = substr($postfix, 8);
} else { } else {
$baseDir = dirname(dirname(__FILE__)); $baseDir = dirname(dirname(__FILE__));
} }

10
Mage/Command/Factory.php

@ -10,6 +10,7 @@
namespace Mage\Command; namespace Mage\Command;
use Mage\Command\AbstractCommand;
use Mage\Config; use Mage\Config;
use Mage\Autoload; use Mage\Autoload;
@ -40,12 +41,17 @@ class Factory
$className = 'Mage\\Command\\BuiltIn\\' . $commandName . 'Command'; $className = 'Mage\\Command\\BuiltIn\\' . $commandName . 'Command';
if (!class_exists($className)) { if (!class_exists($className)) {
throw new Exception('Command "' . $commandName . '" not found.'); // try a custom command
$className = 'Command\\' . $commandName;
if (!class_exists($className)) {
throw new Exception('Command "' . $commandName . '" not found.');
}
} }
/** @var AbstractCommand $instance */ /** @var AbstractCommand $instance */
$instance = new $className; $instance = new $className;
if (!is_a($instance, "Mage\Command\AbstractCommand")) { if (! $instance instanceOf AbstractCommand) {
throw new Exception('The command ' . $commandName . ' must be an instance of Mage\Command\AbstractCommand.'); throw new Exception('The command ' . $commandName . ' must be an instance of Mage\Command\AbstractCommand.');
} }

Loading…
Cancel
Save