Skip to content

Commit

Permalink
Add Symfony Bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgarlag committed Mar 9, 2016
1 parent 5649fce commit 9f99c9f
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]

### Added
- Add Symfony Bundle

## 0.1.0 - 2016-03-09

### Added
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ Once registered, you can call the new `breakpoint` function:
```


Symfony Bundle
--------------

If you want to use this extension in your Symfony application, you can enable the
Symfony Bundle included in this package:

```php
// app/AppKernel.php
if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
$bundles[] = new Ajgl\Twig\Extension\SymfonyBundle\AjglBreakpointTwigExtensionBundle();
}
```

This bundle will register the twig extension automatically. So, once enabled, you
can insert the `breakpoint` twig function in your templates.


License
-------

Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
"php": ">=5.4.0",
"twig/twig": "^1.14"
},
"require-dev": {
"symfony/framework-bundle": "^2.3",
"symfony/twig-bundle": "^2.3"
},
"suggest": {
"ext-xdebug": "The Xdebug extension is required for the breakpoint to work"
"ext-xdebug": "The Xdebug extension is required for the breakpoint to work",
"symfony/framework-bundle": "The framework bundle to integrate the extension into Symfony",
"symfony/twig-bundle": "The twig bundle to integrate the extension into Symfony"
},
"extra": {
"branch-alias": {
Expand Down
21 changes: 21 additions & 0 deletions src/SymfonyBundle/AjglBreakpointTwigExtensionBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* AJGL Breakpoint Twig Extension Component
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Twig\Extension\SymfonyBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* @author Antonio J. García Lagar <[email protected]>
*/
class AjglBreakpointTwigExtensionBundle extends Bundle
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* AJGL Breakpoint Twig Extension Component
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Twig\Extension\SymfonyBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* @author Antonio J. García Lagar <[email protected]>
*/
class AjglBreakpointTwigExtensionExtension extends Extension
{
public function load(array $config, ContainerBuilder $container)
{
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('twig.xml');
}
}
13 changes: 13 additions & 0 deletions src/SymfonyBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>

<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">

<services>
<service id="ajgl_twig_extension.breakpoint" class="Ajgl\Twig\Extension\BreakpointExtension" public="false">
<tag name="twig.extension"/>
</service>
</services>

</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* AJGL Breakpoint Twig Extension Component
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Twig\Extension\Tests\SymfonyBundle\DependencyInjection;

use Ajgl\Twig\Extension\SymfonyBundle\DependencyInjection\AjglBreakpointTwigExtensionExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @author Antonio J. García Lagar <[email protected]>
*/
class AjglBreakpointTwigExtensionExtensionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ContainerBuilder
*/
protected $container;

/**
* @var AjglBreakpointTwigExtensionExtension
*/
protected $extension;

protected function setUp()
{
$this->container = new ContainerBuilder();
$this->extension = new AjglBreakpointTwigExtensionExtension();
}

public function testTwigExtensionsDefinition()
{
$this->extension->load(array(), $this->container);
$this->assertTrue($this->container->hasDefinition('ajgl_twig_extension.breakpoint'));
$definition = $this->container->getDefinition('ajgl_twig_extension.breakpoint');
$this->assertSame(
'Ajgl\Twig\Extension\BreakpointExtension',
$definition->getClass()
);
$this->assertNotNull($definition->getTag('twig.extension'));
}
}

0 comments on commit 9f99c9f

Please sign in to comment.