Symfony\Component\DependencyInjection\Definition::setDeprecated PHP Méthode

setDeprecated() public méthode

Whether this definition is deprecated, that means it should not be called anymore.
public setDeprecated ( boolean $status = true, string $template = null ) : Definition
$status boolean
$template string Template message to use if the definition is deprecated
Résultat Definition the current instance
    public function setDeprecated($status = true, $template = null)
    {
        if (null !== $template) {
            if (preg_match('#[\r\n]|\*/#', $template)) {
                throw new InvalidArgumentException('Invalid characters found in deprecation template.');
            }

            if (false === strpos($template, '%service_id%')) {
                throw new InvalidArgumentException('The deprecation template must contain the "%service_id%" placeholder.');
            }

            $this->deprecationTemplate = $template;
        }

        $this->deprecated = (bool) $status;

        return $this;
    }

Usage Example

 /**
  * @group legacy
  * @expectedDeprecation The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.
  */
 public function testCreateDeprecatedService()
 {
     $definition = new Definition('stdClass');
     $definition->setDeprecated(true);
     $builder = new ContainerBuilder();
     $builder->setDefinition('deprecated_foo', $definition);
     $builder->get('deprecated_foo');
 }
All Usage Examples Of Symfony\Component\DependencyInjection\Definition::setDeprecated