vendor/symfony/src/Symfony/Component/DependencyInjection/Exception/ScopeWideningInjectionException.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the Symfony framework.
       
     5  *
       
     6  * (c) Fabien Potencier <fabien@symfony.com>
       
     7  *
       
     8  * This source file is subject to the MIT license that is bundled
       
     9  * with this source code in the file LICENSE.
       
    10  */
       
    11 
       
    12 namespace Symfony\Component\DependencyInjection\Exception;
       
    13 
       
    14 /**
       
    15  * Thrown when a scope widening injection is detected.
       
    16  *
       
    17  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
       
    18  */
       
    19 class ScopeWideningInjectionException extends RuntimeException
       
    20 {
       
    21     private $sourceServiceId;
       
    22     private $sourceScope;
       
    23     private $destServiceId;
       
    24     private $destScope;
       
    25 
       
    26     public function __construct($sourceServiceId, $sourceScope, $destServiceId, $destScope)
       
    27     {
       
    28         parent::__construct(sprintf(
       
    29             'Scope Widening Injection detected: The definition "%s" references the service "%s" which belongs to a narrower scope. '
       
    30            .'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. '
       
    31            .'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.',
       
    32            $sourceServiceId,
       
    33            $destServiceId,
       
    34            $sourceServiceId,
       
    35            $destScope,
       
    36            $destServiceId
       
    37         ));
       
    38 
       
    39         $this->sourceServiceId = $sourceServiceId;
       
    40         $this->sourceScope = $sourceScope;
       
    41         $this->destServiceId = $destServiceId;
       
    42         $this->destScope = $destScope;
       
    43     }
       
    44 
       
    45     public function getSourceServiceId()
       
    46     {
       
    47         return $this->sourceServiceId;
       
    48     }
       
    49 
       
    50     public function getSourceScope()
       
    51     {
       
    52         return $this->sourceScope;
       
    53     }
       
    54 
       
    55     public function getDestServiceId()
       
    56     {
       
    57         return $this->destServiceId;
       
    58     }
       
    59 
       
    60     public function getDestScope()
       
    61     {
       
    62         return $this->destScope;
       
    63     }
       
    64 }