Skip to content

Commit b221719

Browse files
committed
WIP Basic implementation
1 parent f857822 commit b221719

13 files changed

Lines changed: 483 additions & 2 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor/
2+
composer.lock
3+
.php_cs.cache

.php_cs.dist

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
return PhpCsFixer\Config::create()
4+
->setFinder(
5+
\Symfony\Component\Finder\Finder::create()
6+
->in([
7+
__DIR__ . '/src',
8+
__DIR__ . '/spec',
9+
])
10+
)
11+
->setRiskyAllowed(true)
12+
->setRules([
13+
'@Symfony' => true,
14+
'align_multiline_comment' => true,
15+
'array_indentation' => true,
16+
'array_syntax' => ['syntax' => 'short'],
17+
'backtick_to_shell_exec' => true,
18+
'blank_line_before_return' => true,
19+
'class_keyword_remove' => false,
20+
'combine_consecutive_issets' => true,
21+
'combine_consecutive_unsets' => true,
22+
'comment_to_phpdoc' => true,
23+
'compact_nullable_typehint' => true,
24+
'date_time_immutable' => true,
25+
'declare_strict_types' => true,
26+
'doctrine_annotation_array_assignment' => true,
27+
'doctrine_annotation_braces' => true,
28+
'doctrine_annotation_indentation' => true,
29+
'doctrine_annotation_spaces' => true,
30+
'escape_implicit_backslashes' => true,
31+
'explicit_indirect_variable' => true,
32+
'explicit_string_variable' => true,
33+
'final_internal_class' => false,
34+
'fully_qualified_strict_types' => true,
35+
'general_phpdoc_annotation_remove' => false,
36+
'header_comment' => false,
37+
'heredoc_to_nowdoc' => false,
38+
'linebreak_after_opening_tag' => true,
39+
'list_syntax' => true,
40+
'mb_str_functions' => true,
41+
'method_chaining_indentation' => true,
42+
'multiline_comment_opening_closing' => true,
43+
'multiline_whitespace_before_semicolons' => true,
44+
'native_function_invocation' => false,
45+
'no_alternative_syntax' => true,
46+
'no_blank_lines_before_namespace' => false,
47+
'no_null_property_initialization' => true,
48+
'no_php4_constructor' => true,
49+
'no_short_echo_tag' => false,
50+
'no_superfluous_elseif' => true,
51+
'no_unreachable_default_argument_value' => true,
52+
'no_useless_else' => true,
53+
'no_useless_return' => true,
54+
'not_operator_with_space' => false,
55+
'not_operator_with_successor_space' => false,
56+
'ordered_class_elements' => false,
57+
'ordered_imports' => true,
58+
'php_unit_dedicate_assert' => false,
59+
'php_unit_expectation' => false,
60+
'php_unit_mock' => false,
61+
'php_unit_namespaced' => false,
62+
'php_unit_no_expectation_annotation' => false,
63+
'php_unit_ordered_covers' => true,
64+
'php_unit_set_up_tear_down_visibility' => true,
65+
'php_unit_strict' => false,
66+
'php_unit_test_annotation' => false,
67+
'php_unit_test_class_requires_covers' => false,
68+
'phpdoc_add_missing_param_annotation' => true,
69+
'phpdoc_order' => true,
70+
'phpdoc_types_order' => ['null_adjustment' => 'always_last'],
71+
'pow_to_exponentiation' => true,
72+
'psr0' => true,
73+
'random_api_migration' => false,
74+
'simplified_null_return' => true,
75+
'static_lambda' => false,
76+
'strict_comparison' => true,
77+
'strict_param' => true,
78+
'string_line_ending' => true,
79+
'ternary_to_null_coalescing' => true,
80+
'void_return' => true,
81+
'yoda_style' => true,
82+
])
83+
;

.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
language: php
2+
3+
php:
4+
- 7.2
5+
- nightly
6+
7+
env:
8+
matrix:
9+
-
10+
- DEPENDENCIES=--prefer-lowest
11+
12+
cache:
13+
directories:
14+
- .composer/cache
15+
16+
matrix:
17+
fast_finish: true
18+
allow_failures:
19+
- php: nightly
20+
21+
before_install:
22+
- alias composer=composer\ --no-interaction && composer selfupdate
23+
24+
install:
25+
- travis_retry composer update --no-progress --profile --no-scripts --no-suggest $DEPENDENCIES
26+
27+
script:
28+
- bin/grumphp run

