aad78e806b6b61448c85b1036f3c3292df95ed9a
[yaffs-website] / vendor / symfony / dependency-injection / TypedReference.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection;
13
14 /**
15  * Represents a PHP type-hinted service reference.
16  *
17  * @author Nicolas Grekas <p@tchwork.com>
18  */
19 class TypedReference extends Reference
20 {
21     private $type;
22     private $requiringClass;
23
24     /**
25      * @param string $id              The service identifier
26      * @param string $type            The PHP type of the identified service
27      * @param string $requiringClass  The class of the service that requires the referenced type
28      * @param int    $invalidBehavior The behavior when the service does not exist
29      */
30     public function __construct($id, $type, $requiringClass = '', $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
31     {
32         parent::__construct($id, $invalidBehavior);
33         $this->type = $type;
34         $this->requiringClass = $requiringClass;
35     }
36
37     public function getType()
38     {
39         return $this->type;
40     }
41
42     public function getRequiringClass()
43     {
44         return $this->requiringClass;
45     }
46
47     public function canBeAutoregistered()
48     {
49         return $this->requiringClass && (false !== $i = strpos($this->type, '\\')) && 0 === strncasecmp($this->type, $this->requiringClass, 1 + $i);
50     }
51 }