2010-01-04 14:26:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-01-04 14:26:20 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-01-04 14:26:20 +00:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-01-04 14:26:20 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\DependencyInjection;
|
|
|
|
|
2010-01-04 14:26:20 +00:00
|
|
|
/**
|
|
|
|
* Reference represents a service reference.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2011-07-20 09:50:27 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-01-04 14:26:20 +00:00
|
|
|
*/
|
|
|
|
class Reference
|
|
|
|
{
|
2011-03-11 13:50:46 +00:00
|
|
|
private $id;
|
|
|
|
private $invalidBehavior;
|
|
|
|
private $strict;
|
2010-01-04 14:26:20 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
2011-01-17 22:28:59 +00:00
|
|
|
* @param string $id The service identifier
|
|
|
|
* @param int $invalidBehavior The behavior when the service does not exist
|
2014-04-12 18:54:57 +01:00
|
|
|
* @param bool $strict Sets how this reference is validated
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @see Container
|
|
|
|
*/
|
2011-01-17 22:28:59 +00:00
|
|
|
public function __construct($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $strict = true)
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
2011-12-08 15:30:50 +00:00
|
|
|
$this->id = strtolower($id);
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->invalidBehavior = $invalidBehavior;
|
2011-01-17 22:28:59 +00:00
|
|
|
$this->strict = $strict;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-01-04 14:26:20 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* __toString.
|
|
|
|
*
|
|
|
|
* @return string The service identifier
|
|
|
|
*/
|
|
|
|
public function __toString()
|
|
|
|
{
|
2013-06-05 00:48:30 +01:00
|
|
|
return $this->id;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-01-04 14:26:20 +00:00
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Returns the behavior to be used when the service does not exist.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function getInvalidBehavior()
|
|
|
|
{
|
|
|
|
return $this->invalidBehavior;
|
|
|
|
}
|
2011-01-17 22:28:59 +00:00
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Returns true when this Reference is strict
|
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return bool
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2011-01-17 22:28:59 +00:00
|
|
|
public function isStrict()
|
|
|
|
{
|
|
|
|
return $this->strict;
|
|
|
|
}
|
2010-01-04 14:26:20 +00:00
|
|
|
}
|