public example

use Symfony\Bundle\WebProfilerBundle\Controller\RouterController;
use Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler;
use Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator;
use Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension;
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;

return static function DContainerConfigurator $container) {
    $container->services()

        ->set('web_profiler.controller.profiler', ProfilerController::class)
            ->public()
            ->args([
                service('router')->nullOnInvalid(),
                service('profiler')->nullOnInvalid(),
                service('twig'),
                param('data_collector.templates'),
                service('web_profiler.csp.handler'),
                param('kernel.project_dir'),
            ])

        ->set('web_profiler.controller.router', RouterController::class)
            ->public()
            
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return function DContainerConfigurator $c) {
    $s = $c->services()->defaults()->public();

    $s->set('foo', 'Foo');

    $s->set('service_closure', 'Bar')
        ->args([service_closure('foo')]);

    $s->set('service_closure_invalid', 'Bar')
        ->args([service_closure('invalid_service')->nullOnInvalid()]);
};
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

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

return function DContainerConfigurator $c) {
    $c->import('basic.php');

    $s = $c->services()->defaults()
        ->public()
        ->private()
        ->autoconfigure()
        ->autowire()
        ->tag('t', ['a' => 'b'])
        ->bind(Foo::classservice('bar'))
        ->bind('iterable $foo', tagged_iterator('foo'))
        ->bind('object $baz', inline_service('Baz'))
        ->public();

    $s->set(Foo::class)->args([service('bar')])->public();
    $s->set('bar', Foo::class)->call('setFoo')->autoconfigure(false);
};
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\HttpKernel\Debug\ErrorHandlerConfigurator;
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
use Symfony\Component\HttpKernel\EventListener\DebugHandlersListener;

