Skip to content

Commit

Permalink
Add DI compiler pass to register commonmark extension
Browse files Browse the repository at this point in the history
  • Loading branch information
bcremer committed Apr 13, 2015
1 parent 2e2db80 commit 4961351
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
29 changes: 29 additions & 0 deletions DependencyInjection/Compiler/CommonMarkExtensionPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Bcremer\Sculpin\Bundle\CommonMarkBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;

class CommonMarkExtensionPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (false === $container->hasDefinition('sculpin_commonmark.environment')) {
return;
}

$definition = $container->getDefinition('sculpin_commonmark.environment');

foreach ($container->findTaggedServiceIds('sculpin_commonmark.extension') as $id => $attributes) {
$definition->addMethodCall(
'addExtension',
[new Reference($id)]
);
}
}
}
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ class SculpinKernel extends \Sculpin\Bundle\SculpinBundle\HttpKernel\AbstractKer
}
```

## Defined services
## Extensibility
This bundle provides access to the low level component of the `thephpleague/commonmark` package.
For more information about `thephpleague/commonmark` customization please see [Advanced Usage & Customization](https://github.com/thephpleague/commonmark#advanced-usage--customization) and
[Community Extensions](https://github.com/thephpleague/commonmark#community-extensions).

### Defined services
This bundle defines the following services in the sculpin DI Container:

* `sculpin_commonmark.environment`
Expand All @@ -43,6 +48,13 @@ This bundle defines the following services in the sculpin DI Container:
* `sculpin_commonmark.converter`
* `sculpin_commonmark.event.commonmark`

### Defined DI Tags
This bundle handles the following [Dependency Injection Tags](http://symfony.com/doc/current/components/dependency_injection/tags.html):

* `sculpin_commonmark.extension`: To add a implementation of [`League\CommonMark\Extension\ExtensionInterface`](https://github.com/thephpleague/commonmark/blob/master/src/Extension/ExtensionInterface.php) to the
[`League\CommonMark\Environment`](https://github.com/thephpleague/commonmark/blob/master/src/Environment.php).


## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.
10 changes: 10 additions & 0 deletions SculpinCommonMarkBundle.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<?php
namespace Bcremer\Sculpin\Bundle\CommonMarkBundle;

use Bcremer\Sculpin\Bundle\CommonMarkBundle\DependencyInjection\Compiler\CommonMarkExtensionPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class SculpinCommonMarkBundle extends Bundle
{
const CONVERTER_NAME = 'commonmark';

/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new CommonMarkExtensionPass());
}
}

0 comments on commit 4961351

Please sign in to comment.