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
 /**
  * @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();
             }
         }
     }
 }
Example #2
0
 protected function addMenuItem($menu, MenuItem $menuItem, $parent = null)
 {
     $container = $this->container;
     if (!($container->has('zym_menu.menu_manager') && $container->has('knp_menu.factory'))) {
         // ZymMenuBundle doesn't exist
         return;
     }
     /* @var $menuManager Entity\MenuManager */
     $menuManager = $this->container->get('zym_menu.menu_manager');
     /* @var $menuItemManager Entity\MenuItemManager */
     $menuItemManager = $this->container->get('zym_menu.menu_item_manager');
     // Management Menu
     $menu = $menuManager->findOneBy(array('name' => 'management'));
     if ($menu === null) {
         return;
     }
     $existingMenuItem = $menuItemManager->findMenuItemByName($menu, $menuItem->getName());
     if ($existingMenuItem instanceof Entity\MenuItem) {
         return;
     }
     if ($parent !== null) {
         $parentMenuItem = $menuItemManager->findMenuItemByName($menu, $parent);
         if ($parentMenuItem === null) {
             return;
         }
         $parentMenuItem->addChild($menuItem);
         $menuItemManager->createMenuItem($menuItem);
         $menuItemManager->saveMenuItem($parentMenuItem);
     } else {
         $menu->addChild($menuItem);
         $menuItemManager->createMenuItem($menuItem);
         $menuManager->saveMenu($menu);
     }
 }
 /**
  * @param string $matcherIdentifier
  *
  * @return \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MatcherInterface
  */
 protected function getMatcher($matcherIdentifier)
 {
     if ($this->container->has($matcherIdentifier)) {
         return $this->container->get($matcherIdentifier);
     }
     return parent::getMatcher($matcherIdentifier);
 }
 /**
  * Load the fixture jobs in database
  *
  * @return null
  */
 public function load()
 {
     $rawJobs = array();
     $fileLocator = $this->container->get('file_locator');
     foreach ($this->jobsFilePaths as $jobsFilePath) {
         $realPath = $fileLocator->locate('@' . $jobsFilePath);
         $this->reader->setFilePath($realPath);
         // read the jobs list
         while ($rawJob = $this->reader->read()) {
             $rawJobs[] = $rawJob;
         }
         // sort the jobs by order
         usort($rawJobs, function ($item1, $item2) {
             if ($item1['order'] === $item2['order']) {
                 return 0;
             }
             return $item1['order'] < $item2['order'] ? -1 : 1;
         });
     }
     // store the jobs
     foreach ($rawJobs as $rawJob) {
         unset($rawJob['order']);
         $job = $this->processor->process($rawJob);
         $config = $job->getRawConfiguration();
         $config['filePath'] = sprintf('%s/%s', $this->installerDataPath, $config['filePath']);
         $job->setRawConfiguration($config);
         $this->em->persist($job);
     }
     $this->em->flush();
 }
 public function convertFromLoanApp(LoanApplication $application)
 {
     $this->em->detach($application);
     $vantage = $this->formatVantage($application);
     $applicationXml = $this->container->get('templating')->render('SudouxMortgageBundle:LoanApplicationAdmin/formats:vantageFull.xml.twig', array('application' => $vantage), 'text/xml');
     return $applicationXml;
 }
 public function up(Schema $schema, QueryBag $queries)
 {
     $sqls = $this->container->get('test_service')->getQueries();
     foreach ($sqls as $sql) {
         $queries->addQuery($sql);
     }
 }
Example #7
0
 public function getClient()
 {
     if ($this->client === null) {
         $this->client = $this->container->get($this->clientServiceId);
     }
     return $this->client;
 }
