deprecate example

if (!$definition->hasTag('container.excluded') || !$this->has($id)) {
                $this->setDefinition($id$definition);
            }
        }
        $this->addAliases($container->getAliases());
        $parameterBag = $this->getParameterBag();
        $otherBag = $container->getParameterBag();
        $parameterBag->add($otherBag->all());

        if ($parameterBag instanceof ParameterBag && $otherBag instanceof ParameterBag) {
            foreach ($otherBag->allDeprecated() as $name => $deprecated) {
                $parameterBag->deprecate($name, ...$deprecated);
            }
        }

        if ($this->trackResources) {
            foreach ($container->getResources() as $resource) {
                $this->addResource($resource);
            }
        }

        foreach ($this->extensions as $name => $extension) {
            if (!isset($this->extensionConfigs[$name])) {
                
public function testRemove()
    {
        $this->expectException(\LogicException::class);
        $bag = new FrozenParameterBag(['foo' => 'bar']);
        $bag->remove('foo');
    }

    public function testDeprecate()
    {
        $this->expectException(\LogicException::class);
        $bag = new FrozenParameterBag(['foo' => 'bar']);
        $bag->deprecate('foo', 'symfony/test', '6.3');
    }

    /** * The test should be kept in the group as it always expects a deprecation. * * @group legacy */
    public function testGetDeprecated()
    {
        $bag = new FrozenParameterBag(
            ['foo' => 'bar'],
            [
->configurator([service('twig.configurator.environment'), 'configure'])
            ->tag('container.preload', ['class' => FilesystemCache::class])
            ->tag('container.preload', ['class' => CoreExtension::class])
            ->tag('container.preload', ['class' => EscaperExtension::class])
            ->tag('container.preload', ['class' => OptimizerExtension::class])
            ->tag('container.preload', ['class' => StagingExtension::class])
            ->tag('container.preload', ['class' => ExtensionSet::class])
            ->tag('container.preload', ['class' => Template::class])
            ->tag('container.preload', ['class' => TemplateWrapper::class])

        ->alias('Twig_Environment', 'twig')
            ->deprecate('symfony/twig-bundle', '6.3', 'The "%alias_id%" service alias is deprecated, use "'.Environment::class.'" or "twig" instead.')
        ->alias(Environment::class, 'twig')

        ->set('twig.app_variable', AppVariable::class)
            ->call('setEnvironment', [param('kernel.environment')])
            ->call('setDebug', [param('kernel.debug')])
            ->call('setTokenStorage', [service('security.token_storage')->ignoreOnInvalid()])
            ->call('setRequestStack', [service('request_stack')->ignoreOnInvalid()])
            ->call('setLocaleSwitcher', [service('translation.locale_switcher')->ignoreOnInvalid()])

        ->set('twig.template_iterator', TemplateIterator::class)
            ->args([service('kernel')abstract_arg('Twig paths')param('twig.default_path')abstract_arg('File name pattern')])

        
->set('translation.dumper.ini', IniFileDumper::class)
            ->tag('translation.dumper', ['alias' => 'ini'])

        ->set('translation.dumper.json', JsonFileDumper::class)
            ->tag('translation.dumper', ['alias' => 'json'])

        ->set('translation.dumper.res', IcuResFileDumper::class)
            ->tag('translation.dumper', ['alias' => 'res'])

        ->set('translation.extractor.php', PhpExtractor::class)
            ->deprecate('symfony/framework-bundle', '6.2', 'The "%service_id%" service is deprecated, use "translation.extractor.php_ast" instead.')
            ->tag('translation.extractor', ['alias' => 'php'])

        ->set('translation.extractor.php_ast', PhpAstExtractor::class)
            ->args([tagged_iterator('translation.extractor.visitor')])
            ->tag('translation.extractor', ['alias' => 'php'])

        ->set('translation.extractor.visitor.trans_method', TransMethodVisitor::class)
            ->tag('translation.extractor.visitor')

        ->set('translation.extractor.visitor.translatable_message', TranslatableMessageVisitor::class)
            ->tag('translation.extractor.visitor')

        
->args([service('texter.transports')])
            ->tag('messenger.message_handler', ['handles' => SmsMessage::class])

        ->set('texter.messenger.push_handler', MessageHandler::class)
            ->args([service('texter.transports')])
            ->tag('messenger.message_handler', ['handles' => PushMessage::class])

        ->set('notifier.notification_logger_listener', NotificationLoggerListener::class)
            ->tag('kernel.event_subscriber')

        ->alias('notifier.logger_notification_listener', 'notifier.notification_logger_listener')
            ->deprecate('symfony/framework-bundle', '6.3', 'The "%alias_id%" service is deprecated, use "notifier.notification_logger_listener" instead.')

    ;
};
'security.authenticator.managers_locator' => service('security.authenticator.managers_locator')->ignoreOnInvalid(),
                    'request_stack' => service('request_stack'),
                    'security.firewall.map' => service('security.firewall.map'),
                    'security.user_checker' => service('security.user_checker'),
                    'security.firewall.event_dispatcher_locator' => service('security.firewall.event_dispatcher_locator'),
                    'security.csrf.token_manager' => service('security.csrf.token_manager')->ignoreOnInvalid(),
                ]),
                abstract_arg('authenticators'),
            ])
        ->alias(Security::class, 'security.helper')
        ->alias(LegacySecurity::class, 'security.helper')
            ->deprecate('symfony/security-bundle', '6.2', 'The "%alias_id%" service alias is deprecated, use "'.Security::class.'" instead.')

        ->set('security.user_value_resolver', UserValueResolver::class)
            ->args([
                service('security.token_storage'),
            ])
            ->tag('controller.argument_value_resolver', ['priority' => 120, 'name' => UserValueResolver::class])

        ->set('security.security_token_value_resolver', SecurityTokenValueResolver::class)
            ->args([
                service('security.token_storage'),
            ])
            
