新しいコンソールコマンドを作成すると、探していることが達成されます。
コマンドコード
MyCool / Bundle / Command / GenerateSchemaUpdateCommand.php
<?php
namespace MyCool\Bundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class GenerateSchemaUpdateCommand extends ContainerAwareCommand
{
/**
* Configure command, set parameters definition and help.
*/
protected function configure()
{
$this
->setName('mycoolbundle:schema:update')
->setDescription('Perform my custom schema update.')
->setHelp(sprintf(
'Performs the doctrine:schema:update plus adds our custom records. \n' .
PHP_EOL
));
}
/**
* Execution Code
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output = system('php -f app/console doctrine:schema:update --force');
// do your custom things here.
echo $output;
}
}
コマンドを実行する
php -f app/console mycoolbundle:schema:update
引数の追加
次の方法でコマンドに引数を追加できます。
addArgument('var_name', InputArgument::OPTIONAL, 'Help message...')
// InputArgument::REQUIRED is also available here
ノート
このようにすることで、コンソールコマンドに多くの機能を追加できるようになります。さらに、モデルとエンティティが必要になった場合に、それらに直接アクセスできるようになります。