Example #8
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $factory = $this->container->get('mautic.factory');
     $repo = $factory->getModel('page.page')->getRepository();
     $pages = CsvHelper::csv_to_array(__DIR__ . '/fakepagedata.csv');
     foreach ($pages as $count => $rows) {
         $page = new Page();
         $key = $count + 1;
         foreach ($rows as $col => $val) {
             if ($val != 'NULL') {
                 $setter = 'set' . ucfirst($col);
                 if (in_array($col, ['translationParent', 'variantParent'])) {
                     $page->{$setter}($this->getReference('page-' . $val));
                 } elseif (in_array($col, ['dateAdded', 'variantStartDate'])) {
                     $page->{$setter}(new \DateTime($val));
                 } elseif (in_array($col, ['content', 'variantSettings'])) {
                     $val = unserialize(stripslashes($val));
                     $page->{$setter}($val);
                 } else {
                     $page->{$setter}($val);
                 }
             }
         }
         $page->setCategory($this->getReference('page-cat-1'));
         $repo->saveEntity($page);
         $this->setReference('page-' . $key, $page);
     }
 }
 /**
  * Gets the appropriate resource owner given the name.
  *
  * @param string $name
  *
  * @return null|ResourceOwnerInterface
  */
 public function getResourceOwnerByName($name)
 {
     if (!$this->hasResourceOwnerByName($name)) {
         return null;
     }
     return $this->container->get('hwi_oauth.resource_owner.' . $name);
 }
 /**
  * {@inheritdoc}
  */
 public static function create(ContainerInterface $container) {
   return new static(
     $container->get('module_handler'),
     $container->get('composer_manager.package_manager'),
     $container->get('string_translation')
   );
 }
 /**
  * @before
  *
  */
 protected function setUpSymfonyKernel()
 {
     $this->kernel = $this->createKernel();
     $this->kernel->boot();
     $this->container = $this->kernel->getContainer();
     $this->logger = $this->container->get('logger');
 }
Example #12
0
 /**
  * @param ContainerInterface $container
  */
 public function __construct(ContainerInterface $container)
 {
     $this->container = $container;
     $this->requestStack = $container->get('request_stack');
     $this->request = $this->getCurrentRequest();
     $this->dispatcher = $container->get('event_dispatcher');
 }
 protected function initRepositories()
 {
     $doctrine = $this->container->get('doctrine');
     $this->countryRepository = $doctrine->getManagerForClass('OroAddressBundle:Country')->getRepository('OroAddressBundle:Country');
     $this->regionRepository = $doctrine->getManagerForClass('OroAddressBundle:Region')->getRepository('OroAddressBundle:Region');
     $this->addressTypeRepository = $doctrine->getManagerForClass('OroAddressBundle:AddressType')->getRepository('OroAddressBundle:AddressType');
 }
 /**
  * {@inheritdoc}
  */
 public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
   return new static(
     $entity_type,
     $container->get('entity.manager')->getStorage($entity_type->id()),
     $container->get('scheduled_updates.update_utils')
   );
 }
 /**
  * Checks whether an item is current.
  *
  * If the voter is not able to determine a result,
  * it should return null to let other voters do the job.
  *
  * @param \Knp\Menu\ItemInterface $item The item
  *
  * @return boolean|null
  */
 public function matchItem(ItemInterface $item)
 {
     if ($item->getUri() === $this->container->get('request')->getRequestUri()) {
         return true;
     }
     return false;
 }
Example #16
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $factory = $this->container->get('mautic.factory');
     $repo = $factory->getModel('page.page')->getRepository();
     $hits = CsvHelper::csv_to_array(__DIR__ . '/fakepagehitdata.csv');
     foreach ($hits as $count => $rows) {
         $hit = new Hit();
         foreach ($rows as $col => $val) {
             if ($val != 'NULL') {
                 $setter = 'set' . ucfirst($col);
                 if (in_array($col, ['page', 'ipAddress'])) {
                     $hit->{$setter}($this->getReference($col . '-' . $val));
                 } elseif (in_array($col, ['dateHit', 'dateLeft'])) {
                     $hit->{$setter}(new \DateTime($val));
                 } elseif ($col == 'browserLanguages') {
                     $val = unserialize(stripslashes($val));
                     $hit->{$setter}($val);
                 } else {
                     $hit->{$setter}($val);
                 }
             }
         }
         $repo->saveEntity($hit);
     }
 }
