Skip to content

Instantly share code, notes, and snippets.

@andreia
Created November 26, 2019 01:27
Show Gist options
  • Save andreia/65ab72de782352b0f9172b562765cf07 to your computer and use it in GitHub Desktop.
Save andreia/65ab72de782352b0f9172b562765cf07 to your computer and use it in GitHub Desktop.
A Symfony Command
<?php
// src/Command/SomeCommand.php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SomeCommand extends Command
{
// the name of the command (the part after "bin/console")
protected static $defaultName = 'app:some-command';
private $projectRootDir;
public function __construct($projectRootDir)
{
$this->projectRootDir = $projectRootDir;
parent::__construct();
}
protected function configure()
{
// ...
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// ...
$output->writeln("The project's root directory is: " . $this->projectRootDir);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment