/** * @InjectParams({ * "container" = @Inject("service_container") * }) */ public function __construct(ContainerInterface $container) { $this->container = $container; $this->fileTypes = '/\\.yml$/'; $this->driverPath = $container->getParameter('kernel.root_dir') . '/config/Authentication/'; $this->finder = new Finder(); }
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); }
/** * Construct. * * @param ContainerInterface $container An ContainerInterface instance */ public function __construct(ContainerInterface $container) { $this->publicKey = $container->getParameter('ewz_recaptcha.public_key'); $this->secure = $container->getParameter('ewz_recaptcha.secure'); $this->enabled = $container->getParameter('ewz_recaptcha.enabled'); $this->language = $container->getParameter('session.default_locale'); }
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); } }
public function getClient() { if ($this->client === null) { $this->client = $this->container->get($this->clientServiceId); } return $this->client; }
/** * {@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); }
/** * @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()); } }
public function onKernelException(GetResponseForExceptionEvent $event) { if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { return; } $request = $event->getRequest(); if (!in_array($request->getRequestFormat(), array('soap', 'xml'))) { return; } elseif ('xml' === $request->getRequestFormat() && '_webservice_call' !== $request->attributes->get('_route')) { return; } $attributes = $request->attributes; if (!($webservice = $attributes->get('webservice'))) { return; } if (!$this->container->has(sprintf('besimple.soap.context.%s', $webservice))) { return; } // hack to retrieve the current WebService name in the controller $request->query->set('_besimple_soap_webservice', $webservice); $exception = $event->getException(); if ($exception instanceof \SoapFault) { $request->query->set('_besimple_soap_fault', $exception); } parent::onKernelException($event); }
/** * @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); } }
/** * 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); }
/** * @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); } }
/** * @before * */ protected function setUpSymfonyKernel() { $this->kernel = $this->createKernel(); $this->kernel->boot(); $this->container = $this->kernel->getContainer(); $this->logger = $this->container->get('logger'); }
/** * 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; }
/** * {@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); }
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."); }
public function setContainer(ContainerInterface $container = null) { if (null !== $container) { $this->container = $container; $this->defaultLocale = $container->getParameter('sylius.locale'); } }
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'); }
/** * {@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')); }
/** * @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; }
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; } } } } }
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 function setContainer(ContainerInterface $container = null) { $this->container = $container; $this->prefix = $container->getParameter('mautic.db_table_prefix'); $this->platform = $this->connection->getDatabasePlatform()->getName(); $this->factory = $container->get('mautic.factory'); }
/** * 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; }
function it_deletes_participant(ContainerInterface $container, ParticipantRepository $participantRepository, ParticipantInterface $participant) { $container->get('kreta_project.repository.participant')->shouldBeCalled()->willReturn($participantRepository); $participantRepository->findOneBy(['project' => 'project-id', 'user' => 'user-id'], false)->shouldBeCalled()->willReturn($participant); $participantRepository->remove($participant)->shouldBeCalled(); $this->deleteParticipantsAction('project-id', 'user-id'); }
/** * @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 __construct($translationMap, $requestStack, ContainerInterface $container) { $this->requestStack = $requestStack; $this->session = $container->get('session'); $this->container = $container; $this->translationMap = $translationMap["front_map"]; }