Example #17
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     declare (ticks=1);
     register_shutdown_function(array($this, 'stopCommand'));
     set_error_handler(array($this, 'errorHandler'));
     if (function_exists("pcntl_signal")) {
         pcntl_signal(SIGTERM, [$this, 'stopCommand']);
         pcntl_signal(SIGINT, [$this, 'stopCommand']);
     } else {
     }
     $this->isDebug = $input->getArgument('isDebug');
     $port = $input->getOption('port');
     $chat = $this->container->get('app.chat.handler');
     $chat->setIsDebug($this->isDebug);
     $messageManager = new MessageManager($chat);
     $messageManager->setIsDebug($this->isDebug);
     $server = IoServer::factory(new HttpServer(new WsServer($messageManager)), $port);
     if ($this->isDebug) {
         $redis = $this->container->get('snc_redis.default');
         $server->loop->addPeriodicTimer(5, function () use($redis, $messageManager) {
             $memory = memory_get_usage();
             echo "Send messages. Redis value: " . $redis->get('value') . "\r\n";
             $info = array();
             $info['message'] = "Redis value: " . $redis->get('value') . "; Memory: " . $memory;
             $info['type'] = 'message';
             $info['from'] = 'me';
             $messageManager->sendAll(json_encode($info));
         });
     }
     $this->logMessage("Start server.");
     $server->run();
     $this->logMessage("Finish execute daemon.");
 }
Example #18
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $model = $this->container->get('app_module_notebook.model.note');
     $modelTag = $this->container->get('app_module_notebook.model.noteTag');
     $entity = new Note();
     $entity->setNotebook($this->getReference(sprintf('notebook:%s:%s', 'Katie', 'Todo list')));
     $entity->setSubject('Close window at home');
     $entity->getTags()->add($modelTag->createOrGetTag('At home'));
     $model->save($entity);
     $entity = new Note();
     $entity->setNotebook($this->getReference(sprintf('notebook:%s:%s', 'Greg', 'Shopping list')));
     $entity->setSubject('Food for cat');
     $entity->getTags()->add($modelTag->createOrGetTag('Kitty'));
     $entity->getTags()->add($modelTag->createOrGetTag('Food'));
     $model->save($entity);
     $entity = new Note();
     $entity->setNotebook($this->getReference(sprintf('notebook:%s:%s', 'Greg', 'Shopping list')));
     $entity->setSubject('Food for cat');
     $entity->getTags()->add($modelTag->createOrGetTag('Doggy'));
     $entity->getTags()->add($modelTag->createOrGetTag('Food'));
     $model->save($entity);
     $entity = new Note();
     $entity->setNotebook($this->getReference(sprintf('notebook:%s:%s', 'Greg', 'Shopping list')));
     $entity->setSubject('Cheese');
     $entity->getTags()->add($modelTag->createOrGetTag('Food'));
     $entity->getTags()->add($modelTag->createOrGetTag('At home'));
     $model->save($entity);
     $entity = new Note();
     $entity->setNotebook($this->getReference(sprintf('notebook:%s:%s', 'Greg', 'Todo list')));
     $entity->setSubject('Write corporate scenarios at home');
     $entity->getTags()->add($modelTag->createOrGetTag('Food'));
     $entity->getTags()->add($modelTag->createOrGetTag('At home'));
     $model->save($entity);
 }
