4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection;
15 * Represents a PHP type-hinted service reference.
17 * @author Nicolas Grekas <p@tchwork.com>
19 class TypedReference extends Reference
22 private $requiringClass;
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
30 public function __construct($id, $type, $requiringClass = '', $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
32 parent::__construct($id, $invalidBehavior);
34 $this->requiringClass = $requiringClass;
37 public function getType()
42 public function getRequiringClass()
44 return $this->requiringClass;
47 public function canBeAutoregistered()
49 return $this->requiringClass && (false !== $i = strpos($this->type, '\\')) && 0 === strncasecmp($this->type, $this->requiringClass, 1 + $i);