Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slim4 #10

Merged
merged 5 commits into from Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Expand Up @@ -27,9 +27,10 @@ A simple skeleton to build api's based on the [slimframework][1].
* [monolog/monolog][13]: ^1.24
* [ocramius/proxy-manager][14]: ^2.1.1
* [ramsey/uuid][15]: ^3.8
* [slim/slim][16]: ^3.12.1
* [swagger-api/swagger-ui][17]: ^3.23
* [symfony/console][18]: ^4.3.1
* [slim/slim][16]: ^4.4
* [slim/psr7][17]: ^0.5
* [swagger-api/swagger-ui][18]: ^3.23
* [symfony/console][19]: ^4.3.1

## Environment

Expand Down Expand Up @@ -202,8 +203,9 @@ Dominik Zogg 2018
[14]: https://packagist.org/packages/ocramius/proxy-manager
[15]: https://packagist.org/packages/ramsey/uuid
[16]: https://packagist.org/packages/slim/slim
[17]: https://packagist.org/packages/swagger-api/swagger-ui
[18]: https://packagist.org/packages/symfony/console
[17]: https://packagist.org/packages/slim/psr7
[18]: https://packagist.org/packages/swagger-api/swagger-ui
[19]: https://packagist.org/packages/symfony/console

[40]: https://packagist.org/packages/chubbyphp/petstore

Expand Down
29 changes: 0 additions & 29 deletions app/ApiHttp/Factory/ResponseFactory.php

This file was deleted.

67 changes: 0 additions & 67 deletions app/ApiHttp/Factory/StreamFactory.php

This file was deleted.

3 changes: 1 addition & 2 deletions app/Config/AbstractConfig.php
Expand Up @@ -5,9 +5,8 @@
namespace App\Config;

use Chubbyphp\Config\ConfigInterface;
use Chubbyphp\Config\Slim\SlimSettingsInterface;