Example #19
0
 public function __construct(ContainerInterface $container)
 {
     $this->om = $container->get('claroline.persistence.object_manager');
     $this->roleManager = $container->get('claroline.manager.role_manager');
     $this->userManager = $container->get('claroline.manager.user_manager');
     $this->conn = $container->get('doctrine.dbal.default_connection');
 }
 /**
  * @param $action
  * @param \Doctrine\ORM\Mapping\ClassMetadata $meta
  * @param $entity
  */
 private function logEntityChange($action, \Doctrine\ORM\Mapping\ClassMetadata $meta, $entity)
 {
     $userToken = $this->container->get('security.context')->getToken();
     if (null !== $userToken) {
         $this->logger->info('Entity "' . $meta->getTableName() . '" with id: ' . $meta->getFieldValue($entity, $meta->getSingleIdentifierFieldName()) . ' ' . $action . ' by: ' . $this->container->get('security.context')->getToken()->getUsername());
     }
 }
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $kernel = $this->container->get('kernel');
     $router = $this->container->get('router');
     $route = $input->getOption('route');
     $uri = $input->getOption('uri');
     $uri = $route ? $router->generate($route) : $uri;
     $parameters = $input->getOption('parameters');
     $parameters = json_decode($parameters, JSON_OBJECT_AS_ARRAY);
     $cookies = $input->getOption('cookies');
     $cookies = json_decode($cookies, JSON_OBJECT_AS_ARRAY);
     $files = $input->getOption('files');
     $files = json_decode($files, JSON_OBJECT_AS_ARRAY);
     $server = $input->getOption('server');
     $server = json_decode($server, JSON_OBJECT_AS_ARRAY);
     $encoding = $input->getOption('encoding');
     $content = $input->getOption('content');
     $content = $this->decode($content, $encoding);
     $method = $input->getOption('method') ?: 'GET';
     $method = ($method === 'GET' and $content) ? 'POST' : $method;
     $request = Request::create($uri, $method, $parameters, $cookies, $files, $server, $content);
     $response = $kernel->handle($request, Kernel::SUB_REQUEST);
     $result = $response->getContent();
     if ($response->headers->get('Content-Type') === 'application/json') {
         $result = json_decode($result, JSON_OBJECT_AS_ARRAY);
         $result = json_encode($result, JSON_PRETTY_PRINT);
     }
     $output->writeln($result);
     return;
 }
 /**
  * {@inheritdoc}
  */
 protected function transformDataToArray($file)
 {
     if (strpos($file, "\n") === false && is_file($file)) {
         if (false === is_readable($file)) {
             throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $file));
         }
         if (null !== $this->container && $this->container->has('faker.generator')) {
             $generator = $this->container->get('faker.generator');
             $faker = function ($type) use($generator) {
                 $args = func_get_args();
                 array_shift($args);
                 echo Yaml::dump(call_user_func_array(array($generator, $type), $args)) . "\n";
             };
         } else {
             $faker = function ($text) {
                 echo $text . "\n";
             };
         }
         ob_start();
         $retval = (include $file);
         $content = ob_get_clean();
         // if an array is returned by the config file assume it's in plain php form else in YAML
         $file = is_array($retval) ? $retval : $content;
         // if an array is returned by the config file assume it's in plain php form else in YAML
         if (is_array($file)) {
             return $file;
         }
     }
     return Yaml::parse($file);
 }
Example #23
0
 public function getLocale()
 {
     if ($this->container->isScopeActive('request') && $this->container->has('request')) {
         return $this->container->get('request')->getSession()->getLang()->getLocale();
     }
     return $this->locale;
 }
 /**
  * {@inheritdoc}
  */
 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
 {
     // Create a new instance of the plugin. This also allows us to extract
     // services from the container and inject them into our plugin via its own
     // constructor as needed.
     return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity.manager'), $container->get('link_generator'), $container->get('request_stack'), $container->get('juicebox.formatter'));
 }
 /**
  * Lazy loads the real service from the container.
  *
  * @return object
  *   Returns the constructed real service.
  */
 protected function lazyLoadItself()
 {
     if (!isset($this->service)) {
         $this->service = $this->container->get($this->drupalProxyOriginalServiceId);
     }
     return $this->service;
 }
