當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ContainerInterface::has方法代碼示例

本文整理匯總了PHP中Symfony\Component\DependencyInjection\ContainerInterface::has方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContainerInterface::has方法的具體用法?PHP ContainerInterface::has怎麽用?PHP ContainerInterface::has使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\DependencyInjection\ContainerInterface的用法示例。


在下文中一共展示了ContainerInterface::has方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testKnowsDependency

 /**
  * @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'));
 }
開發者ID:bartfeenstra,項目名稱:dependency-retriever-symfony-bridge,代碼行數:11,代碼來源:ContainerServiceRetrieverTest.php

示例2: addFlash

 /**
  * 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);
 }
開發者ID:Kaik,項目名稱:KaikMediaGallery,代碼行數:12,代碼來源:GalleryModuleInstaller.php

示例3: onFlush

 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()));
         }
     }
 }
開發者ID:gitter-badger,項目名稱:diamantedesk-application,代碼行數:34,代碼來源:DiamanteUserListener.php

示例4: processForm

 /**
  * (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;
 }
開發者ID:artscorestudio,項目名稱:contact-bundle,代碼行數:31,代碼來源:IdentityFormHandler.php

示例5: load

 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $username = 'admin';
     $email = 'admin@drafterbit.org';
     $password = 'admin';
     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);
 }
開發者ID:hikmahtiar6,項目名稱:drafterbit,代碼行數:28,代碼來源:LoadUserData.php

示例6: getMatcher

 /**
  * @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);
 }
開發者ID:CG77,項目名稱:ezpublish-kernel,代碼行數:12,代碼來源:ContentMatcherFactory.php

示例7: createBridge

 /**
  * @param $bridgeName
  * @return TransportBridgeInterface|null
  */
 public static function createBridge($bridgeName)
 {
     if (self::$container->has($bridgeName)) {
         return self::$container->get($bridgeName);
     }
     return null;
 }
開發者ID:velikanov,項目名稱:UnbiasedJsonTransportExampleApplication,代碼行數:11,代碼來源:TransportBridgeFactory.php

示例8: getConfiguration

 /**
  * @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;
 }
開發者ID:helios-ag,項目名稱:elfinder-userbundle-example,代碼行數:31,代碼來源:ConfigurationReader.php

示例9: all_web_services_in_sdk_manifest_should_be_accessible_as_container_services

 /**
  * @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);
 }
開發者ID:joksnet,項目名稱:aws-sdk-php-symfony,代碼行數:15,代碼來源:AwsExtensionTest.php

示例10: getEntity

 /**
  * 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;
     }
 }
開發者ID:IFCD0210,項目名稱:bazaary,代碼行數:32,代碼來源:BazaaryModel.php

示例11: getTokenStorage

 private function getTokenStorage()
 {
     if ($this->container->has('security.token_storage')) {
         return $this->container->get('security.token_storage');
     }
     return $this->container->get('security.context');
 }
開發者ID:bruery,項目名稱:platform,代碼行數:7,代碼來源:AuthorizeController.php

示例12: getReflectionMethod

 /**
  * 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;
 }
開發者ID:eliberty,項目名稱:api-bundle,代碼行數:32,代碼來源:DocumentationHelper.php

示例13: getSlot

 /**
  * 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);
 }
開發者ID:brookinsconsulting,項目名稱:ezecosystem,代碼行數:16,代碼來源:ContainerSlotFactory.php

示例14: execute

 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();
 }
開發者ID:skrz,項目名稱:stack,代碼行數:27,代碼來源:AbstractTask.php

示例15: getController

 /**
  * 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);
 }
開發者ID:MrAdder,項目名稱:phpbb,代碼行數:37,代碼來源:resolver.php


注:本文中的Symfony\Component\DependencyInjection\ContainerInterface::has方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。