* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * Creates a task skeleton * * @package symfony * @subpackage task * @author Francois Zaninotto */ class sfGenerateTaskTask extends sfBaseTask { /** * @see sfTask */ protected function configure() { $this->addArguments(array( new sfCommandArgument('task_name', sfCommandArgument::REQUIRED, 'The task name (can contain namespace)'), )); $this->addOptions(array( new sfCommandOption('dir', null, sfCommandOption::PARAMETER_REQUIRED, 'The directory to create the task in', 'lib/task'), new sfCommandOption('use-database', null, sfCommandOption::PARAMETER_REQUIRED, 'Whether the task needs model initialization to access database', sfConfig::get('sf_orm')), new sfCommandOption('brief-description', null, sfCommandOption::PARAMETER_REQUIRED, 'A brief task description (appears in task list)'), )); $this->namespace = 'generate'; $this->name = 'task'; $this->briefDescription = 'Creates a skeleton class for a new task'; $this->detailedDescription = <<addArguments(array( // new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'), // )); \$this->addOptions(array( new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name'), new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', '$defaultConnection'), // add your own options here )); \$this->namespace = '$namespace'; \$this->name = '$name'; \$this->briefDescription = '$briefDescription'; \$this->detailedDescription = <<configuration); \$connection = \$databaseManager->getDatabase(\$options['connection'])->getConnection(); // add your code here } } HED; } else { $content = <<addArguments(array( // new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'), // )); // // add your own options here // \$this->addOptions(array( // new sfCommandOption('my_option', null, sfCommandOption::PARAMETER_REQUIRED, 'My option'), // )); \$this->namespace = '$namespace'; \$this->name = '$name'; \$this->briefDescription = '$briefDescription'; \$this->detailedDescription = <<getFilesystem()->mkdirs($options['dir']); } $taskFile = sfConfig::get('sf_root_dir').'/'.$options['dir'].'/'.$taskClassName.'.class.php'; if (is_readable($taskFile)) { throw new sfCommandException(sprintf('A "%s" task already exists in "%s".', $taskName, $taskFile)); } $this->logSection('task', sprintf('Creating "%s" task file', $taskFile)); file_put_contents($taskFile, $content); } }