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


PHP DependencyInjection\Reference類代碼示例

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


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

示例1: addBroadcaster

 private function addBroadcaster($broadcaster, array $attributes, Reference $reference, Definition $definition, ContainerBuilder $container)
 {
     $definition->addMethodCall('add', [$attributes['alias'], $broadcaster]);
     // Register an alias for each broadcaster
     if (!$container->hasDefinition('ekko.broadcaster.' . $attributes['alias'])) {
         $container->setAlias('ekko.broadcaster.' . $attributes['alias'], $reference->__toString());
     }
 }
開發者ID:edwin-luijten,項目名稱:ekko-bundle,代碼行數:8,代碼來源:BroadcasterPass.php

示例2: validateScope

 protected function validateScope(Reference $reference, Definition $definition = null)
 {
     if (ContainerInterface::SCOPE_PROTOTYPE === $this->currentScope) {
         return;
     }
     if (!$reference->isStrict()) {
         return;
     }
     if (null === $definition) {
         return;
     }
     if ($this->currentScope === ($scope = $definition->getScope())) {
         return;
     }
     $id = (string) $reference;
     if (in_array($scope, $this->currentScopeChildren, true)) {
         throw new \RuntimeException(sprintf('Scope Widening Injection detected: The definition "%s" references the service "%s" which belongs to a narrower scope. ' . 'Generally, it is safer to either move "%s" to scope "%s" or alternatively rely on the provider pattern by injecting the container itself, and requesting the service "%s" each time it is needed. ' . 'In rare, special cases however that might not be necessary, then you can set the reference to strict=false to get rid of this error.', $this->currentId, $id, $this->currentId, $scope, $id));
     }
     if (!in_array($scope, $this->currentScopeAncestors, true)) {
         throw new \RuntimeException(sprintf('Cross-Scope Injection detected: The definition "%s" references the service "%s" which belongs to another scope hierarchy. ' . 'This service might not be available consistently. Generally, it is safer to either move the definition "%s" to scope "%s", or ' . 'declare "%s" as a child scope of "%s". If you can be sure that the other scope is always active, you can set the reference to strict=false to get rid of this error.', $this->currentId, $id, $this->currentId, $scope, $this->currentScope, $scope));
     }
 }
開發者ID:faridos,項目名稱:ServerGroveLiveChat,代碼行數:22,代碼來源:CheckReferenceValidityPass.php

示例3: getServiceCall

 protected function getServiceCall($id, Reference $reference = null)
 {
     if ('service_container' === $id) {
         return '$this';
     }
     if (null !== $reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) {
         return sprintf('$this->get(\'%s\', ContainerInterface::NULL_ON_INVALID_REFERENCE)', $id);
     } else {
         if ($this->container->hasAlias($id)) {
             $id = $this->container->getAlias($id);
         }
         return sprintf('$this->get(\'%s\')', $id);
     }
 }
開發者ID:jackbravo,項目名稱:symfony-sandbox,代碼行數:14,代碼來源:PhpDumper.php

示例4: getServiceCall

 /**
  * Gets the service call.
  *
  * @param string    $id
  * @param Reference $reference
  *
  * @return string
  */
 private function getServiceCall($id, Reference $reference = null)
 {
     if (null !== $reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) {
         return sprintf('@?%s', $id);
     }
     return sprintf('@%s', $id);
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:15,代碼來源:YamlDumper.php

示例5: getReferenceCall

 /**
  * Gets a service reference for a reference in a suitable PHP array format.
  *
  * The main difference is that this function treats references to private
  * services differently and returns a private service reference instead of
  * a normal reference.
  *
  * @param string $id
  *   The ID of the service to get a reference for.
  * @param \Symfony\Component\DependencyInjection\Reference|NULL $reference
  *   (optional) The reference object to process; needed to get the invalid
  *   behavior value.
  *
  * @return string|\stdClass
  *   A suitable representation of the service reference.
  */
 protected function getReferenceCall($id, Reference $reference = NULL)
 {
     $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
     if ($reference !== NULL) {
         $invalid_behavior = $reference->getInvalidBehavior();
     }
     // Private shared service.
     $definition = $this->container->getDefinition($id);
     if (!$definition->isPublic()) {
         // The ContainerBuilder does not share a private service, but this means a
         // new service is instantiated every time. Use a private shared service to
         // circumvent the problem.
         return $this->getPrivateServiceCall($id, $definition, TRUE);
     }
     return $this->getServiceCall($id, $invalid_behavior);
 }
開發者ID:sojo,項目名稱:d8_friendsofsilence,代碼行數:32,代碼來源:OptimizedPhpArrayDumper.php

示例6: getServiceCall

 /**
  * Gets a service call.
  *
  * @param string    $id
  * @param Reference $reference
  *
  * @return string
  */
 private function getServiceCall($id, Reference $reference = null)
 {
     if ('service_container' === $id) {
         return '$this';
     }
     if ($this->container->hasDefinition($id) && !$this->container->getDefinition($id)->isPublic()) {
         // The following is PHP 5.5 syntax for what could be written as "(\$this->services['$id'] ?? \$this->{$this->generateMethodName($id)}())" on PHP>=7.0
         return "\${(\$_ = isset(\$this->services['{$id}']) ? \$this->services['{$id}'] : \$this->{$this->generateMethodName($id)}()) && false ?: '_'}";
     }
     if (null !== $reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) {
         return sprintf('$this->get(\'%s\', ContainerInterface::NULL_ON_INVALID_REFERENCE)', $id);
     } else {
         if ($this->container->hasAlias($id)) {
             $id = (string) $this->container->getAlias($id);
         }
         return sprintf('$this->get(\'%s\')', $id);
     }
 }
開發者ID:OndraM,項目名稱:symfony,代碼行數:26,代碼來源:PhpDumper.php

示例7: getXmlInvalidBehavior

 protected function getXmlInvalidBehavior(Reference $reference)
 {
     switch ($reference->getInvalidBehavior()) {
         case ContainerInterface::NULL_ON_INVALID_REFERENCE:
             return 'on-invalid="null" ';
         case ContainerInterface::IGNORE_ON_INVALID_REFERENCE:
             return 'on-invalid="ignore" ';
         default:
             return '';
     }
 }
開發者ID:spf13,項目名稱:symfony,代碼行數:11,代碼來源:XmlDumper.php

示例8: assertReferenceEquals

 /**
  * @param string    $expectedId
  * @param Reference $actualReference
  */
 private function assertReferenceEquals($expectedId, Reference $actualReference)
 {
     $this->assertEquals($expectedId, $actualReference->__toString());
 }
開發者ID:michalmrzyk,項目名稱:omnipay-bundle,代碼行數:8,代碼來源:GatewayTagCompilerPassTest.php


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