Skip to content

Latest commit

 

History

History
14 lines (12 loc) · 574 Bytes

getting-services-from-the-service-container.md

File metadata and controls

14 lines (12 loc) · 574 Bytes

Getting Services from the Service Container

By using ContainerAwareCommand as the base class for the command (instead of the more basic Command), you have access to the service container. In other words, you have access to any configured service using the provided getService method.

protected function execute(InputInterface $input, OutputInterface $output)
{
    $uid = $input->getArgument('uid');
    $entityManager = $this->getService('entity.manager');
    if ($entityManager) {
        $user = $entityManager->getStorage('user')->load($uid);
    }
}