has() public method

Returns true if the given service is defined.
public has ( string $id ) : boolean
$id string The service identifier
return boolean true if the service is defined, false otherwise
 /**
  * @covers ::knowsDependency
  * @covers ::__construct
  */
 public function testKnowsDependency()
 {
     $this->container->has('known_dependency')->willReturn(true);
     $this->container->has('unknown_dependency')->willReturn(false);
     $this->assertTrue($this->sut->knowsDependency('known_dependency'));
     $this->assertFalse($this->sut->knowsDependency('unknown_dependency'));
 }
 /**
  * Convenience shortcut to add a session flash message.
  * @param $type
  * @param $message
  */
 public function addFlash($type, $message)
 {
     if (!$this->container->has('session')) {
         throw new \LogicException('You can not use the addFlash method if sessions are disabled.');
     }
     $this->container->get('session')->getFlashBag()->add($type, $message);
 }
 public function onFlush(OnFlushEventArgs $args)
 {
     if (!$this->container->has('orocrm_contact.contact.manager')) {
         return;
     }
     $em = $args->getEntityManager();
     $uow = $em->getUnitOfWork();
     $insertedEntities = $uow->getScheduledEntityInsertions();
     $updatedEntities = $uow->getScheduledEntityUpdates();
     $entities = array_merge($insertedEntities, $updatedEntities);
     foreach ($entities as $entity) {
         if (!$entity instanceof DiamanteUser) {
             continue;
         }
         $contactManager = $this->container->get('orocrm_contact.contact.manager');
         $contact = $contactManager->getRepository()->findOneBy(['email' => $entity->getEmail()]);
         if (empty($contact)) {
             continue;
         }
         if ($entity->getFirstName() == null) {
             $entity->setFirstName($contact->getFirstName());
         }
         if ($entity->getLastName() == null) {
             $entity->setLastName($contact->getLastName());
         }
         try {
             $em->persist($entity);
             $md = $em->getClassMetadata(get_class($entity));
             $uow->recomputeSingleEntityChangeSet($md, $entity);
         } catch (\Exception $e) {
             $this->container->get('monolog.logger.diamante')->addWarning(sprintf('Error saving Contact Information for Diamante User with email: %s', $entity->getEmail()));
         }
     }
 }
 /**
  * (non-PHPdoc)
  * @see \Asf\ApplicationBundle\Application\Form\FormHandlerModel::processForm()
  * @throw \Exception
  */
 public function processForm($model)
 {
     try {
         if (is_null($model->getId())) {
             $isIdentityExist = $this->container->get('asf_contact.identity.manager')->getRepository()->findOneBy(array('name' => $model->getName()));
             if (!is_null($isIdentityExist)) {
                 $this->flashMessage->danger($this->translator->trans('A contact with that name already exists', array(), 'AsfContact'));
                 return false;
             }
         }
         if (!is_null($model->getAccount())) {
             $model->getAccount()->setEmail($model->getMainEmailAddress());
         }
         $this->updateIdentityOrganizationsRelations($model);
         if ($this->container->has('asf_contact.address.manager')) {
             $this->updateIdentityAddressRelations($model);
         }
         if ($this->container->has('asf_contact.contact_device.manager')) {
             $this->updateIdentityContactDeviceRelations($model);
         }
         return true;
     } catch (\Exception $e) {
         throw new \Exception(sprintf('An error occured : %s', $e->getMessage()));
     }
     return false;
 }
