I\'m writing an open source application uses some Symfony components, and using Symfony Console component for interacting with shell.
But, i need to inject dependen
Since Symfony 4.2 the ContainerAwareCommand is deprecated. Use the DI instead.
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Doctrine\ORM\EntityManagerInterface;
final class YourCommand extends Command
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// YOUR CODE
$this->entityManager->persist($object1);
}
}