Skip to content

Commit 6e1cf81

Browse files
author
Florian Eckerstorfer
committed
Use DI to register command
1 parent 955ed38 commit 6e1cf81

File tree

6 files changed

+120
-9
lines changed

6 files changed

+120
-9
lines changed

Command/InstallSymfony2CodingStandardCommand.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Bc\Bundle\Symfony2CodingStandardBundle\Command;
1212

13-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
13+
use Symfony\Component\Console\Command\Command;
1414
use Symfony\Component\Console\Input\InputArgument;
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Input\InputOption;
@@ -28,8 +28,22 @@
2828
*
2929
* @codeCoverageIgnore
3030
*/
31-
class InstallSymfony2CodingStandardCommand extends ContainerAwareCommand
31+
class InstallSymfony2CodingStandardCommand extends Command
3232
{
33+
/** @var string */
34+
private $rootDir;
35+
36+
/**
37+
* Constructor.
38+
*
39+
* @param string $rootDir Root directory
40+
*/
41+
public function __construct($rootDir)
42+
{
43+
$this->rootDir = $rootDir;
44+
parent::__construct();
45+
}
46+
3347
/**
3448
* {@inheritDoc}
3549
*/
@@ -43,7 +57,7 @@ protected function configure()
4357
*/
4458
protected function execute(InputInterface $input, OutputInterface $output)
4559
{
46-
$vendorDir = sprintf('%s/../vendor', $this->getContainer()->getParameter('kernel.root_dir'));
60+
$vendorDir = sprintf('%s/../vendor', $this->rootDir);
4761
$codeSnifferDir = sprintf('%s/squizlabs/php_codesniffer', $vendorDir);
4862

4963
if (false === file_exists($codeSnifferDir)) {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* This file is part of BcSymfony2CodingStandardBundle.
4+
*
5+
* (c) 2013 Florian Eckerstorfer <[email protected]>
6+
*
7+
* This source file is subject to the MIT license that is bundled
8+
* with this source code in the file LICENSE.
9+
*/
10+
11+
namespace Bc\Bundle\Symfony2CodingStandardBundle\DependencyInjection;
12+
13+
use Symfony\Component\DependencyInjection\ContainerBuilder;
14+
use Symfony\Component\Config\FileLocator;
15+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
16+
use Symfony\Component\DependencyInjection\Loader;
17+
18+
/**
19+
* BcSymfony2CodingStandardExtension
20+
*
21+
* @package BcSymfony2CodingStandardBundle
22+
* @subpackage DependencyInjection
23+
* @author Florian Eckerstorfer <[email protected]>
24+
* @copyright 2013 Florian Eckerstorfer
25+
* @license http://opensource.org/licenses/MIT The MIT License
26+
*/
27+
class BcSymfony2CodingStandardExtension extends Extension
28+
{
29+
/**
30+
* {@inheritDoc}
31+
*/
32+
public function load(array $configs, ContainerBuilder $container)
33+
{
34+
$configuration = new Configuration();
35+
$config = $this->processConfiguration($configuration, $configs);
36+
37+
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
38+
$loader->load('services.xml');
39+
}
40+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* This file is part of BcSymfony2CodingStandardBundle.
4+
*
5+
* (c) 2013 Florian Eckerstorfer <[email protected]>
6+
*
7+
* This source file is subject to the MIT license that is bundled
8+
* with this source code in the file LICENSE.
9+
*/
10+
11+
namespace Bc\Bundle\Symfony2CodingStandardBundle\DependencyInjection;
12+
13+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
14+
use Symfony\Component\Config\Definition\ConfigurationInterface;
15+
16+
/**
17+
* Configuration
18+
*
19+
* @package BcSymfony2CodingStandardBundle
20+
* @subpackage DependencyInjection
21+
* @author Florian Eckerstorfer <[email protected]>
22+
* @copyright 2013 Florian Eckerstorfer
23+
* @license http://opensource.org/licenses/MIT The MIT License
24+
*/
25+
class Configuration implements ConfigurationInterface
26+
{
27+
/**
28+
* {@inheritDoc}
29+
*/
30+
public function getConfigTreeBuilder()
31+
{
32+
$treeBuilder = new TreeBuilder();
33+
$rootNode = $treeBuilder->root('bc_symfony2_coding_standard');
34+
35+
return $treeBuilder;
36+
}
37+
}

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ Compatiblity
1818
<th>BcSymfony2CodingStandardBundle</th><th>Symfony</th>
1919
</tr>
2020
<tr>
21-
<td>0.1.*</td><td>2.3.*</td>
21+
<td><code>0.1.*</code></td><td><code>2.3.*</code></td>
22+
</tr>
23+
<tr>
24+
<td><code>master</code></td><td><code>2.4.*</code></td>
2225
</tr>
2326
</table>
2427

@@ -30,7 +33,7 @@ First of all you have to add the bundle to your `composer.json`:
3033

3134
{
3235
"require": {
33-
"braincrafted/symfony2cs-bundle": "0.1.*"
36+
"braincrafted/symfony2cs-bundle": "dev-master"
3437
}
3538
}
3639

@@ -80,8 +83,6 @@ However, things get even better if you add the script handler that is included i
8083
},
8184
...
8285

83-
_The `composer.json` above is based on [Symfony 2.3.*](https://github.com/symfony/symfony-standard/blob/2.3/composer.json)._
84-
8586

8687
Usage
8788
-----

Resources/config/services.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="bc_symfony2_coding_standard.command.install.class">Bc\Bundle\Symfony2CodingStandardBundle\Command\InstallSymfony2CodingStandardCommand</parameter>
9+
</parameters>
10+
11+
<services>
12+
<service id="bc_symfony2_coding_standard.command.install" class="%bc_symfony2_coding_standard.command.install.class%">
13+
<argument>%kernel.root_dir%</argument>
14+
<tag name="console.command" />
15+
</service>
16+
</services>
17+
18+
</container>

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"license": "MIT",
44
"type": "symfony-bundle",
55
"require": {
6-
"symfony/symfony": "2.3.0"
6+
"symfony/symfony": "~2.4"
77
},
88
"require-dev": {
99
"squizlabs/php_codesniffer": "1.4.*"
10-
}
10+
},
11+
"minimum-stability": "beta"
1112
}

0 commit comments

Comments
 (0)