Example #5
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $username = '******';
     $email = '*****@*****.**';
     $password = '******';
     if ($this->container->has('drafterbit_installer')) {
         $data = $this->container->get('drafterbit_installer')->getData();
         if ($data) {
             $username = $data['username'];
             $email = $data['email'];
             $password = $data['password'];
         }
     }
     $userAdmin = new User();
     $userAdmin->setUsername($username);
     $userAdmin->setRealname($username);
     $userAdmin->setEmail($email);
     $userAdmin->setPlainPassword($password);
     $userAdmin->setEnabled(1);
     $userAdmin->addRole('ROLE_ADMIN');
     $userAdmin->getGroups()->add($this->getReference('admin-group'));
     $manager->persist($userAdmin);
     $manager->flush();
     $this->addReference('admin-user', $userAdmin);
 }
 /**
  * @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);
 }
 /**
  * @param $bridgeName
  * @return TransportBridgeInterface|null
  */
 public static function createBridge($bridgeName)
 {
     if (self::$container->has($bridgeName)) {
         return self::$container->get($bridgeName);
     }
     return null;
 }
 /**
  * @param $instance
  * @return array
  */
 public function getConfiguration($instance)
 {
     $request = $this->requestStack->getCurrentRequest();
     $efParameters = $this->parameters;
     $parameters = $efParameters['instances'][$instance];
     $options = array();
     $options['corsSupport'] = $parameters['cors_support'];
     $options['debug'] = $parameters['connector']['debug'];
     $options['bind'] = $parameters['connector']['binds'];
     $options['plugins'] = $parameters['connector']['plugins'];
     $options['roots'] = array();
     foreach ($parameters['connector']['roots'] as $parameter) {
         $path = $parameter['path'];
         $homeFolder = $this->container->get('security.token_storage')->getToken()->getUser()->getUsername();
         //            var_dump($path.$homeFolder);
         $driver = $this->container->has($parameter['driver']) ? $this->container->get($parameter['driver']) : null;
         $driverOptions = array('driver' => $parameter['driver'], 'service' => $driver, 'glideURL' => $parameter['glide_url'], 'glideKey' => $parameter['glide_key'], 'plugin' => $parameter['plugins'], 'path' => $path . '/' . $homeFolder, 'startPath' => $parameter['start_path'], 'URL' => $this->getURL($parameter, $request, $homeFolder, $path), 'alias' => $parameter['alias'], 'mimeDetect' => $parameter['mime_detect'], 'mimefile' => $parameter['mimefile'], 'imgLib' => $parameter['img_lib'], 'tmbPath' => $parameter['tmb_path'], 'tmbPathMode' => $parameter['tmb_path_mode'], 'tmbUrl' => $parameter['tmb_url'], 'tmbSize' => $parameter['tmb_size'], 'tmbCrop' => $parameter['tmb_crop'], 'tmbBgColor' => $parameter['tmb_bg_color'], 'copyOverwrite' => $parameter['copy_overwrite'], 'copyJoin' => $parameter['copy_join'], 'copyFrom' => $parameter['copy_from'], 'copyTo' => $parameter['copy_to'], 'uploadOverwrite' => $parameter['upload_overwrite'], 'uploadAllow' => $parameter['upload_allow'], 'uploadDeny' => $parameter['upload_deny'], 'uploadMaxSize' => $parameter['upload_max_size'], 'defaults' => $parameter['defaults'], 'attributes' => $parameter['attributes'], 'acceptedName' => $parameter['accepted_name'], 'disabled' => $parameter['disabled_commands'], 'treeDeep' => $parameter['tree_deep'], 'checkSubfolders' => $parameter['check_subfolders'], 'separator' => $parameter['separator'], 'timeFormat' => $parameter['time_format'], 'archiveMimes' => $parameter['archive_mimes'], 'archivers' => $parameter['archivers']);
         if (!$parameter['show_hidden']) {
             $driverOptions['accessControl'] = array($this, 'access');
         }
         if ($parameter['driver'] == 'Flysystem') {
             $driverOptions['filesystem'] = $filesystem;
         }
         $options['roots'][] = array_merge($driverOptions, $this->configureDriver($parameter));
     }
     return $options;
 }
 /**
  * @test
  * @dataProvider serviceProvider
  *
  * @param string $webServiceName
  * @param string $containerServiceName
  * @param string $clientClassName
  */
 public function all_web_services_in_sdk_manifest_should_be_accessible_as_container_services($webServiceName, $containerServiceName, $clientClassName)
 {
     $this->assertTrue($this->container->has($containerServiceName));
     $service = $this->container->get($containerServiceName);
     $this->assertInstanceOf($clientClassName, $service);
     $this->assertInstanceOf(AwsClient::class, $service);
 }
Example #10
0
 /**
  * Lógica de Dominio
  * @param  String $entityName es el nombre de la entidad que se desea
  * @return Entity|null si existe una factory para la entidad pedida
  * se devuelve una instancia nueva de la Entidad creada por la Factoría,
  * si no, devuelve null
  */
 public function getEntity($entityName)
 {
     // Por pragmatismo, se ha decidido que las factorías
     // serán servicios que se llamaran:
     // "bazaary.model.{entidad}.factory"
     $factoryServiceName = 'bazaary.model.' . strtolower($entityName) . '.factory';
     $factory = null;
     // Por lo tanto, si el service container tiene registrado un servicio llamado así,
     // entonces es que ese servicio devolverá la Factory que necesitamos usar
     if ($this->service_container->has($factoryServiceName)) {
         $factory = $this->service_container->get($factoryServiceName);
     } else {
         $repository = $this->getRepository($entityName);
         if ($repository) {
             $factory = $repository->getFactory();
         }
     }
     // En este punto sabremos si hemos conseguido la factory
     // con la que crear la entity que se nos pide
     if ($factory) {
         return $factory->newInstance();
     } else {
         return null;
     }
 }
