| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfSymfonyCommandApplication extends sfCommandApplication |
|---|
| 20 |
{ |
|---|
| 21 |
protected $taskFiles = array(); |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
* Configures the current symfony command application. |
|---|
| 25 |
*/ |
|---|
| 26 |
public function configure() |
|---|
| 27 |
{ |
|---|
| 28 |
if (!isset($this->options['symfony_lib_dir'])) |
|---|
| 29 |
{ |
|---|
| 30 |
throw new sfInitializationException('You must pass a "symfony_lib_dir" option.'); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
$configurationFile = getcwd().'/config/ProjectConfiguration.class.php'; |
|---|
| 34 |
if (is_readable($configurationFile)) |
|---|
| 35 |
{ |
|---|
| 36 |
require_once $configurationFile; |
|---|
| 37 |
$configuration = new ProjectConfiguration(getcwd(), $this->dispatcher); |
|---|
| 38 |
} |
|---|
| 39 |
else |
|---|
| 40 |
{ |
|---|
| 41 |
$configuration = new sfProjectConfiguration(getcwd(), $this->dispatcher); |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
$this->setName('symfony'); |
|---|
| 46 |
$this->setVersion(SYMFONY_VERSION); |
|---|
| 47 |
|
|---|
| 48 |
$this->loadTasks($configuration); |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
* Runs the current application. |
|---|
| 53 |
* |
|---|
| 54 |
* @param mixed $options The command line options |
|---|
| 55 |
* |
|---|
| 56 |
* @return integer 0 if everything went fine, or an error code |
|---|
| 57 |
*/ |
|---|
| 58 |
public function run($options = null) |
|---|
| 59 |
{ |
|---|
| 60 |
$this->handleOptions($options); |
|---|
| 61 |
$arguments = $this->commandManager->getArgumentValues(); |
|---|
| 62 |
|
|---|
| 63 |
if (!isset($arguments['task'])) |
|---|
| 64 |
{ |
|---|
| 65 |
$arguments['task'] = 'list'; |
|---|
| 66 |
$this->commandOptions .= $arguments['task']; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
$this->currentTask = $this->getTaskToExecute($arguments['task']); |
|---|
| 70 |
|
|---|
| 71 |
if ($this->currentTask instanceof sfCommandApplicationTask) |
|---|
| 72 |
{ |
|---|
| 73 |
$this->currentTask->setCommandApplication($this); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
$ret = $this->currentTask->runFromCLI($this->commandManager, $this->commandOptions); |
|---|
| 77 |
|
|---|
| 78 |
$this->currentTask = null; |
|---|
| 79 |
|
|---|
| 80 |
return $ret; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
* Loads all available tasks. |
|---|
| 85 |
* |
|---|
| 86 |
* Looks for tasks in the symfony core, the current project and all project plugins. |
|---|
| 87 |
* |
|---|
| 88 |
* @param sfProjectConfiguration $configuration The project configuration |
|---|
| 89 |
*/ |
|---|
| 90 |
protected function loadTasks(sfProjectConfiguration $configuration) |
|---|
| 91 |
{ |
|---|
| 92 |
|
|---|
| 93 |
$dirs = array(sfConfig::get('sf_symfony_lib_dir').'/task'); |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
foreach ($configuration->getPluginPaths() as $path) |
|---|
| 97 |
{ |
|---|
| 98 |
if (is_dir($taskPath = $path.'/lib/task')) |
|---|
| 99 |
{ |
|---|
| 100 |
$dirs[] = $taskPath; |
|---|
| 101 |
} |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
$dirs[] = sfConfig::get('sf_lib_dir').'/task'; |
|---|
| 106 |
|
|---|
| 107 |
$finder = sfFinder::type('file')->name('*Task.class.php'); |
|---|
| 108 |
foreach ($finder->in($dirs) as $file) |
|---|
| 109 |
{ |
|---|
| 110 |
$this->taskFiles[basename($file, '.class.php')] = $file; |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
spl_autoload_register(array($this, 'autoloadTask')); |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
foreach ($this->taskFiles as $task => $file) |
|---|
| 118 |
{ |
|---|
| 119 |
|
|---|
| 120 |
class_exists($task, true); |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
spl_autoload_unregister(array($this, 'autoloadTask')); |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
* Autoloads a task class |
|---|
| 129 |
* |
|---|
| 130 |
* @param string $class The task class name |
|---|
| 131 |
* |
|---|
| 132 |
* @return Boolean |
|---|
| 133 |
*/ |
|---|
| 134 |
public function autoloadTask($class) |
|---|
| 135 |
{ |
|---|
| 136 |
if (isset($this->taskFiles[$class])) |
|---|
| 137 |
{ |
|---|
| 138 |
require_once $this->taskFiles[$class]; |
|---|
| 139 |
|
|---|
| 140 |
return true; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
return false; |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
* @see sfCommandApplication |
|---|
| 148 |
*/ |
|---|
| 149 |
public function getLongVersion() |
|---|
| 150 |
{ |
|---|
| 151 |
return sprintf('%s version %s (%s)', $this->getName(), $this->formatter->format($this->getVersion(), 'INFO'), sfConfig::get('sf_symfony_lib_dir'))."\n"; |
|---|
| 152 |
} |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|