Skip to content

Commit 975b200

Browse files
author
Florian Eckerstorfer
committed
Merge pull request #23 from cocur/bundle
Add Symfony2 service
2 parents e3e109b + 8721880 commit 975b200

File tree

6 files changed

+181
-1
lines changed

6 files changed

+181
-1
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Features
1818
- No external dependencies (except PHPUnit for testing).
1919
- PSR-4 compatible
2020
- Compatible with PHP >= 5.3.3 and [HHVM](http://hhvm.com)
21+
- Integration as service for the Symfony2 framework
2122

2223

2324
Installation
@@ -53,6 +54,32 @@ echo $slugify->slugify('Hello World!', '_'); // hello_world
5354
The library also contains `Cocur\Slugify\SlugifyInterface`. Use this interface whenever you reference a type in your code.
5455

5556

57+
Integrations
58+
------------
59+
60+
### Symfony2
61+
62+
Slugify contains a Symfony2 bundle and service definition that allow you to use it as a service in your Symfony2 application. The code resides in the `Cocur\Slugify\Bridge\Bundle` namespace and you only need to add the bundle class to your `AppKernel.php`:
63+
64+
```php
65+
# app/AppKernel.php
66+
67+
class AppKernel extends Kernel
68+
{
69+
public function registerBundles()
70+
{
71+
$bundles = array(
72+
// ...
73+
new Cocur\Slugify\Bridge\Bundle\CocurSlugifyBundle(),
74+
);
75+
// ...
76+
}
77+
78+
// ...
79+
}
80+
```
81+
82+
5683
Changelog
5784
---------
5885

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"php": ">=5.3.3"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "~3.7"
22+
"phpunit/phpunit": "~3.7",
23+
"symfony/http-kernel": "~2.4",
24+
"symfony/dependency-injection": "~2.4"
2325
},
2426
"autoload": {
2527
"psr-4": {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* This file is part of cocur/slugify.
5+
*
6+
* (c) Florian Eckerstorfer <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Cocur\Slugify\Bridge\Bundle;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
/**
18+
* CourSlugifyBundle
19+
*
20+
* @package cocur/slugify
21+
* @subpackage bridge
22+
* @author Florian Eckerstorfer <[email protected]>
23+
* @copyright 2012-2014 Florian Eckerstorfer
24+
* @license http://www.opensource.org/licenses/MIT The MIT License
25+
*/
26+
class CocurSlugifyBundle extends Bundle
27+
{
28+
/**
29+
* {@inheritDoc}
30+
*/
31+
public function build(ContainerBuilder $container)
32+
{
33+
parent::build($container);
34+
35+
$extension = new CocurSlugifyExtension();
36+
$extension->load(array(), $container);
37+
38+
$container->registerExtension($extension);
39+
}
40+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/**
4+
* This file is part of cocur/slugify.
5+
*
6+
* (c) Florian Eckerstorfer <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Cocur\Slugify\Bridge\Bundle;
13+
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
17+
18+
/**
19+
* CocurSlugifyExtension
20+
*
21+
* @package cocur/slugify
22+
* @subpackage bridge
23+
* @author Florian Eckerstorfer <[email protected]>
24+
* @copyright 2012-2014 Florian Eckerstorfer
25+
* @license http://www.opensource.org/licenses/MIT The MIT License
26+
*/
27+
class CocurSlugifyExtension extends Extension
28+
{
29+
/**
30+
* {@inheritDoc}
31+
*
32+
* @param mixed[] $configs
33+
* @param ContainerBuilder $container
34+
*/
35+
public function load(array $configs, ContainerBuilder $container)
36+
{
37+
$container->setDefinition('cocur_slugify', new Definition('Cocur\Slugify\Slugify'));
38+
}
39+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Cocur\Slugify\Bridge\Bundle;
4+
5+
use Cocur\Slugify\Bridge\Bundle\CocurSlugifyBundle;
6+
7+
/**
8+
* CocurSlugifyBundleTest
9+
*
10+
* @group unit
11+
*/
12+
class CocurSlugifyBundleTest extends \PHPUnit_Framework_TestCase
13+
{
14+
public function setUp()
15+
{
16+
$this->bundle = new CocurSlugifyBundle();
17+
}
18+
19+
/**
20+
* @test
21+
* @covers Cocur\Slugify\Bridge\Bundle\CocurSlugifyBundle::build()
22+
*/
23+
public function build()
24+
{
25+
$container = $this->getMock(
26+
'Symfony\Component\DependencyInjection\ContainerBuilder',
27+
array('registerExtension')
28+
);
29+
$container->expects($this->once())
30+
->method('registerExtension')
31+
->with($this->isInstanceOf('Cocur\Slugify\Bridge\Bundle\CocurSlugifyExtension'));
32+
33+
$this->bundle->build($container);
34+
}
35+
}
36+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Cocur\Slugify\Bridge\Bundle;
4+
5+
use Cocur\Slugify\Bridge\Bundle\CocurSlugifyExtension;
6+
7+
/**
8+
* CocurSlugifyExtensionTest
9+
*
10+
* @group unit
11+
*/
12+
class CocurSlugifyExtensionTest extends \PHPUnit_Framework_TestCase
13+
{
14+
public function setUp()
15+
{
16+
$this->extension = new CocurSlugifyExtension();
17+
}
18+
19+
/**
20+
* @test
21+
* @covers Cocur\Slugify\Bridge\Bundle\CocurSlugifyExtension::load()
22+
*/
23+
public function load()
24+
{
25+
$container = $this->getMock(
26+
'Symfony\Component\DependencyInjection\ContainerBuilder',
27+
array('setDefinition')
28+
);
29+
$container->expects($this->once())
30+
->method('setDefinition')
31+
->with('cocur_slugify', $this->isInstanceOf('Symfony\Component\DependencyInjection\Definition'));
32+
33+
$this->extension->load(array(), $container);
34+
}
35+
}
36+

0 commit comments

Comments
 (0)