Symfony\Component\DependencyInjection\ContainerInterface::get PHP Method

get() public method

Gets a service.
See also: Reference
public get ( string $id, integer $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE ) : object
$id string The service identifier
$invalidBehavior integer The behavior when the service does not exist
return object The associated service
    function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);

Usage Example

 /**
  * @param Schema $schema
  */
 public function up(Schema $schema)
 {
     $jobInstanceRepo = $this->container->get('pim_import_export.repository.job_instance');
     $channelRepo = $this->container->get('pim_catalog.repository.channel');
     $entityManager = $this->container->get('doctrine.orm.entity_manager');
     $validator = $this->container->get('validator');
     $jobInstances = $jobInstanceRepo->findBy(['type' => 'export']);
     foreach ($jobInstances as $jobInstance) {
         $parameters = $jobInstance->getRawParameters();
         // Only product exports have a parameter named 'channel'
         if (isset($parameters['channel'])) {
             $channel = $channelRepo->findOneByIdentifier($parameters['channel']);
             if (null === $channel) {
                 continue;
             }
             $locales = $channel->getLocales();
             $localeCodes = [];
             foreach ($locales as $locale) {
                 $localeCodes[] = $locale->getCode();
             }
             $parameters['filters'] = ['data' => [['field' => 'enabled', 'operator' => '=', 'value' => true], ['field' => 'categories.code', 'operator' => 'IN CHILDREN', 'value' => [$channel->getCategory()->getCode()]], ['field' => 'completeness', 'operator' => '>=', 'value' => 100]], 'structure' => ['scope' => $channel->getCode(), 'locales' => $localeCodes]];
             unset($parameters['channel']);
             $jobInstance->setRawParameters($parameters);
             $errors = $validator->validate($jobInstance);
             if (count($errors) === 0) {
                 $entityManager->persist($jobInstance);
                 $entityManager->flush();
             }
         }
     }
 }
All Usage Examples Of Symfony\Component\DependencyInjection\ContainerInterface::get