Skip to content

Commit

Permalink
Merge pull request PUGX#46 from eux/master
Browse files Browse the repository at this point in the history
moved statistic related classes to a proper bundle
  • Loading branch information
leopro committed Jun 5, 2013
2 parents 379760a + 6749c74 commit aa2ad44
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 53 deletions.
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
app/cache
app/logs
app/parameters.yml
app/bootstrap.php.cache
bin/phpunit
vendor
web/bundles
/composer.lock
/app/cache/*
/app/logs/*
/app/config/parameters.yml
/app/bootstrap*
/bin/phpunit
/vendor/
/web/bundles/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ matrix:
- php: 5.5

before_script:
- COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install
- COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev --no-interaction install

script:
- bin/phpunit
1 change: 1 addition & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function registerBundles()
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Snc\RedisBundle\SncRedisBundle(),
new PUGX\BadgeBundle\PUGXBadgeBundle(),
new PUGX\StatsBundle\PUGXStatsBundle(),
);

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
Expand Down
6 changes: 3 additions & 3 deletions app/config/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ imports:
- { resource: config.yml }

services:
statistic_listener:
class: PUGX\BadgeBundle\Service\Statistic\NullPersister
stats_listener:
class: PUGX\StatsBundle\Service\NullPersister

framework:
router: { resource: "%kernel.root_dir%/config/routing_dev.yml" }
Expand All @@ -27,4 +27,4 @@ monolog:
level: info

assetic:
use_controller: true
use_controller: true
14 changes: 0 additions & 14 deletions app/config/parameters.yml

This file was deleted.

4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions src/PUGX/BadgeBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
<parameter key="image_creator.class">PUGX\BadgeBundle\Service\ImageCreator</parameter>
<parameter key="badge_package.class">PUGX\BadgeBundle\Package\Package</parameter>
<parameter key="package_manager.class">PUGX\BadgeBundle\Service\PackageManager</parameter>
<parameter key="statistic_listener.class">PUGX\BadgeBundle\Listener\StatisticListener</parameter>
<parameter key="statistic_persister.class">PUGX\BadgeBundle\Service\Statistic\RedisPersister</parameter>
</parameters>

<services>
Expand All @@ -29,16 +27,6 @@
<argument>DroidSans.ttf</argument>
<tag name="monolog.logger" channel="image_creator"/>
</service>

<!--listener and statistics-->
<service id="statistic_persister" class="%statistic_persister.class%">
<argument type="service" id="snc_redis.default"/>
</service>

<service id="statistic_listener" class="%statistic_listener.class%">
<argument type="service" id="statistic_persister"/>
<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController"/>
</service>
</services>


Expand Down
29 changes: 29 additions & 0 deletions src/PUGX/StatsBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace PUGX\StatsBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http:https://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('pugx_stats');

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
}
}
28 changes: 28 additions & 0 deletions src/PUGX/StatsBundle/DependencyInjection/PUGXStatsExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace PUGX\StatsBundle\DependencyInjection;

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

/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http:https://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class PUGXStatsExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
* file that was distributed with this source code.
*/

namespace PUGX\BadgeBundle\Listener;
namespace PUGX\StatsBundle\Listener;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use PUGX\BadgeBundle\Service\Statistic\PersisterInterface;
use PUGX\StatsBundle\Service\PersisterInterface;

/**
* Class StatisticListener
* Class StatsListener
* This class is intended to collect and store usage statistic on Redis.
*
* @package PUGX\BadgeBundle\Listener
*/
class StatisticListener
class StatsListener
{
private $client;

Expand Down
9 changes: 9 additions & 0 deletions src/PUGX/StatsBundle/PUGXStatsBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PUGX\StatsBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class PUGXStatsBundle extends Bundle
{
}
22 changes: 22 additions & 0 deletions src/PUGX/StatsBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" ?>

<container xmlns="http:https://symfony.com/schema/dic/services"
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:https://symfony.com/schema/dic/services http:https://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="stats_listener.class">PUGX\StatsBundle\Listener\StatsListener</parameter>
<parameter key="stats_persister.class">PUGX\StatsBundle\Service\RedisPersister</parameter>
</parameters>

<services>
<service id="stats_persister" class="%stats_persister.class%">
<argument type="service" id="snc_redis.default"/>
</service>

<service id="stats_listener" class="%stats_listener.class%">
<argument type="service" id="stats_persister"/>
<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController"/>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/

namespace PUGX\BadgeBundle\Service\Statistic;
namespace PUGX\StatsBundle\Service;

class NullPersister implements PersisterInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/

namespace PUGX\BadgeBundle\Service\Statistic;
namespace PUGX\StatsBundle\Service;

Interface PersisterInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/

namespace PUGX\BadgeBundle\Service\Statistic;
namespace PUGX\StatsBundle\Service;

class RedisPersister implements PersisterInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
<?php

namespace PUGX\BadgeBundle\Tests\Listener;
namespace PUGX\StatsBundle\Tests\Listener;

use PUGX\BadgeBundle\Listener\StatisticListener;
use PUGX\StatsBundle\Listener\StatsListener;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class StatisticListenerTest extends WebTestCase
class StatListenerTest extends WebTestCase
{
protected $persister;

protected $controllerEvent;

protected $request;

protected $listener;

public function setUp()
{

$this->persister = $this->getMockBuilder('PUGX\BadgeBundle\Service\Statistic\PersisterInterface')
$this->persister = $this->getMockBuilder('PUGX\StatsBundle\Service\PersisterInterface')
->disableOriginalConstructor()->getMock();

$this->controllerEvent = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterControllerEvent')
->disableOriginalConstructor()->getMock();

$this->request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
->disableOriginalConstructor()->getMock();

$this->listener = new StatsListener($this->persister);
}

public function testOnKernelController()
Expand Down Expand Up @@ -45,8 +54,6 @@ public function testOnKernelController()
->with($repository, $method)
->will($this->returnSelf());

$this->listener = new StatisticListener($this->persister);
$this->listener->onKernelController($this->controllerEvent);

}
}

0 comments on commit aa2ad44

Please sign in to comment.