-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement add sitemap URL providers to sitemap generator compiler pass.
- Loading branch information
igor
committed
Feb 20, 2016
1 parent
33b9a0d
commit bf4c04d
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
DependencyInjection/Compiler/AddSitemapUrlProvidersPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* @author Igor Nikolaev <[email protected]> | ||
* @copyright Copyright (c) 2016, Darvin Studio | ||
* @link https://www.darvin-studio.ru | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Darvin\SitemapBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Add sitemap URL providers to sitemap generator compiler pass | ||
*/ | ||
class AddSitemapUrlProvidersPass implements CompilerPassInterface | ||
{ | ||
const SITEMAP_GENERATOR_ALIAS = 'darvin_sitemap.generator'; | ||
const SITEMAP_URL_PROVIDER_TAG = 'darvin_sitemap.url_provider'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasAlias(self::SITEMAP_GENERATOR_ALIAS)) { | ||
return; | ||
} | ||
|
||
$generatorId = (string) $container->getAlias(self::SITEMAP_GENERATOR_ALIAS); | ||
|
||
if (!$container->hasDefinition($generatorId)) { | ||
return; | ||
} | ||
|
||
$urlProviderIds = $container->findTaggedServiceIds(self::SITEMAP_URL_PROVIDER_TAG); | ||
|
||
if (empty($urlProviderIds)) { | ||
return; | ||
} | ||
|
||
$generatorDefinition = $container->getDefinition($generatorId); | ||
|
||
foreach ($urlProviderIds as $id => $tags) { | ||
$reference = new Reference($id); | ||
|
||
foreach ($tags as $tag) { | ||
$generatorDefinition->addMethodCall('addUrlProvider', array( | ||
$reference, | ||
)); | ||
} | ||
} | ||
} | ||
} |