2011-02-25 12:34:20 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Knplabs\MarkdownBundle\DependencyInjection;
|
|
|
|
|
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension;
|
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
|
|
|
use Symfony\Component\Config\FileLocator;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
|
|
|
|
class KnplabsMarkdownExtension extends Extension
|
|
|
|
{
|
2011-02-25 15:43:59 +01:00
|
|
|
/**
|
|
|
|
* Handles the knplabs_markdown configuration.
|
|
|
|
*
|
|
|
|
* @param array $configs The configurations being loaded
|
|
|
|
* @param ContainerBuilder $container
|
|
|
|
*/
|
2011-02-25 12:34:20 +01:00
|
|
|
public function load(array $configs , ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
$config = array();
|
|
|
|
foreach($configs as $c) {
|
|
|
|
$config = array_merge($config, $c);
|
|
|
|
}
|
|
|
|
|
2011-02-25 15:43:59 +01:00
|
|
|
if(array_key_exists('parser', $config)) {
|
2011-02-25 12:34:20 +01:00
|
|
|
$this->parserLoad($config, $container);
|
|
|
|
}
|
|
|
|
|
2011-02-25 15:43:59 +01:00
|
|
|
if(array_key_exists('helper', $config)) {
|
2011-02-25 12:34:20 +01:00
|
|
|
$this->helperLoad($config, $container);
|
|
|
|
}
|
|
|
|
|
2011-02-25 15:43:59 +01:00
|
|
|
if(array_key_exists('twig', $config)) {
|
2011-02-25 12:34:20 +01:00
|
|
|
$this->twigLoad($config, $container);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-25 15:43:59 +01:00
|
|
|
/**
|
|
|
|
* Handles the parser configuration.
|
|
|
|
*
|
|
|
|
* @param array $config The configurations being loaded
|
|
|
|
* @param ContainerBuilder $container
|
|
|
|
*/
|
2011-02-25 12:34:20 +01:00
|
|
|
public function parserLoad($config, ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
|
|
|
$loader->load('parser.xml');
|
|
|
|
|
|
|
|
if(isset($config['class'])) {
|
|
|
|
$container->setParameter('markdown.parser.class', $config['class']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-25 15:43:59 +01:00
|
|
|
/**
|
|
|
|
* Handles the helper configuration.
|
|
|
|
*
|
|
|
|
* @param array $config The configurations being loaded
|
|
|
|
* @param ContainerBuilder $container
|
|
|
|
*/
|
2011-02-25 12:34:20 +01:00
|
|
|
public function helperLoad($config, ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
|
|
|
$loader->load('helper.xml');
|
|
|
|
}
|
|
|
|
|
2011-02-25 15:43:59 +01:00
|
|
|
/**
|
|
|
|
* Handles the twig configuration.
|
|
|
|
*
|
|
|
|
* @param array $config The configurations being loaded
|
|
|
|
* @param ContainerBuilder $container
|
|
|
|
*/
|
2011-02-25 12:34:20 +01:00
|
|
|
public function twigLoad($config, ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
|
|
|
$loader->load('twig.xml');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the base path for the XSD files.
|
|
|
|
*
|
|
|
|
* @return string The XSD base path
|
|
|
|
*/
|
|
|
|
public function getXsdValidationBasePath()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-02-25 15:43:59 +01:00
|
|
|
/**
|
|
|
|
* @see Symfony\Component\DependencyInjection\Extension\ExtensionInterface
|
|
|
|
*/
|
2011-02-25 12:34:20 +01:00
|
|
|
public function getNamespace()
|
|
|
|
{
|
2011-02-25 15:43:59 +01:00
|
|
|
return 'http://www.symfony-project.org/schema/dic/markdown';
|
2011-02-25 12:34:20 +01:00
|
|
|
}
|
|
|
|
|
2011-02-25 15:43:59 +01:00
|
|
|
/**
|
|
|
|
* @see Symfony\Component\DependencyInjection\Extension\ExtensionInterface
|
|
|
|
*/
|
2011-02-25 12:34:20 +01:00
|
|
|
public function getAlias()
|
|
|
|
{
|
|
|
|
return 'knplabs_markdown';
|
|
|
|
}
|
|
|
|
}
|