Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from M6Web/feature/add-base-bundle
Browse files Browse the repository at this point in the history
Add base bundle
  • Loading branch information
Cédric Vanet committed Oct 23, 2015
2 parents e1a8ec1 + 9d99e2d commit 2ea1b34
Show file tree
Hide file tree
Showing 40 changed files with 2,479 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .atoum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$runner->addTestsFromDirectory(__DIR__.'/Tests');
3 changes: 3 additions & 0 deletions .bootstrap.atoum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require __DIR__ . '/vendor/autoload.php';
10 changes: 10 additions & 0 deletions .coke
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Standard used by PHP CodeSniffer (required)
standard=vendor/m6web/symfony2-coding-standard/Symfony2

# White list of files and directories (optional)
.

# Black list of files and directories (optional)
!Tests/
!vendor/
!bin/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin/
vendor/
composer.lock
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: php

php:
- 5.5

branches:
only:
- master

install:
- composer install -n --dev

script:
- bin/atoum
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributing

First of all, **thank you** for contributing, **you are awesome**!

Here are few rules to follow for a easier code review before the maintainers accept and merge your request.

##### Rules development

- Run the test suite.
- Write (or update) unit tests.
- Write (or update) documentation.
- Write [commit messages that make sense](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)

##### Rules Pull Request
- [Rebase your branch](http://git-scm.com/book/en/Git-Branching-Rebasing) before submitting your Pull Request.
- [Squash your commits] to "clean" your pull request before merging (http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html).
- Write and good description which gives the context and/or explains why you are creating it.

**Thank you!**


### Install project to development

Get sources dependancies :

```
composer install
```

### Unit tests

Launch unit tests with Atoum

```
./bin/atoum
```

### Check style

Check style use [Coke](https://github.com/M6Web/Coke)

Start code analysis :

```
./bin/coke
```
56 changes: 56 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace M6Web\Bundle\ApiExceptionBundle\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
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('m6web_api_exception');

$rootNode
->children()
->booleanNode('stack_trace')->defaultValue(false)->end()
->booleanNode('match_all')->defaultValue(true)->end()
->arrayNode('default')
->addDefaultsIfNotSet()
->children()
->integerNode('code')->defaultValue(0)->end()
->integerNode('status')->defaultValue(500)->end()
->scalarNode('message')->defaultValue('Internal server error')->end()
->arrayNode('headers')
->useAttributeAsKey('name')
->prototype('scalar')->end()
->defaultValue([])
->end()
->end()
->end()
->arrayNode('exceptions')
->useAttributeAsKey('name')
->prototype('array')
->children()
->integerNode('code')->end()
->integerNode('status')->end()
->scalarNode('message')->end()
->arrayNode('headers')
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
->end();

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

namespace M6Web\Bundle\ApiExceptionBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

/**
* This is the class that loads and manages your bundle configuration
*/
class M6WebApiExceptionExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$this->loadExceptionManager($container, $config);
$this->loadExceptionListener($container, $config);
}

/**
* @return string
*/
public function getAlias()
{
return 'm6web_api_exception';
}

/**
* load service exception manager
*
* @param ContainerBuilder $container
* @param array $config
*/
protected function loadExceptionManager(ContainerBuilder $container, array $config)
{
$definition = new Definition(
'M6Web\Bundle\ApiExceptionBundle\Manager\ExceptionManager',
[
$config['default'],
$config['exceptions'],
]
);

$container->setDefinition($this->getAlias().'.manager.exception', $definition);
}

/**
* load service exception listener
*
* @param ContainerBuilder $container
* @param array $config
*/
protected function loadExceptionListener(ContainerBuilder $container, array $config)
{
$definition = new Definition(
'M6Web\Bundle\ApiExceptionBundle\EventListener\ExceptionListener',
[
new Reference('kernel'),
new Reference($this->getAlias().'.manager.exception'),
$config['match_all'],
$config['default'],
$config['stack_trace'],
]
);

$definition->addTag(
'kernel.event_listener',
[
'event' => 'kernel.exception',
'method' => 'onKernelException',
]
);

$container->setDefinition($this->getAlias().'.listener.exception', $definition);
}
}
Loading

0 comments on commit 2ea1b34

Please sign in to comment.