I am using symfony 4 and I want to access a repository for an entity if I am in the Command class. There is not a function getDoctrine
or something..
I
Using Symfony 4.2 here.
use Symfony\Component\Console\Command\Command;
use Doctrine\DBAL\Connection;
class ArchiveCommand extends Command
{
protected static $defaultName = 'simon:test:archive';
private $connection;
public function __construct(Connection $connection)
{
$this->connection = $connection;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->connection->prepare('SQL HERE');
}
Works exactly as getting it from the container but is deprecated using it from the containerAwareInterface and should be injected now.