CONTRIBUTING

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Contributing
2+
3+
Api Problem Bundle is an open source, community-driven project. If you'd like to contribute,
4+
feel free to do this, but remember to follow this few simple rules:
5+
6+
## Branching strategy
7+
8+
- __Always__ base your changes on the `master` branch (all new development happens here),
9+
- When you create Pull Request, always select `master` branch as target, otherwise it
10+
will be closed (this is selected by default).
11+
12+
## Coverage
13+
14+
- All classes that interact solely with the core logic should be covered by Specs
15+
16+
## Code style / Formatting
17+
18+
- All code in the `src` and `spec` folder must follow the PSR-2 standard and should comply with the php-cs-fixer config.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Phpro
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,84 @@
1-
# api-problem-bundle
2-
RFC7807 Problem details integration for Symfony
1+
[![Travis](https://img.shields.io/travis/phpro/api-problem-bundle/master.svg)](http://travis-ci.org/phpro/api-problem-bundle)
2+
[![Installs](https://img.shields.io/packagist/dt/phpro/api-problem-bundle.svg)](https://packagist.org/packages/phpro/api-problem-bundle/stats)
3+
[![Packagist](https://img.shields.io/packagist/v/phpro/api-problem-bundle.svg)](https://packagist.org/packages/phpro/api-problem-bundle)
4+
5+
6+
# Api Problem Bundle
7+
8+
This package provides a [RFC7807](https://tools.ietf.org/html/rfc7807) Problem details exception listener for Symfony.
9+
Internal, this package uses the models provided by `phpro/api-problem`](https://www.github.com/phpro/api-problem).
10+
When an `ApiProblemException` is triggered, this bundle will return the correct response.
11+
12+
13+
## Installation
14+
15+
```sh
16+
composer require phpro/api-problem-bundle
17+
```
18+
19+
```php
20+
// config/bundles.php
21+
22+
return [
23+
// ...
24+
Phpro\ApiProblemBundle\ApiProblemBundle::class => ['all' => true],
25+
];
26+
```
27+
28+
## Configuration
29+
30+
TODO
31+
32+
33+
## Supported response formats
34+
35+
- application/problem+json
36+
37+
38+
## How it works
39+
40+
```
41+
Use Phpro\ApiProblem\Exception\ApiProblemException
42+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
43+
44+
SomeController {
45+
46+
/**
47+
* @Route('/some-route', defaults={"_format" = "json"})
48+
*/
49+
someAction() {
50+
throw new ApiProblemException(
51+
new HttpApiProblem('400', 'It aint all bad ...')
52+
);
53+
}
54+
}
55+
```
56+
57+
When the controller is marked as a "json" format or the request `Content-Type` is `*/json`, this bundle kicks in.
58+
It will transform the exception to following response:
59+
60+
Headers:
61+
```
62+
Content-Type: application/problem+json
63+
```
64+
65+
Body:
66+
```json
67+
{
68+
"status": 400,
69+
"type": "http:\/\/www.w3.org\/Protocols\/rfc2616\/rfc2616-sec10.html",
70+
"title": "Bad Request",
71+
"detail": "It aint all bad ..."
72+
}
73+
```
74+
75+
## About
76+
77+
### Submitting bugs and feature requests
78+
79+
Bugs and feature request are tracked on [GitHub](https://github.com/phpro/api-problem-bundle/issues).
80+
Please take a look at our rules before [contributing your code](CONTRIBUTING).
81+
82+
### License
83+
84+
api-problem-bundle is licensed under the [MIT License](LICENSE).

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "phpro/api-problem-bundle",
3+
"description": "RFC7807 Problem details integration for Symfony",
4+
"type": "library",
5+
"require-dev": {
6+
"friendsofphp/php-cs-fixer": "^2.12",
7+
"phpro/grumphp": "^0.14.1",
8+
"phpspec/phpspec": "^4.3"
9+
},
10+
"license": "MIT",
11+
"authors": [
12+
{
13+
"name": "Toon Verwerft",
14+
"email": "toon.verwerft@phpro.be"
15+
}
16+
],
17+
"require": {
18+
"php": "^7.2",
19+
"symfony/dependency-injection": "^4.1",
20+
"symfony/event-dispatcher": "^4.1",
21+
"symfony/http-kernel": "^4.1"
22+
},
23+
"config": {
24+
"sort-packages": true
25+
},
26+
"autoload": {
27+
"psr-4": {
28+
"Phpro\\ApiProblemBundle\\": "src/"
29+
}
30+
}
31+
}

grumphp.yml.dist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
git_dir: .
3+
bin_dir: vendor/bin
4+
tasks:
5+
phpcsfixer2:
6+
config: ".php_cs.dist"
7+
config_contains_finder: true
8+
phpspec:
9+
format: dot
10+
composer:
11+
no_check_lock: true

phpspec.yml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
suites:
2+
apiproblem_suite:
3+
namespace: Phpro\ApiProblemBundle
4+
psr4_prefix: Phpro\ApiProblemBundle
5+
formatter.name: pretty

spec/ApiProblemBundleSpec.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace spec\Phpro\ApiProblemBundle;
6+
7+
use Phpro\ApiProblemBundle\ApiProblemBundle;
8+
use PhpSpec\ObjectBehavior;
9+
use Symfony\Component\HttpKernel\Bundle\Bundle;
10+
11+
class ApiProblemBundleSpec extends ObjectBehavior
12+
{
13+
public function it_is_initializable(): void
14+
{
15+
$this->shouldHaveType(ApiProblemBundle::class);
16+
}
17+
18+
public function it_is_a_symfony_bundle(): void
19+
{
20+
$this->shouldHaveType(Bundle::class);
21+
}
22+
}

0 commit comments

Comments
 (0)