setPublic example

use Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\EnvParameterException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

class CheckDefinitionValidityPassTest extends TestCase
{
    public function testProcessDetectsSyntheticNonPublicDefinitions()
    {
        $this->expectException(RuntimeException::class);
        $container = new ContainerBuilder();
        $container->register('a')->setSynthetic(true)->setPublic(false);

        $this->process($container);
    }

    public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
    {
        $this->expectException(RuntimeException::class);
        $container = new ContainerBuilder();
        $container->register('a')->setSynthetic(false)->setAbstract(false);

        $this->process($container);
    }
public function testProcessCacheObjectsAreDecorated()
    {
        $container = new ContainerBuilder();
        $collector = $container->register('data_collector.cache', CacheDataCollector::class);

        $container
            ->register('cache.object', ArrayAdapter::class)
            ->addTag('cache.pool', ['name' => 'cache.object']);

        $container
            ->register('something_is_decorating_cache_object', TagAwareAdapter::class)
            ->setPublic(true)
            ->setDecoratedService('cache.object');

        $container->register('some_service_using_cache_object', TraceableAdapter::class)
            ->setPublic(true)
            ->addArgument(new Reference('cache.object'));

        $container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING);

        $container->compile();
        $this->assertCount(1, $collector->getMethodCalls());
        $this->assertEquals(
            [
/** * @internal * * @covers \Shopware\Elasticsearch\DependencyInjection\ElasticsearchMigrationCompilerPass */
class ElasticsearchMigrationCompilerPassTest extends TestCase
{
    public function testCompilerPass(): void
    {
        $container = new ContainerBuilder();
        $container->register(MigrationSource::class D '.core.V6_5', MigrationSource::class)->setPublic(true);

        $container->addCompilerPass(new ElasticsearchMigrationCompilerPass());
        $container->compile();

        $calls = $container->getDefinition(MigrationSource::class D '.core.V6_5')->getMethodCalls();
        static::assertCount(1, $calls);

        static::assertSame('addDirectory', $calls[0][0]);
        static::assertStringContainsString('Migration/V6_5', $calls[0][1][0]);
        static::assertSame('Shopware\Elasticsearch\Migration\V6_5', $calls[0][1][1]);
    }
}
$container->setDefinition($this->getServiceIdLogger($servicePrefix)$this->createLogger($servicePrefix));
    }

    protected function createLoggerHandler(string $servicePrefix): Definition
    {
        return (new Definition(RotatingFileHandler::class[
                sprintf('%%kernel.logs_dir%%/%s_%%kernel.environment%%.log', $servicePrefix),
                sprintf('%%%s%%', $this->getParameterNameLoggerMaxFiles($servicePrefix)),
                sprintf('%%%s%%', $this->getParameterNameLogLevel($servicePrefix)),
            ]))
            ->addMethodCall('pushProcessor', [new Reference('monolog.processor.uid')])
            ->setPublic(false)
        ;
    }

    protected function createLoggerFormatter(): Definition
    {
        return (new Definition(PsrLogMessageProcessor::class))
            ->setPublic(false)
        ;
    }

    protected function createLogger(string $servicePrefix): Definition
    {

        if (!isset($data['configuratorSet'])) {
            return $data;
        }

        $configuratorSet = $article->getConfiguratorSet();
        if (!$configuratorSet) {
            $configuratorSet = new Set();
            $number = $data['mainDetail']['number'] ?? $article->getMainDetail()->getNumber();

            $configuratorSet->setName('Set-' . $number);
            $configuratorSet->setPublic(false);
        }

        if (isset($data['configuratorSet']['type'])) {
            $configuratorSet->setType($data['configuratorSet']['type']);
        }

        if (isset($data['configuratorSet']['name'])) {
            $configuratorSet->setName($data['configuratorSet']['name']);
        }

        $allOptions = [];
        

    public function __construct(\SplFileInfo|string $file, int $status = 200, array $headers = [], bool $public = true, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true)
    {
        parent::__construct(null, $status$headers);

        $this->setFile($file$contentDisposition$autoEtag$autoLastModified);

        if ($public) {
            $this->setPublic();
        }
    }

    /** * Sets the file to stream. * * @return $this * * @throws FileException */
    public function setFile(\SplFileInfo|string $file, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true)static
    {
/** * Parses an individual Definition. */
    private function parseDefinition(\DOMElement $service, string $file, Definition $defaults): ?Definition
    {
        if ($alias = $service->getAttribute('alias')) {
            $this->validateAlias($service$file);

            $this->container->setAlias($service->getAttribute('id')$alias = new Alias($alias));
            if ($publicAttr = $service->getAttribute('public')) {
                $alias->setPublic(XmlUtils::phpize($publicAttr));
            } elseif ($defaults->getChanges()['public'] ?? false) {
                $alias->setPublic($defaults->isPublic());
            }

            if ($deprecated = $this->getChildren($service, 'deprecated')) {
                $message = $deprecated[0]->nodeValue ?: '';
                $package = $deprecated[0]->getAttribute('package') ?: '';
                $version = $deprecated[0]->getAttribute('version') ?: '';

                if (!$deprecated[0]->hasAttribute('package')) {
                    throw new InvalidArgumentException(sprintf('Missing attribute "package" at node "deprecated" in "%s".', $file));
                }
use Symfony\Component\DependencyInjection\ContainerBuilder;

/** * @deprecated since shopware 5.7.3 and will be removed with 5.8 */
class SitemapCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        foreach (array_keys($container->findTaggedServiceIds('sitemap_url_provider')) as $id) {
            $def = $container->getDefinition($id);
            $def->setPublic(true);
        }
    }
}

        throw new \RuntimeException('secureAction() should never be called.');
    }

    public function profileAction()
    {
        return new Response('<html><body>Profile</body></html>');
    }

    public function homepageAction()
    {
        return (new Response('<html><body>Homepage</body></html>'))->setPublic();
    }

    public static function getSubscribedServices(): array
    {
        return [
            'twig' => Environment::class,
        ];
    }
}
public function testProcess()
    {
        $container = new ContainerBuilder();
        $container
            ->register('foo')
        ;
        $container
            ->register('bar')
        ;
        $container
            ->register('moo')
            ->setPublic(true)
            ->setArguments([new Reference('bar')])
        ;

        $this->process($container);

        $this->assertFalse($container->hasDefinition('foo'));
        $this->assertTrue($container->hasDefinition('bar'));
        $this->assertTrue($container->hasDefinition('moo'));
    }

    public function testProcessRemovesUnusedDefinitionsRecursively()
    {

        $alias = new Alias('foo', false, false);

        $this->assertEquals('foo', (string) $alias);
        $this->assertFalse($alias->isPublic());
        $this->assertTrue($alias->isPrivate());
    }

    public function testCanSetPublic()
    {
        $alias = new Alias('foo', false);
        $alias->setPublic(true);

        $this->assertTrue($alias->isPublic());
    }

    public function testCanDeprecateAnAlias()
    {
        $alias = new Alias('foo', false);
        $alias->setDeprecated('vendor/package', '1.1', 'The %alias_id% service is deprecated.');

        $this->assertTrue($alias->isDeprecated());
    }

    


    public static function getPrivatePublicDefinitions()
    {
        return [
            [
                (new Definition(__CLASS__)),
                'privates',
            ],
            [
                (new Definition(__CLASS__))
                    ->setPublic(true),
                'services',
            ],
        ];
    }

    public function testGetProxyFactoryCodeForInterface()
    {
        $class = DummyClass::class;
        $definition = new Definition($class);

        $definition->setLazy(true);
        
$container->removeDefinition(AbstractReverseProxyGateway::class);
            $container->removeDefinition(FastlyReverseProxyGateway::class);
            $container->removeDefinition(ReverseProxyCacheClearer::class);
            $container->removeDefinition(FastlyReverseProxyGateway::class);

            return;
        }

        $container->removeDefinition(CacheStore::class);

        $container->setAlias(CacheStore::class, ReverseProxyCache::class);
        $container->getAlias(CacheStore::class)->setPublic(true);

        if ($container->getParameter('storefront.reverse_proxy.fastly.enabled')) {
            $container->setAlias(AbstractReverseProxyGateway::class, FastlyReverseProxyGateway::class);
        } elseif ($container->getParameter('storefront.reverse_proxy.use_varnish_xkey')) {
            $container->setAlias(AbstractReverseProxyGateway::class, VarnishReverseProxyGateway::class);
        }
    }
}
new Expression('service("Shopware\\\\Bundle\\\\ContentTypeBundle\\\\Services\\\\TypeProvider").getType("' . $name . '")'),
                new Reference('shopware.bundle.content_type.' . $name),
            ]);

            $backendController->addTag(
                'shopware.controller',
                [
                    'controller' => 'Custom' . ucfirst($name),
                    'module' => 'backend',
                ]
            );
            $backendController->setPublic(true);

            $container->setDefinition('shopware_bundle.content_type.controllers.backend.' . $name$backendController);

            $apiController = new Definition(\Shopware\Bundle\ContentTypeBundle\Controller\Api\ContentType::class);
            $apiController->setArguments([
                new Reference('shopware.bundle.content_type.' . $name),
                new Reference('models'),
                new Reference('shopware.components.shop_registration_service'),
            ]);

            $apiController->addTag(
                

    public function process(ContainerBuilder $container)
    {
        parent::process($container);

        foreach ($container->getAliases() as $id => $alias) {
            $aliasId = (string) $alias;
            $this->currentId = $id;

            if ($aliasId !== $defId = $this->getDefinitionId($aliasId$container)) {
                $container->setAlias($id$defId)->setPublic($alias->isPublic());
            }
        }
    }

    protected function processValue(mixed $value, bool $isRoot = false): mixed
    {
        if (!$value instanceof Reference) {
            return parent::processValue($value$isRoot);
        }

        $defId = $this->getDefinitionId($id = (string) $value$this->container);

        
Home | Imprint | This part of the site doesn't use cookies.