abstract class AbstractConfig implements ConfigInterface, SlimSettingsInterface
abstract class AbstractConfig implements ConfigInterface
{
/**
* @var string
Expand Down
17 changes: 4 additions & 13 deletions app/Config/DevConfig.php
Expand Up @@ -15,6 +15,8 @@ public function getConfig(): array
{
$config = parent::getConfig();

$config['debug'] = true;

$config['doctrine.dbal.db.options']['configuration']['cache.result']['type'] = 'array';

$config['doctrine.orm.em.options']['cache.hydration']['type'] = 'array';
Expand All @@ -23,20 +25,9 @@ public function getConfig(): array

$config['monolog']['level'] = Logger::DEBUG;

return $config;
}

/**
* @return array
*/
public function getSlimSettings(): array
{
$slimSettings = parent::getSlimSettings();

$slimSettings['displayErrorDetails'] = true;
$slimSettings['routerCacheFile'] = false;
$config['routerCacheFile'] = null;

return $slimSettings;
return $config;
}

/**
Expand Down
13 changes: 2 additions & 11 deletions app/Config/ProdConfig.php
Expand Up @@ -17,6 +17,7 @@ public function getConfig(): array
$logDir = $this->getLogDir();

return [
'debug' => false,
'doctrine.dbal.db.options' => [
'configuration' => [
'cache.result' => ['type' => 'apcu'],
Expand All @@ -42,17 +43,7 @@ public function getConfig(): array
'path' => $logDir.'/application.log',
'level' => Logger::NOTICE,
],
];
}

/**
* @return array
*/
public function getSlimSettings(): array
{
return [
'displayErrorDetails' => false,
'routerCacheFile' => $this->getCacheDir().'/routes.php',
'routerCacheFile' => $cacheDir.'/routes.php',
];
}

Expand Down
12 changes: 6 additions & 6 deletions app/Mapping/Serialization/AbstractCollectionMapping.php
Expand Up @@ -12,19 +12,19 @@
use Chubbyphp\Serialization\Mapping\NormalizationObjectMappingInterface;
use Chubbyphp\Serialization\Normalizer\CallbackLinkNormalizer;
use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface;
use Slim\Interfaces\RouterInterface;
use Slim\Interfaces\RouteParserInterface;

abstract class AbstractCollectionMapping implements NormalizationObjectMappingInterface
{
/**
* @var RouterInterface
* @var RouteParserInterface
*/
protected $router;

/**
* @param RouterInterface $router
* @param RouteParserInterface $router
*/
public function __construct(RouterInterface $router)
public function __construct(RouteParserInterface $router)
{
$this->router = $router;
}
Expand Down Expand Up @@ -69,7 +69,7 @@ public function getNormalizationLinkMappings(string $path): array
function (string $path, CollectionInterface $collection, NormalizerContextInterface $context) {
return LinkBuilder
::create(
$this->router->pathFor(
$this->router->urlFor(
$this->getListRouteName(),
[],
array_replace($context->getRequest()->getQueryParams(), [
Expand All @@ -85,7 +85,7 @@ function (string $path, CollectionInterface $collection, NormalizerContextInterf
)),
new NormalizationLinkMapping('create', [], new CallbackLinkNormalizer(
function () {
return LinkBuilder::create($this->router->pathFor($this->getCreateRouteName()))
return LinkBuilder::create($this->router->urlFor($this->getCreateRouteName()))
->setAttributes(['method' => 'POST'])
->getLink()
;
Expand Down
14 changes: 7 additions & 7 deletions app/Mapping/Serialization/AbstractModelMapping.php
Expand Up @@ -11,19 +11,19 @@
use Chubbyphp\Serialization\Mapping\NormalizationLinkMapping;
use Chubbyphp\Serialization\Mapping\NormalizationObjectMappingInterface;
use Chubbyphp\Serialization\Normalizer\CallbackLinkNormalizer;
use Slim\Interfaces\RouterInterface;
use Slim\Interfaces\RouteParserInterface;

abstract class AbstractModelMapping implements NormalizationObjectMappingInterface
{
/**
* @var RouterInterface
* @var RouteParserInterface
*/
protected $router;

/**
* @param RouterInterface $router
* @param RouteParserInterface $router
*/
public function __construct(RouterInterface $router)
public function __construct(RouteParserInterface $router)
{
$this->router = $router;
}
Expand Down Expand Up @@ -64,7 +64,7 @@ public function getNormalizationLinkMappings(string $path): array
function (string $path, ModelInterface $model) {
return LinkBuilder
::create(
$this->router->pathFor($this->getReadRouteName(), ['id' => $model->getId()])
$this->router->urlFor($this->getReadRouteName(), ['id' => $model->getId()])
)
->setAttributes(['method' => 'GET'])
->getLink()
Expand All @@ -75,7 +75,7 @@ function (string $path, ModelInterface $model) {
function (string $path, ModelInterface $model) {
return LinkBuilder
::create(
$this->router->pathFor($this->getUpdateRouteName(), ['id' => $model->getId()])
$this->router->urlFor($this->getUpdateRouteName(), ['id' => $model->getId()])
)
->setAttributes(['method' => 'PUT'])
->getLink()
Expand All @@ -86,7 +86,7 @@ function (string $path, ModelInterface $model) {
function (string $path, ModelInterface $model) {
return LinkBuilder
::create(
$this->router->pathFor($this->getDeleteRouteName(), ['id' => $model->getId()])
$this->router->urlFor($this->getDeleteRouteName(), ['id' => $model->getId()])
)
->setAttributes(['method' => 'DELETE'])
->getLink()
Expand Down
10 changes: 5 additions & 5 deletions app/RequestHandler/IndexRequestHandler.php
Expand Up @@ -8,7 +8,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Slim\Interfaces\RouterInterface;
use Slim\Interfaces\RouteParserInterface;

class IndexRequestHandler implements RequestHandlerInterface
{
Expand All @@ -18,17 +18,17 @@ class IndexRequestHandler implements RequestHandlerInterface
private $responseFactory;

/**
* @var RouterInterface
* @var RouteParserInterface
*/
private $router;

/**
* @param ResponseFactoryInterface $responseFactory
* @param RouterInterface $router
* @param RouteParserInterface $router
*/
public function __construct(
ResponseFactoryInterface $responseFactory,
RouterInterface $router
RouteParserInterface $router
) {
$this->responseFactory = $responseFactory;
$this->router = $router;
Expand All @@ -42,7 +42,7 @@ public function __construct(
public function handle(ServerRequestInterface $request): ResponseInterface
{
return $this->responseFactory->createResponse(302)
->withHeader('Location', $this->router->pathFor('swagger_index'))
->withHeader('Location', $this->router->urlFor('swagger_index'))
;
}
}
4 changes: 2 additions & 2 deletions app/ServiceProvider/ApiHttpServiceProvider.php
Expand Up @@ -5,10 +5,10 @@
namespace App\ServiceProvider;

use App\ApiHttp\Factory\InvalidParametersFactory;
use App\ApiHttp\Factory\ResponseFactory;
use App\ApiHttp\Factory\StreamFactory;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Slim\Psr7\Factory\ResponseFactory;
use Slim\Psr7\Factory\StreamFactory;

final class ApiHttpServiceProvider implements ServiceProviderInterface
{
Expand Down
49 changes: 49 additions & 0 deletions app/ServiceProvider/SlimServiceProvider.php
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace App\ServiceProvider;

use Pimple\Container;
use Pimple\Psr11\Container as PsrContainer;
use Pimple\ServiceProviderInterface;
use Slim\CallableResolver;
use Slim\Handlers\Strategies\RequestHandler;
use Slim\Routing\RouteCollector;

final class SlimServiceProvider implements ServiceProviderInterface
{
/**
* @param Container $container
*/
public function register(Container $container): void
{
$container[PsrContainer::class] = function () use ($container) {
return new PsrContainer($container);
};

$container[CallableResolver::class] = function () use ($container) {
return new CallableResolver($container[PsrContainer::class]);
};

$container[RouteCollector::class] = function () use ($container) {
$routeCollector = new RouteCollector(
$container['api-http.response.factory'],
$container[CallableResolver::class],
$container[PsrContainer::class]
);

$routeCollector->setDefaultInvocationStrategy(new RequestHandler(true));

if (null !== $routerCacheFile = $container['routerCacheFile']) {
$routeCollector->setCacheFile($routerCacheFile);
}

return $routeCollector;
};

$container['router'] = function () use ($container) {
return $container[RouteCollector::class]->getRouteParser();
};
}
}