<?php
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return static function DRoutingConfigurator $routes): void {
    $routes->add('route', '/hello');
    $routes->add('overrided', '/');
    $routes->alias('alias', 'route');
    $routes->alias('deprecated', 'route')
        ->deprecate('foo/bar', '1.0.0', '');
    $routes->alias('deprecated-with-custom-message', 'route')
        ->deprecate('foo/bar', '1.0.0', 'foo %alias_id%.');
    $routes->alias('deep', 'alias');
    $routes->alias('overrided', 'route');
};
if (!$definition->hasTag('container.excluded') || !$this->has($id)) {
                $this->setDefinition($id$definition);
            }
        }
        $this->addAliases($container->getAliases());
        $parameterBag = $this->getParameterBag();
        $otherBag = $container->getParameterBag();
        $parameterBag->add($otherBag->all());

        if ($parameterBag instanceof ParameterBag && $otherBag instanceof ParameterBag) {
            foreach ($otherBag->allDeprecated() as $name => $deprecated) {
                $parameterBag->deprecate($name, ...$deprecated);
            }
        }

        if ($this->trackResources) {
            foreach ($container->getResources() as $resource) {
                $this->addResource($resource);
            }
        }

        foreach ($this->extensions as $name => $extension) {
            if (!isset($this->extensionConfigs[$name])) {
                
abstract_arg('workflow definition'),
                abstract_arg('marking store'),
                service('event_dispatcher')->ignoreOnInvalid(),
                abstract_arg('workflow name'),
                abstract_arg('events to dispatch'),
            ])
            ->abstract()
        ->set('workflow.marking_store.method', MethodMarkingStore::class)
            ->abstract()
        ->set('.workflow.registry', Registry::class)
        ->alias(Registry::class, '.workflow.registry')
            ->deprecate('symfony/workflow', '6.2', 'The "%alias_id%" alias is deprecated, inject the workflow directly.')
        ->alias('workflow.registry', '.workflow.registry')
            ->deprecate('symfony/workflow', '6.2', 'The "%alias_id%" alias is deprecated, inject the workflow directly.')
        ->set('workflow.security.expression_language', ExpressionLanguage::class)
    ;
};
->args([
                service('serializer.mapping.class_metadata_factory'),
                service('serializer.name_converter.metadata_aware'),
                service('serializer.property_accessor'),
                service('property_info')->ignoreOnInvalid(),
                service('serializer.mapping.class_discriminator_resolver')->ignoreOnInvalid(),
                null,
            ])
            ->tag('serializer.normalizer', ['priority' => -1000])

        ->alias(ObjectNormalizer::class, 'serializer.normalizer.object')
            ->deprecate('symfony/serializer', '6.2', 'The "%alias_id%" service alias is deprecated, type-hint against "'.NormalizerInterface::class.'" or implement "'.NormalizerAwareInterface::class.'" instead.')

        ->set('serializer.normalizer.property', PropertyNormalizer::class)
            ->args([
                service('serializer.mapping.class_metadata_factory'),
                service('serializer.name_converter.metadata_aware'),
                service('property_info')->ignoreOnInvalid(),
                service('serializer.mapping.class_discriminator_resolver')->ignoreOnInvalid(),
                null,
            ])

        ->alias(PropertyNormalizer::class, 'serializer.normalizer.property')
            

        $bag->remove('foo');
        $this->assertEquals(['bar' => 'bar']$bag->all(), '->remove() removes a parameter');
    }

    public function testRemoveWithDeprecation()
    {
        $bag = new ParameterBag([
            'foo' => 'foo',
            'bar' => 'bar',
        ]);
        $bag->deprecate('foo', 'symfony/test', '6.3');
        $bag->remove('foo');
        $this->assertEquals(['bar' => 'bar']$bag->all(), '->remove() removes a parameter');
        $this->assertEquals([]$bag->allDeprecated());
    }

    public function testGetSet()
    {
        $bag = new ParameterBag(['foo' => 'bar']);
        $bag->set('bar', 'foo');
        $this->assertEquals('foo', $bag->get('bar'), '->set() sets the value of a new parameter');

        
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype;

return function DContainerConfigurator $c) {
    $di = $c->services()->defaults()
        ->tag('baz');
    $di->load(Prototype::class.'\\', '../Prototype')
        ->public()
        ->autoconfigure()
        ->exclude('../Prototype/{OtherDir,BadClasses,SinglyImplementedInterface,StaticConstructor}')
        ->factory('f')
        ->deprecate('vendor/package', '1.1', '%service_id%')
        ->args([0])
        ->args([1])
        ->autoconfigure(false)
        ->tag('foo')
        ->parent('foo');
    $di->set('foo')->lazy()->abstract()->public();
    $di->get(Prototype\Foo::class)->lazy(false);
};
->configurator([service('configurator_service_simple'), 'configureStdClass']);

    $s->set('decorated', 'stdClass');

    $s->set('decorator_service', 'stdClass')
        ->decorate('decorated');

    $s->set('decorator_service_with_name', 'stdClass')
        ->decorate('decorated', 'decorated.pif-pouf');

    $s->set('deprecated_service', 'stdClass')
        ->deprecate('vendor/package', '1.1', 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.');

    $s->set('new_factory', 'FactoryClass')
        ->property('foo', 'bar')
        ->private();

    $s->set('factory_service', 'Bar')
        ->factory([service('foo.baz'), 'getInstance']);

    $s->set('new_factory_service', 'FooBarBaz')
        ->property('foo', 'bar')
        ->factory([service('new_factory'), 'getInstance']);

    
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\Annotations\Reader;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('annotations.reader', AnnotationReader::class)
            ->call('addGlobalIgnoredName', ['required']) // @deprecated since Symfony 6.3             ->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.')

        ->set('annotations.cached_reader', PsrCachedReader::class)
            ->args([
                service('annotations.reader'),
                inline_service(ArrayAdapter::class),
                abstract_arg('Debug-Flag'),
            ])
            ->tag('annotations.cached_reader')
            ->tag('container.do_not_inline')
            ->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.')

        
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype;

return function DContainerConfigurator $c) {
    $di = $c->services()->defaults()
        ->tag('baz');
    $di->load(Prototype::class.'\\', '../Prototype')
        ->public()
        ->autoconfigure()
        ->exclude(['../Prototype/OtherDir', '../Prototype/BadClasses', '../Prototype/SinglyImplementedInterface', '../Prototype/StaticConstructor'])
        ->factory('f')
        ->deprecate('vendor/package', '1.1', '%service_id%')
        ->args([0])
        ->args([1])
        ->autoconfigure(false)
        ->tag('foo')
        ->parent('foo');
    $di->set('foo')->lazy()->abstract()->public();
    $di->get(Prototype\Foo::class)->lazy(false);
};
Home | Imprint | This part of the site doesn't use cookies.