return static function DContainerConfigurator $container) {
    $container->parameters()->set('debug.error_handler.throw_at', -1);

    $container->services()
        ->set('debug.error_handler_configurator', ErrorHandlerConfigurator::class)
            ->public()
            ->args([
                service('monolog.logger.php')->nullOnInvalid(),
                null, // Log levels map for enabled error levels                 param('debug.error_handler.throw_at'),
                param('kernel.debug'),
                param('kernel.debug'),
                service('monolog.logger.deprecation')->nullOnInvalid(),
            ])
            ->tag('monolog.logger', ['channel' => 'php'])

        ->set('debug.debug_handlers_listener', DebugHandlersListener::class)
            


namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Bundle\FrameworkBundle\CacheWarmer\CachePoolClearerCacheWarmer;
use Symfony\Component\Cache\DataCollector\CacheDataCollector;

return static function DContainerConfigurator $container) {
    $container->services()
        // DataCollector (public to prevent inlining, made private in CacheCollectorPass)         ->set('data_collector.cache', CacheDataCollector::class)
            ->public()
            ->tag('data_collector', [
                'template' => '@WebProfiler/Collector/cache.html.twig',
                'id' => 'cache',
                'priority' => 275,
            ])

        // CacheWarmer used in dev to clear cache pool         ->set('cache_pool_clearer.cache_warmer', CachePoolClearerCacheWarmer::class)
            ->args([
                service('cache.system_clearer'),
                [
                    
$container->services()

        ->set('parameter_bag', ContainerBag::class)
            ->args([
                service('service_container'),
            ])
        ->alias(ContainerBagInterface::class, 'parameter_bag')
        ->alias(ParameterBagInterface::class, 'parameter_bag')

        ->set('event_dispatcher', EventDispatcher::class)
            ->public()
            ->tag('container.hot_path')
            ->tag('event_dispatcher.dispatcher', ['name' => 'event_dispatcher'])
        ->alias(EventDispatcherInterfaceComponentAlias::class, 'event_dispatcher')
        ->alias(EventDispatcherInterface::class, 'event_dispatcher')
        ->alias(PsrEventDispatcherInterface::class, 'event_dispatcher')

        ->set('http_kernel', HttpKernel::class)
            ->public()
            ->args([
                service('event_dispatcher'),
                service('controller_resolver'),
                
param('kernel.enabled_locales'),
            ])
            ->tag('kernel.event_subscriber')

        ->set('validate_request_listener', ValidateRequestListener::class)
            ->tag('kernel.event_subscriber')

        ->set('disallow_search_engine_index_response_listener', DisallowRobotsIndexingListener::class)
            ->tag('kernel.event_subscriber')

        ->set('error_controller', ErrorController::class)
            ->public()
            ->args([
                service('http_kernel'),
                param('kernel.error_controller'),
                service('error_renderer'),
            ])

        ->set('exception_listener', ErrorListener::class)
            ->args([
                param('kernel.error_controller'),
                service('logger')->nullOnInvalid(),
                param('kernel.debug'),
                
use Symfony\Component\DependencyInjection\Reference;

require_once __DIR__.'/../includes/classes.php';
require_once __DIR__.'/../includes/foo.php';

return function DContainerConfigurator $c) {
    $p = $c->parameters();
    $p->set('baz_class', 'BazClass');
    $p->set('foo_class', FooClass::class)
      ->set('foo', 'bar');

    $s = $c->services()->defaults()->public();
    $s->set('foo')
        ->args(['foo', service('foo.baz')['%foo%' => 'foo is %foo%', 'foobar' => '%foo%'], true, service('service_container')])
        ->class(FooClass::class)
        ->tag('foo', ['foo' => 'foo'])
        ->tag('foo', ['bar' => 'bar', 'baz' => 'baz'])
        ->tag('foo', ['name' => 'bar', 'baz' => 'baz'])
        ->factory([FooClass::class, 'getInstance'])
        ->property('foo', 'bar')
        ->property('moo', service('foo.baz'))
        ->property('qux', ['%foo%' => 'foo is %foo%', 'foobar' => '%foo%'])
        ->call('setBar', [service('bar')])
        
$container->services()

        ->set('twig.extension.dump', DumpExtension::class)
            ->args([
                service('var_dumper.cloner'),
                service('var_dumper.html_dumper'),
            ])
            ->tag('twig.extension')

        ->set('data_collector.dump', DumpDataCollector::class)
            ->public()
            ->args([
                service('debug.stopwatch')->ignoreOnInvalid(),
                service('debug.file_link_formatter')->ignoreOnInvalid(),
                param('kernel.charset'),
                service('request_stack'),
                null, // var_dumper.cli_dumper or var_dumper.server_connection when debug.dump_destination is set             ])
            ->tag('data_collector', [
                'id' => 'dump',
                'template' => '@Debug/Profiler/dump.html.twig',
                'priority' => 240,
            ])
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;

class Php82Dummy
{
    public null $nil = null;

    public false $false = false;

    public true $true = true;

    public (\Traversable&\Countable)|null $someCollection = null;
}
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
use Symfony\Component\Cache\Messenger\EarlyExpirationHandler;
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('cache.app')
            ->parent('cache.adapter.filesystem')
            ->public()
            ->tag('cache.pool', ['clearer' => 'cache.app_clearer'])

        ->set('cache.app.taggable', TagAwareAdapter::class)
            ->args([service('cache.app')])
            ->tag('cache.taggable', ['pool' => 'cache.app'])

        ->set('cache.system')
            ->parent('cache.adapter.system')
            ->public()
            ->tag('cache.pool')

        
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use App\BarService;

return function DContainerConfigurator $c) {
    $c->services()
        ->set('bar', 'Class1')->public()
        ->set(BarService::class)
            ->public()
            ->abstract(true)
            ->lazy()
        ->set('foo')
            ->parent(BarService::class)
            ->public()
            ->decorate('bar', 'b', 1)
            ->args([service('b')])
            ->class('Class2')
            ->file('file.php')
            
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return function DContainerConfigurator $configurator) {
    $services = $configurator->services()->defaults()->public();

    $services->set('foo_service', \stdClass::class);

    $services->set('bar_service', \stdClass::class);

    $services->set('locator_dependent_service_indexed', \ArrayObject::class)
        ->args([service_locator([
            'foo' => service('foo_service'),
            'bar' => service('bar_service'),
        ])]);

    
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

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

return function DContainerConfigurator $c) {
    $c->import('basic.php');

    $s = $c->services()->defaults()
        ->public()
        ->private()
        ->autoconfigure()
        ->autowire()
        ->tag('t', ['a' => 'b'])
        ->bind(Foo::classservice('bar'))
        ->bind('iterable $foo', tagged_iterator('foo'))
        ->public();

    $s->set(Foo::class)->args([service('bar')])->public();
    $s->set('bar', Foo::class)->call('setFoo')->autoconfigure(false);
};
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

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.