Example #11
0
 private function getTokenStorage()
 {
     if ($this->container->has('security.token_storage')) {
         return $this->container->get('security.token_storage');
     }
     return $this->container->get('security.context');
 }
 /**
  * Returns the ReflectionMethod for the given controller string.
  *
  * @param string $controller
  * @return \ReflectionMethod|null
  */
 public function getReflectionMethod($controller)
 {
     if (false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
         $controller = $this->controllerNameParser->parse($controller);
     }
     if (preg_match('#(.+)::([\\w]+)#', $controller, $matches)) {
         $class = $matches[1];
         $method = $matches[2];
     } elseif (preg_match('#(.+):([\\w]+)#', $controller, $matches)) {
         $controller = $matches[1];
         $method = $matches[2];
         if ($this->container->has($controller)) {
             $this->container->enterScope('request');
             $this->container->set('request', new Request(), 'request');
             $class = ClassUtils::getRealClass(get_class($this->container->get($controller)));
             $this->container->leaveScope('request');
         }
     }
     if (isset($class) && isset($method)) {
         try {
             return new \ReflectionMethod($class, $method);
         } catch (\ReflectionException $e) {
         }
     }
     return null;
 }
 /**
  * Returns a Slot with the given $slotIdentifier
  *
  * @param string $slotIdentifier
  *
  * @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException When no slot is found
  *
  * @return \eZ\Publish\Core\SignalSlot\Slot
  */
 public function getSlot($slotIdentifier)
 {
     if (!$this->container->has($slotIdentifier)) {
         throw new NotFoundException('slot', $slotIdentifier);
     }
     return $this->container->get($slotIdentifier);
 }
Example #14
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $className = Utils::getSimpleClassName(get_class($this));
     if (substr($className, -4) !== "Task") {
         throw new SkrzException(sprintf("Task class name has to end with 'Task', class: '%s'.", $className));
     }
     $taskLogDirectory = $this->container->getParameter("kernel.logs_dir");
     $this->log->pushHandler(new RotatingFileHandler($taskLogDirectory . "/" . $className . ".log", $this->rotatingLogMaxFiles));
     try {
         $this->log->info("Task {$className} started.");
         $startTime = microtime(true);
         $this->work();
         $endTime = microtime(true);
         $this->log->info(sprintf("Task {$className} terminated with success in %.3fs.", $endTime - $startTime));
     } catch (\Exception $e) {
         if ($this->container->has("service.alert")) {
             // FIXME: do not rely on hostname
             /** @var AlertServiceInterface $alertService */
             $alertService = $this->container->get("service.alert");
             $alertService->sendEmailToAdmin($this->devEmail, "[" . gethostname() . "]: Task " . get_class($this) . " failed with exception: " . $e->getMessage(), $e->getMessage() . "\n\n" . $e->getTraceAsString());
         }
         $this->log->emergency("Task terminated with exception. " . get_class($e) . ": " . $e->getMessage() . "\n\n" . $e->getTraceAsString());
     }
     $this->log->popHandler();
 }
Example #15
0
 /**
  * Load a controller callable
  *
  * @param \Symfony\Component\HttpFoundation\Request $request Symfony Request object
  * @return bool|Callable Callable or false
  * @throws \phpbb\controller\exception
  */
 public function getController(Request $request)
 {
     $controller = $request->attributes->get('_controller');
     if (!$controller) {
         throw new \phpbb\controller\exception('CONTROLLER_NOT_SPECIFIED');
     }
     // Require a method name along with the service name
     if (stripos($controller, ':') === false) {
         throw new \phpbb\controller\exception('CONTROLLER_METHOD_NOT_SPECIFIED');
     }
     list($service, $method) = explode(':', $controller);
     if (!$this->container->has($service)) {
         throw new \phpbb\controller\exception('CONTROLLER_SERVICE_UNDEFINED', array($service));
     }
     $controller_object = $this->container->get($service);
     /*
      * If this is an extension controller, we'll try to automatically set
      * the style paths for the extension (the ext author can change them
      * if necessary).
      */
     $controller_dir = explode('\\', get_class($controller_object));
     // 0 vendor, 1 extension name, ...
     if (!is_null($this->template) && isset($controller_dir[1])) {
         $controller_style_dir = 'ext/' . $controller_dir[0] . '/' . $controller_dir[1] . '/styles';
         if (is_dir($this->phpbb_root_path . $controller_style_dir)) {
             $this->template->set_style(array($controller_style_dir, 'styles'));
         }
     }
     return array($controller_object, $method);
 }
 /**
  * {@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);
 }
 /**
  * {@inheritDoc}
  */
 public function convert(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $method, $value, array $attributes = [])
 {
     if (!$this->container->isScopeActive('request') || !$this->container->has('request')) {
         throw new ConverterException('Could not convert Request parameter in not active "request" scope.');
     }
     return $this->container->get('request');
 }
 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);
 }
