This repository has been archived by the owner on Oct 11, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dominik Zogg
committed
Aug 25, 2017
0 parents
commit ed7d3ab
Showing
60 changed files
with
3,223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.idea | ||
.php_cs.cache | ||
cache | ||
phpunit | ||
vendor | ||
composer.lock | ||
var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "vagrant-php"] | ||
path = vagrant-php | ||
url = https://github.com/vagrant-php/ubuntu.git | ||
branch = 16.04 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
build: | ||
tests: | ||
override: | ||
- | ||
command: 'vendor/bin/phpunit --coverage-clover=coverage/clover.xml' | ||
coverage: | ||
file: 'coverage/clover.xml' | ||
format: 'php-clover' | ||
|
||
checks: | ||
php: true | ||
|
||
coding_style: | ||
php: {} | ||
|
||
filter: | ||
excluded_paths: | ||
- 'tests/*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
language: php | ||
|
||
php: | ||
- 7.0 | ||
- 7.1 | ||
|
||
services: | ||
- mysql | ||
|
||
matrix: | ||
include: | ||
- php: 7.0 | ||
env: dependencies=lowest | ||
- php: 7.0 | ||
env: dependencies=highest | ||
- php: 7.1 | ||
env: dependencies=lowest | ||
- php: 7.1 | ||
env: dependencies=highest | ||
|
||
before_script: | ||
- echo "USE mysql;\nUPDATE user SET password=PASSWORD('root') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root | ||
- composer self-update -q | ||
- if [ -z "$dependencies" ]; then composer install; fi; | ||
- if [ "$dependencies" = "lowest" ]; then composer update --prefer-lowest -n; fi; | ||
- if [ "$dependencies" = "highest" ]; then composer update -n; fi; | ||
|
||
script: vendor/bin/phpunit --coverage-text --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# chubbyphp/chubbyphp-api-slim-skeleton | ||
|
||
[![Build Status](https://api.travis-ci.org/chubbyphp/chubbyphp-api-slim-skeleton.png?branch=master)](https://travis-ci.org/chubbyphp/chubbyphp-api-slim-skeleton) | ||
[![Total Downloads](https://poser.pugx.org/chubbyphp/chubbyphp-api-slim-skeleton/downloads.png)](https://packagist.org/packages/chubbyphp/chubbyphp-api-slim-skeleton) | ||
[![Latest Stable Version](https://poser.pugx.org/chubbyphp/chubbyphp-api-slim-skeleton/v/stable.png)](https://packagist.org/packages/chubbyphp/chubbyphp-api-slim-skeleton) | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/chubbyphp/chubbyphp-api-slim-skeleton/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/chubbyphp/chubbyphp-api-slim-skeleton/?branch=master) | ||
[![Code Coverage](https://scrutinizer-ci.com/g/chubbyphp/chubbyphp-api-slim-skeleton/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/chubbyphp/chubbyphp-api-slim-skeleton/?branch=master) | ||
|
||
## Description | ||
|
||
A slim 3 skeleton to build web apis. | ||
|
||
## Requirements | ||
|
||
* php: ~7.0 | ||
* [chubbyphp/chubbyphp-api-http][1]: ~1.0@beta | ||
* [chubbyphp/chubbyphp-deserialization][2]: ~1.1 | ||
* [chubbyphp/chubbyphp-deserialization-model][3]: ~1.0 | ||
* [chubbyphp/chubbyphp-lazy][4]: ~1.1 | ||
* [chubbyphp/chubbyphp-model][5]: ~3.0 | ||
* [chubbyphp/chubbyphp-model-doctrine-dbal][6]: ~1.0 | ||
* [chubbyphp/chubbyphp-serialization][7]: ^1.0.1 | ||
* [chubbyphp/chubbyphp-translation][8]: ^1.1.2 | ||
* [chubbyphp/chubbyphp-validation][9]: ~2.1 | ||
* [chubbyphp/chubbyphp-validation-model][10]: ~1.0 | ||
* [monolog/monolog][11]: ~1.21 | ||
* [ramsey/uuid][12]: ~3.5 | ||
* [silex/providers][13]: ^2.0.3 | ||
* [slim/slim][14]: ~3.5 | ||
* [symfony/console][15]: ~3.1 | ||
* [symfony/yaml][16]: ~3.1 | ||
* [willdurand/negotiation][17]: ^2.3 | ||
|
||
## Installation | ||
|
||
### With vagrant-php | ||
|
||
#### Install `create-slim3-project` command | ||
|
||
[create-slim3-project][18] | ||
|
||
#### Create project | ||
|
||
```{.sh} | ||
create-slim3-project --name=myproject --vagrantIp=10.15.10.15 | ||
``` | ||
|
||
### With php on host | ||
|
||
```{.sh} | ||
composer create-project chubbyphp/chubbyphp-api-slim-skeleton myproject dev-master --prefer-dist | ||
``` | ||
|
||
## Setup | ||
|
||
### Create database | ||
|
||
```{.sh} | ||
bin/console chubbyphp:model:dbal:database:create | ||
``` | ||
|
||
### Create / Update schema | ||
|
||
```{.sh} | ||
bin/console chubbyphp:model:dbal:database:schema:update --dump --force | ||
``` | ||
|
||
[1]: https://github.com/chubbyphp/chubbyphp-api-http | ||
[2]: https://github.com/chubbyphp/chubbyphp-deserialization | ||
[3]: https://github.com/chubbyphp/chubbyphp-deserialization-model | ||
[4]: https://github.com/chubbyphp/chubbyphp-lazy | ||
[5]: https://github.com/chubbyphp/chubbyphp-model | ||
[6]: https://github.com/chubbyphp/chubbyphp-model-doctrine-dbal | ||
[7]: https://github.com/chubbyphp/chubbyphp-serialization | ||
[8]: https://github.com/chubbyphp/chubbyphp-translation | ||
[9]: https://github.com/chubbyphp/chubbyphp-validation | ||
[10]: https://github.com/chubbyphp/chubbyphp-validation-model | ||
[11]: https://github.com/Seldaek/monolog | ||
[12]: https://github.com/ramsey/uuid | ||
[13]: https://github.com/silexphp/Silex-Providers | ||
[14]: https://github.com/slimphp/Slim | ||
[15]: https://github.com/symfony/console | ||
[16]: https://github.com/symfony/yaml | ||
[17]: https://github.com/willdurand/negotiation | ||
[18]: https://github.com/vagrant-php/create-slim3-project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\ApiSkeleton\ApiHttp; | ||
|
||
use Chubbyphp\ApiHttp\Factory\ResponseFactoryInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Slim\Http\Response; | ||
|
||
final class ResponseFactory implements ResponseFactoryInterface | ||
{ | ||
/** | ||
* @param int $code | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function createResponse($code = 200): ResponseInterface | ||
{ | ||
return new Response($code); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\ApiSkeleton\Controller\Course; | ||
|
||
use Chubbyphp\ApiHttp\Manager\RequestManagerInterface; | ||
use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface; | ||
use Chubbyphp\Model\RepositoryInterface; | ||
use Chubbyphp\Validation\ValidatorInterface; | ||
use Psr\Http\Message\ServerRequestInterface as Request; | ||
use Psr\Http\Message\ResponseInterface as Response; | ||
use Chubbyphp\ApiSkeleton\Error\Error; | ||
use Chubbyphp\ApiSkeleton\Error\ErrorManager; | ||
use Chubbyphp\ApiSkeleton\Model\Course; | ||
|
||
final class CourseCreateController | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $defaultLanguage; | ||
|
||
/** | ||
* @var ErrorManager | ||
*/ | ||
private $errorManager; | ||
|
||
/** | ||
* @var RepositoryInterface | ||
*/ | ||
private $repository; | ||
|
||
/** | ||
* @var RequestManagerInterface | ||
*/ | ||
private $requestManager; | ||
|
||
/** | ||
* @var ResponseManagerInterface | ||
*/ | ||
private $responseManager; | ||
|
||
/** | ||
* @var ValidatorInterface | ||
*/ | ||
private $validator; | ||
|
||
/** | ||
* @param string $defaultLanguage | ||
* @param ErrorManager $errorManager | ||
* @param RepositoryInterface $repository | ||
* @param RequestManagerInterface $requestManager | ||
* @param ResponseManagerInterface $responseManager | ||
* @param ValidatorInterface $validator | ||
*/ | ||
public function __construct( | ||
string $defaultLanguage, | ||
ErrorManager $errorManager, | ||
RepositoryInterface $repository, | ||
RequestManagerInterface $requestManager, | ||
ResponseManagerInterface $responseManager, | ||
ValidatorInterface $validator | ||
) { | ||
$this->defaultLanguage = $defaultLanguage; | ||
$this->errorManager = $errorManager; | ||
$this->repository = $repository; | ||
$this->requestManager = $requestManager; | ||
$this->responseManager = $responseManager; | ||
$this->validator = $validator; | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* | ||
* @return Response | ||
*/ | ||
public function __invoke(Request $request): Response | ||
{ | ||
/** @var Course $course */ | ||
$course = $this->requestManager->getDataFromRequestBody($request, Course::class); | ||
|
||
if (null === $course) { | ||
return $this->responseManager->createResponse($request, 415); | ||
} | ||
|
||
if ([] !== $errors = $this->validator->validateObject($course)) { | ||
return $this->responseManager->createResponse( | ||
$request, | ||
422, | ||
$this->errorManager->createByValidationErrors( | ||
$errors, | ||
$this->requestManager->getAcceptLanguage($request, $this->defaultLanguage), | ||
Error::SCOPE_BODY, | ||
'course' | ||
) | ||
); | ||
} | ||
|
||
$this->repository->persist($course); | ||
|
||
return $this->responseManager->createResponse($request, 201, $course); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\ApiSkeleton\Controller\Course; | ||
|
||
use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface; | ||
use Chubbyphp\Model\RepositoryInterface; | ||
use Psr\Http\Message\ServerRequestInterface as Request; | ||
use Psr\Http\Message\ResponseInterface as Response; | ||
use Chubbyphp\ApiSkeleton\Error\ErrorManager; | ||
use Chubbyphp\ApiSkeleton\Model\Course; | ||
|
||
final class CourseDeleteController | ||
{ | ||
/** | ||
* @var ErrorManager | ||
*/ | ||
private $errorManager; | ||
|
||
/** | ||
* @var RepositoryInterface | ||
*/ | ||
private $repository; | ||
|
||
/** | ||
* @var ResponseManagerInterface | ||
*/ | ||
private $responseManager; | ||
|
||
/** | ||
* @param ErrorManager $errorManager | ||
* @param RepositoryInterface $repository | ||
* @param ResponseManagerInterface $responseManager | ||
*/ | ||
public function __construct( | ||
ErrorManager $errorManager, | ||
RepositoryInterface $repository, | ||
ResponseManagerInterface $responseManager | ||
) { | ||
$this->errorManager = $errorManager; | ||
$this->repository = $repository; | ||
$this->responseManager = $responseManager; | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* | ||
* @return Response | ||
*/ | ||
public function __invoke(Request $request): Response | ||
{ | ||
$id = $request->getAttribute('id'); | ||
|
||
/** @var Course $course */ | ||
$course = $this->repository->find($id); | ||
|
||
if (null === $course) { | ||
return $this->responseManager->createResponse( | ||
$request, | ||
404, | ||
$this->errorManager->createByMissingModel('course', ['id' => $id]) | ||
); | ||
} | ||
|
||
$this->repository->remove($course); | ||
|
||
return $this->responseManager->createResponse($request, 200); | ||
} | ||
} |
Oops, something went wrong.