Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d294c4f

Browse filesBrowse files
committed
Add a new disallow_search_engine_index option in framework bundle
1 parent f370eb1 commit d294c4f
Copy full SHA for d294c4f

File tree

4 files changed

+28
-2
lines changed
Filter options

4 files changed

+28
-2
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function getConfigTreeBuilder()
108108
$this->addWebLinkSection($rootNode);
109109
$this->addLockSection($rootNode);
110110
$this->addMessengerSection($rootNode);
111+
$this->addRobotsIndexSection($rootNode);
111112

112113
return $treeBuilder;
113114
}
@@ -1156,4 +1157,18 @@ function ($a) {
11561157
->end()
11571158
;
11581159
}
1160+
1161+
private function addRobotsIndexSection(ArrayNodeDefinition $rootNode)
1162+
{
1163+
$rootNode
1164+
->children()
1165+
->booleanNode('disallow_search_engine_index')
1166+
->info('Ask search engine to avoid indexing your application. Enabled by default when debug is enabled.')
1167+
->example('"true" to enable it. "false" to disable.')
1168+
->defaultValue($this->debug)
1169+
->treatNullLike($this->debug)
1170+
->end()
1171+
->end()
1172+
;
1173+
}
11591174
}

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,11 @@ public function load(array $configs, ContainerBuilder $container)
396396
// remove tagged iterator argument for resource checkers
397397
$container->getDefinition('config_cache_factory')->setArguments([]);
398398
}
399+
400+
if ($config['disallow_search_engine_index'] ?? false) {
401+
$container->register(DisallowRobotsIndexingListener::class)
402+
->addTag('kernel.event_listener', ['event' => KernelEvents::RESPONSE, 'priority' => -255]);
403+
}
399404
}
400405

401406
/**
@@ -709,8 +714,6 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
709714

710715
if ($debug) {
711716
$container->setParameter('debug.container.dump', '%kernel.cache_dir%/%kernel.container_class%.xml');
712-
$container->register(DisallowRobotsIndexingListener::class)
713-
->addTag('kernel.event_listener', ['event' => KernelEvents::RESPONSE, 'priority' => -255]);
714717
}
715718

716719
if ($debug && class_exists(Stopwatch::class)) {

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
330330
'default_bus' => null,
331331
'buses' => ['messenger.bus.default' => ['default_middleware' => true, 'middleware' => []]],
332332
],
333+
'disallow_search_engine_index' => true,
333334
];
334335
}
335336
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,13 @@ public function testRobotsTagListenerIsRegisteredInDebugMode()
13421342
$definition->getTag('kernel.event_listener')
13431343
);
13441344

1345+
$container = $this->createContainer(['kernel.debug' => true]);
1346+
(new FrameworkExtension())->load([['disallow_search_engine_index' => false]], $container);
1347+
$this->assertFalse(
1348+
$container->has(DisallowRobotsIndexingListener::class),
1349+
'DisallowRobotsIndexingListener should not be registered when explicitly disabled'
1350+
);
1351+
13451352
$container = $this->createContainer(['kernel.debug' => false]);
13461353
(new FrameworkExtension())->load([], $container);
13471354
$this->assertFalse($container->has(DisallowRobotsIndexingListener::class), 'DisallowRobotsIndexingListener should NOT be registered');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.