Example #19
0
 /**
  * Shortcut to return the Doctrine Registry service.
  *
  * @return \Doctrine\Bundle\DoctrineBundle\Registry
  *
  * @throws \LogicException If DoctrineBundle is not available
  */
 protected function getDoctrine()
 {
     if (!$this->container->has('doctrine')) {
         throw new \LogicException('The DoctrineBundle is not registered in your application.');
     }
     return $this->container->get('doctrine');
 }
Example #20
0
 /**
  * Returns the current session.
  * Returns null if the there is no session.
  */
 protected function getSession()
 {
     if (!$this->container->has('session')) {
         return null;
     }
     return $this->container->get('session');
 }
Example #21
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 function resolve($className)
 {
     if (isset($this->mapping[$className]) && $this->container->has($this->mapping[$className])) {
         return $this->container->get($this->mapping[$className]);
     }
     return parent::resolve($className);
 }
Example #23
0
 /**
  * @param string $formatterId
  *
  * @return TypeFormatterInterface
  */
 protected function getFormatterService($formatterId)
 {
     if (!$this->container->has($formatterId)) {
         $message = sprintf('The formatter "%s" is not registered with the service container.', $formatterId);
         throw new InvalidArgumentException($message);
     }
     return $this->container->get($formatterId);
 }
Example #24
0
 /**
  * @param string $authenticationMethod
  *
  * @return \ACP3\Core\Authentication\AuthenticationInterface
  * @throws \ACP3\Core\Authentication\Exception\InvalidAuthenticationMethodException
  */
 public function get($authenticationMethod)
 {
     $serviceId = 'core.authentication.' . $authenticationMethod;
     if ($this->container->has($serviceId)) {
         return $this->container->get($serviceId);
     }
     throw new InvalidAuthenticationMethodException();
 }
 /**
  * {@inheritDoc}
  */
 public function call(TransitionEvent $event)
 {
     // Load the services only now (when the callback is actually called)
     if (is_array($this->callable) && is_string($this->callable[0]) && 0 === strpos($this->callable[0], '@') && $this->container->has($serviceId = substr($this->callable[0], 1))) {
         $this->callable[0] = $this->container->get($serviceId);
     }
     return parent::call($event);
 }
 /**
  * Returns the service instance given in param.
  *
  * @param string $service The service name
  * 
  * @return string
  * @access public
  * @author Etienne de Longeaux <*****@*****.**>
  */
 public function getServiceFunction($service)
 {
     if ($this->container->has($service)) {
         return $this->container->get($service);
     } else {
         throw new \InvalidArgumentException("The service given in param isn't register !");
     }
 }
 /**
  * {@inheritdoc}
  */
 public function createPerformantJob(JobInterface $job)
 {
     $target = $job->getJobClass();
     if ($this->container->has($target)) {
         return $this->container->get($target);
     }
     return parent::createPerformantJob($job);
 }
 /**
  * Gets a service this link refers to
  *
  * @return object
  */
 public function getService()
 {
     // try to get a service and save it to internal cache
     if ($this->service === false) {
         $this->service = !$this->isOptional || $this->container->has($this->serviceId) ? $this->container->get($this->serviceId) : null;
     }
     return $this->service;
 }
 /**
  * Attempts to load Filter from Container or hands off to parent loader.
  *
  * @param Rule $rule
  * @return BaseFilter
  */
 public function getFilterForRule(Rule $rule)
 {
     $filterIdentifier = $rule->getFilter();
     if ($this->container === null || !$this->container->has($filterIdentifier)) {
         return parent::getFilterForRule($rule);
     }
     return $this->container->get($filterIdentifier);
 }
 /**
  * Returns the index manager service for a given index manager name
  *
  * @param string $name
  * @return IndexManager
  */
 public function get($name)
 {
     $serviceName = sprintf('sfes.index.%s', $name);
     if (!$this->container->has($serviceName)) {
         throw new \RuntimeException(sprintf('No manager is defined for "%s" index', $name));
     }
     return $this->container->get($serviceName);
 }