-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from jrobeson/use-config-from-container-extens…
…ions Implement configuration via container extensions
- Loading branch information
Showing
10 changed files
with
278 additions
and
41 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the c33s\StaticPageContentBundle. | ||
* | ||
* (c) consistency <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
/** | ||
* This file is part of the c33s\StaticPageContentBundle. | ||
* | ||
* (c) consistency <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace c33s\StaticPageContentBundle\Controller; | ||
|
||
|
@@ -23,17 +22,6 @@ | |
*/ | ||
class BaseStaticPageController extends Controller | ||
{ | ||
/** | ||
* Should the Static content be sanboxed? | ||
* | ||
* Only works for the default Content Container | ||
* | ||
* http://twig.sensiolabs.org/doc/api.html#sandbox-extension | ||
* | ||
* @var Boolean | ||
*/ | ||
protected $isSandboxed = false; | ||
|
||
/** | ||
* Returns the name of the Bundle, where the templates, which are | ||
* containing the static content, are stored | ||
|
@@ -42,7 +30,7 @@ class BaseStaticPageController extends Controller | |
*/ | ||
protected function getContentBundleName() | ||
{ | ||
return 'c33sStaticPageContentBundle'; | ||
return $this->container->getParameter('c33s_static_pages.content_bundle'); | ||
} | ||
|
||
/** | ||
|
@@ -56,12 +44,21 @@ protected function getContentBundleName() | |
*/ | ||
protected function getContentFolderName() | ||
{ | ||
return 'Content'; | ||
return $this->container->getParameter('c33s_static_pages.content_dir'); | ||
} | ||
|
||
/** | ||
* Should the Static content be sandboxed? | ||
* | ||
* Only works for the default Content Container | ||
* | ||
* http://twig.sensiolabs.org/doc/api.html#sandbox-extension | ||
* | ||
* @return bool | ||
*/ | ||
protected function isSandboxed() | ||
{ | ||
return $this->isSandboxed; | ||
return $this->container->getParameter('c33s_static_pages.use_template_sandbox'); | ||
} | ||
|
||
/** | ||
|
@@ -98,7 +95,7 @@ protected function getContentLocation($contentName, $subfolder = "") | |
*/ | ||
protected function getTemplateExtension() | ||
{ | ||
return '.html.twig'; | ||
return $this->container->getParameter('c33s_static_pages.template_extension'); | ||
} | ||
|
||
/** | ||
|
@@ -108,7 +105,7 @@ protected function getTemplateExtension() | |
*/ | ||
protected function getContainerLocation() | ||
{ | ||
return 'c33sStaticPageContentBundle:Content:_content_container.html.twig'; | ||
return $this->container->getParameter('c33s_static_pages.wrapper_template'); | ||
} | ||
|
||
/** | ||
|
@@ -119,7 +116,7 @@ protected function getContainerLocation() | |
*/ | ||
protected function getBaseTemplateLocation() | ||
{ | ||
return '::base.html.twig'; | ||
return $this->container->getParameter('c33s_static_pages.base_template'); | ||
} | ||
|
||
/** | ||
|
@@ -162,7 +159,7 @@ public function showAction($name, $subfolder="") | |
*/ | ||
public function isUsingTranslations() | ||
{ | ||
return false; | ||
return $this->container->getParameter('c33s_static_pages.prefer_locale_templates'); | ||
} | ||
|
||
/** | ||
|
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,62 @@ | ||
<?php | ||
/** | ||
* This file is part of the c33s\StaticPageContentBundle. | ||
* | ||
* (c) consistency <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace c33s\StaticPageContentBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
/* @var Symfony\Component\Config\Definition\Builder\NodeDefinition */ | ||
$rootNode = $treeBuilder->root('c33s_static_pages'); | ||
|
||
$rootNode | ||
->children() | ||
->scalarNode('base_template') | ||
->defaultValue('::base.html.twig') | ||
->info('Template that the content wrapper template will extend from') | ||
->end() | ||
->scalarNode('template_extension') | ||
->defaultValue('.html.twig') | ||
->info('Template file name extension') | ||
->end() | ||
->scalarNode('content_dir') | ||
->defaultValue('Content') | ||
->info('Relative path from the views directory to a directory containing' . PHP_EOL . | ||
'the page templates.') | ||
->end() | ||
->scalarNode('content_bundle') | ||
->defaultValue('c33sStaticPageContentBundle') | ||
->info('Bundle that holds the static pages') | ||
->end() | ||
->scalarNode('wrapper_template') | ||
->defaultValue('c33sStaticPageContentBundle:Content:_content_container.html.twig') | ||
->info('Template used to wrap your static pages') | ||
->end() | ||
->booleanNode('use_template_sandbox') | ||
->defaultFalse() | ||
->info('Should the pages use the twig sandbox extension?' . PHP_EOL . | ||
'(http://twig.sensiolabs.org/doc/api.html#sandbox-extension)' . PHP_EOL . | ||
'NOTE: it only works when using the default content template') | ||
->end() | ||
->booleanNode('prefer_locale_templates') | ||
->defaultFalse() | ||
->info('use templates for the requested locale if they exist. '. PHP_EOL . | ||
'These templates should be placed in a folder named after the locale in the content directory.') | ||
->end() | ||
->end(); | ||
|
||
return $treeBuilder; | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
/** | ||
* This file is part of the c33s\StaticPageContentBundle. | ||
* | ||
* (c) consistency <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace c33s\StaticPageContentBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; | ||
|
||
class StaticPagesExtension extends ConfigurableExtension | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function loadInternal(array $mergedConfig, ContainerBuilder $container) | ||
{ | ||
$fileLocator = new FileLocator(__DIR__.'/../Resources/config'); | ||
$loader = new XmlFileLoader($container, $fileLocator); | ||
$loader->load('services.xml'); | ||
|
||
foreach($mergedConfig as $name => $value) { | ||
$container->setParameter($this->getAlias() . '.' . $name, $value); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAlias() | ||
{ | ||
return 'c33s_static_pages'; | ||
} | ||
} | ||
|
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,14 @@ | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<parameters> | ||
<parameter key="c33s_static_pages.base_template"/> | ||
<parameter key="c33s_static_pages.content_bundle"/> | ||
<parameter key="c33s_static_pages.content_dir"/> | ||
<parameter key="c33s_static_pages.template_extension"/> | ||
<parameter key="c33s_static_pages.prefer_locale_templates"/> | ||
<parameter key="c33s_static_pages.use_template_sandbox"/> | ||
<parameter key="c33s_static_pages.wrapper_template"/> | ||
</parameters> | ||
</container> |
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,41 @@ | ||
<?php | ||
/* | ||
* This file is part of the c33s\StaticPageContentBundle. | ||
* | ||
* (c) consistency <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace c33s\StaticPageContentBundle\Tests\DependencyInjection; | ||
|
||
use c33s\StaticPageContentBundle\DependencyInjection\Configuration; | ||
use Matthias\SymfonyConfigTest\PhpUnit\AbstractConfigurationTestCase; | ||
|
||
class ConfigurationTest extends AbstractConfigurationTestCase | ||
{ | ||
protected function getConfiguration() | ||
{ | ||
return new Configuration(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itSetsDefaultConfiguration() | ||
{ | ||
$this->assertProcessedConfigurationEquals(array( | ||
array() | ||
), array( | ||
'base_template' => '::base.html.twig', | ||
'content_bundle' => 'c33sStaticPageContentBundle', | ||
'content_dir' => 'Content', | ||
'wrapper_template' => 'c33sStaticPageContentBundle:Content:_content_container.html.twig', | ||
'template_extension' => '.html.twig', | ||
'use_template_sandbox' => false, | ||
'prefer_locale_templates' => false | ||
)); | ||
} | ||
} | ||
|
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,48 @@ | ||
<?php | ||
/** | ||
* This file is part of the c33s\StaticPageContentBundle. | ||
* | ||
* (c) consistency <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace c33s\StaticPageContentBundle\Tests\DependencyInjection; | ||
|
||
use c33s\StaticPageContentBundle\DependencyInjection\StaticPagesExtension; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; | ||
|
||
class StaticPagesExtensionTest extends AbstractExtensionTestCase | ||
{ | ||
protected function getContainerExtensions() | ||
{ | ||
return array(new StaticPagesExtension()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itSetsDefaultParameters() | ||
{ | ||
$this->load(); | ||
|
||
$this->assertContainerBuilderHasParameter( | ||
'c33s_static_pages.content_bundle', | ||
'c33sStaticPageContentBundle' | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itCanChangeParameters() | ||
{ | ||
$config = array('content_dir' => 'pages'); | ||
$this->load($config); | ||
|
||
$this->assertContainerBuilderHasParameter( | ||
'c33s_static_pages.content_dir', | ||
'pages' | ||
); | ||
} | ||
} |
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,7 @@ | ||
<?php | ||
if (!@include(__DIR__ . '/../vendor/autoload.php')) { | ||
die('You must set up the project dependencies, run the following commands: | ||
wget http://getcomposer.org/composer.phar | ||
php composer.phar install --dev | ||
'); | ||
} |
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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the c33s\StaticPageContentBundle. | ||
* | ||
* (c) consistency <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* This file is part of the c33s\StaticPageContentBundle. | ||
* | ||
* (c) consistency <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace c33s\StaticPageContentBundle; | ||
|
||
use c33s\StaticPageContentBundle\DependencyInjection\StaticPagesExtension; | ||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class c33sStaticPageContentBundle extends Bundle | ||
{ | ||
public function getContainerExtension() | ||
{ | ||
return new StaticPagesExtension(); | ||
} | ||
} |
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
Oops, something went wrong.