本文整理匯總了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);
}
示例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()));
}
}
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
}
示例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');
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}