* updated expressive version

This commit is contained in:
Danyi Dávid
2018-11-12 07:09:32 +01:00
parent 17ec066110
commit d77a3e4211
109 changed files with 5980 additions and 2606 deletions

View File

@@ -7,6 +7,7 @@
return [
'acl_config' => [
'unguarded_routes' => [
'home',
'api.auth.login',
'api.ping',
'api.xlsx',

View File

@@ -6,14 +6,14 @@ return [
'factories' => [
App\Command\InitializeFixtureCommand::class => App\Command\InitializeFixtureCommandFactory::class,
// App\Command\ConvertMaintenanceHashCommand::class => App\Command\ConvertMaintenanceHashCommandFactory::class,
// App\Command\MailTestCommand::class => App\Command\MailTestCommandFactory::class,
// App\Command\DebugMailCommand::class => App\Command\DebugMailCommandFactory::class,
],
],
'console' => [
'commands' => [
App\Command\InitializeFixtureCommand::class,
// App\Command\ConvertMaintenanceHashCommand::class,
// App\Command\MailTestCommand::class,
// App\Command\DebugMailCommand::class,
],
],
];

View File

@@ -1,10 +1,6 @@
<?php
use Zend\Expressive\Application;
use Zend\Expressive\Container;
use Zend\Expressive\Delegate;
use Zend\Expressive\Helper;
use Zend\Expressive\Middleware;
declare(strict_types=1);
return [
// Provides application-wide services.
@@ -14,30 +10,19 @@ return [
// Use 'aliases' to alias a service name to another service. The
// key is the alias name, the value is the service to which it points.
'aliases' => [
'Zend\Expressive\Delegate\DefaultDelegate' => Delegate\NotFoundDelegate::class,
// Fully\Qualified\ClassOrInterfaceName::class => Fully\Qualified\ClassName::class,
],
// Use 'invokables' for constructor-less services, or services that do
// not require arguments to the constructor. Map a service name to the
// class name.
'invokables' => [
// Fully\Qualified\InterfaceName::class => Fully\Qualified\ClassName::class,
Helper\ServerUrlHelper::class => Helper\ServerUrlHelper::class,
],
// Use 'factories' for services provided by callbacks/factory classes.
'factories' => [
Application::class => Container\ApplicationFactory::class,
Delegate\NotFoundDelegate::class => Container\NotFoundDelegateFactory::class,
Helper\ServerUrlMiddleware::class => Helper\ServerUrlMiddlewareFactory::class,
Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
Helper\UrlHelperMiddleware::class => Helper\UrlHelperMiddlewareFactory::class,
Zend\Stratigility\Middleware\ErrorHandler::class => Container\ErrorHandlerFactory::class,
Middleware\ErrorResponseGenerator::class => Container\ErrorResponseGeneratorFactory::class,
Middleware\NotFoundHandler::class => Container\NotFoundHandlerFactory::class,
Slim\Middleware\JwtAuthentication::class => App\Middleware\JwtAuthenticationFactory::class,
Tuupola\Middleware\Cors::class => App\Middleware\CorsMiddlewareFactory::class,
// Fully\Qualified\ClassName::class => Fully\Qualified\FactoryName::class,
App\Middleware\RouteAuthorization::class => App\Middleware\RouteAuthorizationFactory::class,
Tuupola\Middleware\JwtAuthentication::class => App\Middleware\JwtAuthenticationFactory::class,
],
],
];

View File

@@ -1,5 +1,4 @@
<?php
/**
* Development-only configuration.
*
@@ -10,6 +9,8 @@
* `composer development-enable`.
*/
declare(strict_types=1);
use Zend\Expressive\Container;
use Zend\Expressive\Middleware\ErrorResponseGenerator;

View File

@@ -1,12 +1,6 @@
<?php
return [
'dependencies' => [
'factories' => [
'doctrine.entity_manager.orm_default' => ContainerInteropDoctrine\EntityManagerFactory::class,
'doctrine.hydrator' => App\Hydrator\DoctrineObjectFactory::class,
],
],
'doctrine' => [
'driver' => [
'orm_default' => [

View File

@@ -1,12 +0,0 @@
<?php
use Zend\Expressive\Router\FastRouteRouter;
use Zend\Expressive\Router\RouterInterface;
return [
'dependencies' => [
'invokables' => [
RouterInterface::class => FastRouteRouter::class,
],
],
];

View File

@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
use Zend\ConfigAggregator\ConfigAggregator;
return [
@@ -13,10 +15,6 @@ return [
'debug' => false,
'zend-expressive' => [
// Enable programmatic pipeline: Any `middleware_pipeline` or `routes`
// configuration will be ignored when creating the `Application` instance.
'programmatic_pipeline' => true,
// Provide templates for the error handling middleware to use when
// generating responses.
'error_handler' => [

View File

@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
use Zend\ConfigAggregator\ArrayProvider;
use Zend\ConfigAggregator\ConfigAggregator;
use Zend\ConfigAggregator\PhpFileProvider;
@@ -11,15 +13,22 @@ $cacheConfig = [
];
$aggregator = new ConfigAggregator([
\Zend\Cache\ConfigProvider::class,
\Zend\Expressive\ConfigProvider::class,
\Zend\Expressive\Helper\ConfigProvider::class,
\Zend\Expressive\Router\FastRouteRouter\ConfigProvider::class,
\Zend\Expressive\Router\ConfigProvider::class,
\Zend\HttpHandlerRunner\ConfigProvider::class,
\Zend\Hydrator\ConfigProvider::class,
\Zend\Mail\ConfigProvider::class,
\Zend\Validator\ConfigProvider::class,
\Zend\Cache\ConfigProvider::class,
\Zend\Hydrator\ConfigProvider::class,
// Include cache configuration
new ArrayProvider($cacheConfig),
// Default App module config
App\ConfigProvider::class,
ApiLibs\ConfigProvider::class,
DoctrineExpressiveModule\ConfigProvider::class,
// Load application config in a pre-defined order in such a way that local settings
// overwrite global settings. (Loaded as first to last):
@@ -27,10 +36,10 @@ $aggregator = new ConfigAggregator([
// - `*.global.php`
// - `local.php`
// - `*.local.php`
new PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'),
new PhpFileProvider(realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php'),
// Load development config if it exists
new PhpFileProvider('config/development.config.php'),
new PhpFileProvider(realpath(__DIR__) . '/development.config.php'),
], $cacheConfig['config_cache_path']);
return $aggregator->getMergedConfig();

View File

@@ -1,16 +1,14 @@
<?php
use Zend\ServiceManager\Config;
declare(strict_types=1);
use Zend\ServiceManager\ServiceManager;
// Load configuration
$config = require __DIR__ . '/config.php';
$dependencies = $config['dependencies'];
$dependencies['services']['config'] = $config;
// Build container
$container = new ServiceManager();
(new Config($config['dependencies']))->configureServiceManager($container);
// Inject config
$container->setService('config', $config);
return $container;
return new ServiceManager($dependencies);

View File

@@ -1,5 +1,4 @@
<?php
/**
* File required to allow enablement of development mode.
*
@@ -21,6 +20,8 @@
* - Configuration caching is _disabled_.
*/
declare(strict_types=1);
use Zend\ConfigAggregator\ConfigAggregator;
return [

View File

@@ -1,58 +1,81 @@
<?php
declare(strict_types=1);
use Psr\Container\ContainerInterface;
use Tuupola\Middleware\CorsMiddleware;
use Zend\Expressive\Application;
use Zend\Expressive\Handler\NotFoundHandler;
use Zend\Expressive\Helper\ServerUrlMiddleware;
use Zend\Expressive\Helper\UrlHelperMiddleware;
use Zend\Expressive\Middleware\ImplicitHeadMiddleware;
use Zend\Expressive\Middleware\ImplicitOptionsMiddleware;
use Zend\Expressive\Middleware\NotFoundHandler;
use Zend\Expressive\MiddlewareFactory;
use Zend\Expressive\Router\Middleware\DispatchMiddleware;
use Zend\Expressive\Router\Middleware\ImplicitHeadMiddleware;
use Zend\Expressive\Router\Middleware\MethodNotAllowedMiddleware;
use Zend\Expressive\Router\Middleware\RouteMiddleware;
use Zend\Stratigility\Middleware\ErrorHandler;
/**
* Setup middleware pipeline:
*/
return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container) : void {
// The error handler should be the first (most outer) middleware to catch
// all Exceptions.
$app->pipe(ErrorHandler::class);
//$app->pipe(LosMiddleware\BasePath\BasePathMiddleware::class);
$app->pipe(ServerUrlMiddleware::class);
// The error handler should be the first (most outer) middleware to catch
// all Exceptions.
$app->pipe(Tuupola\Middleware\Cors::class);
$app->pipe(ErrorHandler::class);
$app->pipe(ServerUrlMiddleware::class);
// Pipe more middleware here that you want to execute on every request:
// - bootstrapping
// - pre-conditions
// - modifications to outgoing responses
//
// Piped Middleware may be either callables or service names. Middleware may
// also be passed as an array; each item in the array must resolve to
// middleware eventually (i.e., callable or service name).
//
// Middleware can be attached to specific paths, allowing you to mix and match
// applications under a common domain. The handlers in each middleware
// attached this way will see a URI with the matched path segment removed.
//
// i.e., path of "/api/member/profile" only passes "/member/profile" to $apiMiddleware
// - $app->pipe('/api', $apiMiddleware);
// - $app->pipe('/docs', $apiDocMiddleware);
// - $app->pipe('/files', $filesMiddleware);
// Pipe more middleware here that you want to execute on every request:
// - bootstrapping
// - pre-conditions
// - modifications to outgoing responses
//
// Piped Middleware may be either callables or service names. Middleware may
// also be passed as an array; each item in the array must resolve to
// middleware eventually (i.e., callable or service name).
//
// Middleware can be attached to specific paths, allowing you to mix and match
// applications under a common domain. The handlers in each middleware
// attached this way will see a URI with the MATCHED PATH SEGMENT REMOVED!!!
//
// - $app->pipe('/api', $apiMiddleware);
// - $app->pipe('/docs', $apiDocMiddleware);
// - $app->pipe('/files', $filesMiddleware);
// Register the routing middleware in the middleware pipeline
$app->pipeRoutingMiddleware();
$app->pipe(ImplicitHeadMiddleware::class);
$app->pipe(ImplicitOptionsMiddleware::class);
$app->pipe(UrlHelperMiddleware::class);
// Register the routing middleware in the middleware pipeline.
// This middleware registers the Zend\Expressive\Router\RouteResult request attribute.
$app->pipe(RouteMiddleware::class);
// Add more middleware here that needs to introspect the routing results; this
// might include:
//
// - route-based authentication
// - route-based validation
// - etc.
$app->pipe(Slim\Middleware\JwtAuthentication::class);
$app->pipe(App\Middleware\RouteAuthorization::class);
// The following handle routing failures for common conditions:
// - HEAD request but no routes answer that method
// - OPTIONS request but no routes answer that method
// - method not allowed
// Order here matters; the MethodNotAllowedMiddleware should be placed
// after the Implicit*Middleware.
$app->pipe(ImplicitHeadMiddleware::class);
$app->pipe(CorsMiddleware::class);
$app->pipe(MethodNotAllowedMiddleware::class);
// Register the dispatch middleware in the middleware pipeline
$app->pipeDispatchMiddleware();
// Seed the UrlHelper with the routing results:
$app->pipe(UrlHelperMiddleware::class);
// At this point, if no Response is return by any middleware, the
// NotFoundHandler kicks in; alternately, you can provide other fallback
// middleware to execute.
$app->pipe(NotFoundHandler::class);
// Add more middleware here that needs to introspect the routing results; this
// might include:
//
// - route-based authentication
// - route-based validation
// - etc.
// Register the dispatch middleware in the middleware pipeline
$app->pipe(Tuupola\Middleware\JwtAuthentication::class);
$app->pipe(App\Middleware\RouteAuthorization::class);
$app->pipe(DispatchMiddleware::class);
// At this point, if no Response is returned by any middleware, the
// NotFoundHandler kicks in; alternately, you can provide other fallback
// middleware to execute.
$app->pipe(NotFoundHandler::class);
};

View File

@@ -1,60 +1,72 @@
<?php
declare(strict_types=1);
use Psr\Container\ContainerInterface;
use Zend\Expressive\Application;
use Zend\Expressive\MiddlewareFactory;
/**
* Setup routes with a single request method:
*
* $app->get('/', App\Action\HomePageAction::class, 'home');
* $app->post('/album', App\Action\AlbumCreateAction::class, 'album.create');
* $app->put('/album/:id', App\Action\AlbumUpdateAction::class, 'album.put');
* $app->patch('/album/:id', App\Action\AlbumUpdateAction::class, 'album.patch');
* $app->delete('/album/:id', App\Action\AlbumDeleteAction::class, 'album.delete');
* $app->get('/', App\Handler\HomePageHandler::class, 'home');
* $app->post('/album', App\Handler\AlbumCreateHandler::class, 'album.create');
* $app->put('/album/:id', App\Handler\AlbumUpdateHandler::class, 'album.put');
* $app->patch('/album/:id', App\Handler\AlbumUpdateHandler::class, 'album.patch');
* $app->delete('/album/:id', App\Handler\AlbumDeleteHandler::class, 'album.delete');
*
* Or with multiple request methods:
*
* $app->route('/contact', App\Action\ContactAction::class, ['GET', 'POST', ...], 'contact');
* $app->route('/contact', App\Handler\ContactHandler::class, ['GET', 'POST', ...], 'contact');
*
* Or handling all request methods:
*
* $app->route('/contact', App\Action\ContactAction::class)->setName('contact');
* $app->route('/contact', App\Handler\ContactHandler::class)->setName('contact');
*
* or:
*
* $app->route(
* '/contact',
* App\Action\ContactAction::class,
* App\Handler\ContactHandler::class,
* Zend\Expressive\Router\Route::HTTP_METHOD_ANY,
* 'contact'
* );
*/
return function (
Application $app,
MiddlewareFactory $factory,
ContainerInterface $container
) : void {
$app->get('/', App\Handler\PingHandler::class, 'home');
$app->get('/api/ping', App\Handler\PingHandler::class, 'api.ping');
$app->get('/', App\Action\PingAction::class, 'home');
$app->get('/api/ping', App\Action\PingAction::class, 'api.ping');
$app->get('/api/maintenance/upcoming', App\Handler\MaintenanceUpcomingHandler::class, 'api.maintenance.upcoming');
$app->route('/api/maintenance[/{id:\w+}]', App\Handler\MaintenanceHandler::class, ['GET', 'OPTIONS'], 'api.maintenance');
$app->route('/api/maintenance/{id:\w+}', App\Handler\MaintenanceHandler::class, ['PUT'], 'api.maintenance.put');
$app->get('/api/maintenance/upcoming', App\Action\MaintenanceUpcomingAction::class, 'api.maintenance.upcoming');
$app->route('/api/maintenance[/{id:\w+}]', App\Action\MaintenanceAction::class, ['GET', 'OPTIONS'], 'api.maintenance');
$app->route('/api/maintenance/{id:\w+}', App\Action\MaintenanceAction::class, ['PUT'], 'api.maintenance.put');
// authentication and user management
$app->route('/api/auth/login', App\Handler\Auth\AuthHandler::class, ['POST', 'OPTIONS'], 'api.auth.login');
$app->route('/api/auth/renew', App\Handler\Auth\AuthHandler::class, ['GET', 'OPTIONS'], 'api.auth.renew');
$app->route('/api/user[/{id:\d+}]', App\Handler\User\UserHandler::class, ['GET', 'PUT', 'OPTIONS'], 'api.user.profile');
$app->route('/api/user/password', App\Handler\User\PasswordHandler::class, ['POST', 'OPTIONS'], 'api.user.password');
// authentication and user management
$app->route('/api/auth/login', App\Action\Auth\AuthAction::class, ['POST', 'OPTIONS'], 'api.auth.login');
$app->route('/api/auth/renew', App\Action\Auth\AuthAction::class, ['GET', 'OPTIONS'], 'api.auth.renew');
$app->route('/api/user[/{id:\d+}]', App\Action\User\UserAction::class, ['GET', 'PUT', 'OPTIONS'], 'api.user.profile');
$app->route('/api/user/password', App\Action\User\PasswordAction::class, ['POST', 'OPTIONS'], 'api.user.password');
// fault management
$app->route('/api/fault[/{id:\d+}]', App\Handler\Fault\FaultHandler::class, ['GET', 'OPTIONS'], 'api.fault.get'); // list/show
$app->post('/api/fault', App\Handler\Fault\FaultHandler::class, 'api.fault.post'); // create
$app->put('/api/fault/{id:\d+}', App\Handler\Fault\FaultHandler::class, 'api.fault.put'); // update
$app->delete('/api/fault/{id:\d+}', App\Handler\Fault\FaultHandler::class, 'api.fault.delete');
// fault management
$app->route('/api/fault[/{id:\d+}]', App\Action\Fault\FaultAction::class, ['GET', 'OPTIONS'], 'api.fault.get'); // list/show
$app->post('/api/fault', App\Action\Fault\FaultAction::class, 'api.fault.post'); // create
$app->put('/api/fault/{id:\d+}', App\Action\Fault\FaultAction::class, 'api.fault.put'); // update
$app->delete('/api/fault/{id:\d+}', App\Action\Fault\FaultAction::class, 'api.fault.delete');
$app->route('/api/fault-reject/{id:\d+}', App\Handler\Fault\FaultRejectHandler::class, ['POST', 'OPTIONS'], 'api.fault-reject.post');
$app->route('/api/fault-comment/{id:\d+}', App\Handler\Fault\FaultCommentHandler::class, ['POST', 'OPTIONS'], 'api.fault-comment.post');
$app->route('/api/fault-attachment/{id:\d+}/{type}', App\Handler\Fault\FaultAttachmentHandler::class, ['POST', 'OPTIONS'], 'api.fault-attachment.post');
$app->route('/show-attachment/{id:\d+}', App\Handler\Fault\FaultAttachmentHandler::class, ['GET', 'OPTIONS'], 'show-attachment');
$app->route('/api/fault-reject/{id:\d+}', App\Action\Fault\FaultRejectAction::class, ['POST', 'OPTIONS'], 'api.fault-reject.post');
$app->route('/api/fault-comment/{id:\d+}', App\Action\Fault\FaultCommentAction::class, ['POST', 'OPTIONS'], 'api.fault-comment.post');
$app->route('/api/fault-attachment/{id:\d+}/{type}', App\Action\Fault\FaultAttachmentAction::class, ['POST', 'OPTIONS'], 'api.fault-attachment.post');
$app->route('/show-attachment/{id:\d+}', App\Action\Fault\FaultAttachmentAction::class, ['GET', 'OPTIONS'], 'show-attachment');
$app->route('/hibajegy-pdf/{id:\d+}[/{filename}]', App\Handler\Pdf\GenerateWorksheetHandler::class, ['GET', 'OPTIONS'], 'hibajegy-pdf');
$app->route('/karbantartasjegy-pdf/{id:\w+}[/{filename}]', App\Handler\Pdf\GenerateMaintenanceSheetHandler::class, ['GET', 'OPTIONS'], 'karbantartasjegy-pdf');
$app->route('/hibajegy-pdf/{id:\d+}[/{filename}]', App\Action\Pdf\GenerateWorksheetAction::class, ['GET', 'OPTIONS'], 'hibajegy-pdf');
$app->route('/karbantartasjegy-pdf/{id:\w+}[/{filename}]', App\Action\Pdf\GenerateMaintenanceSheetAction::class, ['GET', 'OPTIONS'], 'karbantartasjegy-pdf');
// core data
$app->route('/api/error-category', App\Action\ErrorCategoryAction::class, ['GET', 'OPTIONS'], 'api.error-category.get'); // list/show
$app->route('/api/error-origin', App\Action\ErrorOriginAction::class, ['GET', 'OPTIONS'], 'api.error-origin.get'); // list/show
$app->route('/api/facility-location', App\Action\FacilityLocationAction::class, ['GET', 'OPTIONS'], 'api.facility-location.get'); // list/show
$app->route('/api/solution-time-interval', App\Action\SolutionTimeIntervalAction::class, ['GET', 'OPTIONS'], 'api.solution-time-interval.get'); // list/show
// core data
$app->route('/api/error-category', App\Handler\ErrorCategoryHandler::class, ['GET', 'OPTIONS'], 'api.error-category.get'); // list/show
$app->route('/api/error-origin', App\Handler\ErrorOriginHandler::class, ['GET', 'OPTIONS'], 'api.error-origin.get'); // list/show
$app->route('/api/facility-location', App\Handler\FacilityLocationHandler::class, ['GET', 'OPTIONS'], 'api.facility-location.get'); // list/show
$app->route('/api/solution-time-interval', App\Handler\SolutionTimeIntervalHandler::class, ['GET', 'OPTIONS'], 'api.solution-time-interval.get'); // list/show
};