je suis tout blanc avec Symfony, j'ignorais même que c'était installé sur mon serveur.
Dans mon projet de billets https://github.com/pixeline/bugs/
(en fait, c'est un projet orphelin que j'ai mis à jour)
Je trouve le fichier suivant
https://github.com/pixeline/bugs/tree/m ... /Shell.php
Je me dis alors que ce pourrait m'aider à passer une commande en console.
Mais voilà. Je n'ai aucune idée par où commencer.
Ici https://stackoverflow.com/questions/640 ... -php-shell , je trouve du code est des explications qui me mettent sur une piste.
<?php
namespace Acme\FooBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\Command,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console\Input\InputInterface,
Symfony\Component\Console\Output\OutputInterface;
class BarCommand extends Command
{
protected function configure()
{
$this
->setName('foo:bar-cmd')
->setDescription('Test command')
->addOption('baz', null, InputOption::VALUE_NONE, 'Test option');
;
}
/**
* Execute the command
* The environment option is automatically handled.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Test command');
}
}
C'est complété par
You can then run the command with:
$> app/console foo:bar-cmd
And pass in options like:
$> app/console foo:bar-cmd --baz
Mais je suis trop enfoncé dans le statut de « débutant » avec symfony pour y comprendre un peu.C'est charmant en console, mais moi je veux l'intégrer à du code PHP.
C'est quoi ce « bundle » dont il est question ?
La page mentionnée dit « tu crées un fichier Command » dans ton bundle.
Mon objectif est simple:
passer la commande « git pull » en PHP pour automatiser la mise à jour de l'application Bugs.
J'ai toujours programmé en style procédurale, mais voici que la programmation objet s'impose.
Comment créerai-je l'objet de mon rêve ?
Comment lui ferai-je exécuter ma commande ?
Merci