Example #26
0
 private function migrateExternalLinks(SessionInterface $session, $directionUp = true)
 {
     $workspace = $session->getWorkspace();
     $queryManager = $workspace->getQueryManager();
     $webspaceManager = $this->container->get('sulu_core.webspace.webspace_manager');
     $propertyEncoder = $this->container->get('sulu_document_manager.property_encoder');
     $webspaces = $webspaceManager->getWebspaceCollection();
     /** @var Webspace $webspace */
     foreach ($webspaces as $webspace) {
         foreach ($webspace->getAllLocalizations() as $localization) {
             $locale = $localization->getLocalization();
             $query = $queryManager->createQuery(sprintf('SELECT * FROM [nt:base] WHERE [%s] = 4 AND [jcr:mixinTypes] = "sulu:page"', $propertyEncoder->localizedSystemName('nodeType', $locale)), 'JCR-SQL2');
             $rows = $query->execute();
             foreach ($rows as $row) {
                 /** @var NodeInterface $node */
                 $node = $row->getNode();
                 $templatePropertyName = $propertyEncoder->localizedSystemName('template', $locale);
                 try {
                     if (true === $directionUp) {
                         $node->setProperty($templatePropertyName, $webspace->getDefaultTemplate('page'));
                     } else {
                         $node->setProperty($templatePropertyName, 'external-link');
                     }
                 } catch (\Exception $e) {
                     echo $e->getMessage() . PHP_EOL;
                 }
             }
         }
     }
 }
Example #27
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $user = new User();
     $user->setFirstName('Admin');
     $user->setLastName('User');
     $user->setUsername('admin');
     $user->setEmail('*****@*****.**');
     $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
     $user->setPassword($encoder->encodePassword('mautic', $user->getSalt()));
     $user->setRole($this->getReference('admin-role'));
     $manager->persist($user);
     $manager->flush();
     $this->addReference('admin-user', $user);
     $user = new User();
     $user->setFirstName('Sales');
     $user->setLastName('User');
     $user->setUsername('sales');
     $user->setEmail('*****@*****.**');
     $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
     $user->setPassword($encoder->encodePassword('mautic', $user->getSalt()));
     $user->setRole($this->getReference('sales-role'));
     $manager->persist($user);
     $manager->flush();
     $this->addReference('sales-user', $user);
 }
 public function setUp()
 {
     $kernel = new \AppKernel('test', true);
     $kernel->boot();
     $this->container = $kernel->getContainer();
     $this->service = $this->container->get('dugun_upload.service.upload_service');
 }
 /**
  * @return TagManager
  */
 protected function getTagManager()
 {
     if (!$this->tagManager) {
         $this->tagManager = $this->container->get($this->tagManagerService);
     }
     return $this->tagManager;
 }
 public function load1A($manager)
 {
     $test_password = '******';
     $factory = $this->container->get('security.encoder_factory');
     $finder = new Finder();
     $finder = Finder::create()->name('liste_1a_2015-2016.csv')->in(__DIR__ . '/../data/files');
     $rows = $this->parseCSV($finder);
     foreach ($rows as $key => $student) {
         /** @var $user \Application\Sonata\UserBundle\Entity\User */
         $user = new Student();
         $user->setSchoolClass($this->getReference('schoolClass.1A_' . mb_strtoupper($student[4])));
         $user->setUsername($student[1] . '.' . $student[2]);
         $user->setPlainPassword($test_password);
         $user->setEmail($student[5]);
         $user->setFirstname($student[1]);
         $user->setLastname($student[2]);
         // $user->setRoles(array('ROLE_USER'));
         $user->addGroup($this->getReference('schoolClass.1A_' . mb_strtoupper($student[4])));
         $user->setEnabled(true);
         $encoder = $factory->getEncoder($user);
         $password = $encoder->encodePassword($user->getPlainPassword(), $user->getSalt());
         $user->setPassword($password);
         $manager->updateUser($user);
     }
 }