* updated expressive version
This commit is contained in:
parent
17ec066110
commit
d77a3e4211
@ -4,49 +4,71 @@
|
||||
"type": "project",
|
||||
"homepage": "https://github.com/zendframework/zend-expressive-skeleton",
|
||||
"license": "BSD-3-Clause",
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"extra": {
|
||||
"zf": {
|
||||
"component-whitelist": [
|
||||
"zendframework/zend-expressive",
|
||||
"zendframework/zend-expressive-helpers",
|
||||
"zendframework/zend-expressive-router",
|
||||
"zendframework/zend-httphandlerrunner",
|
||||
"zendframework/zend-expressive-fastroute"
|
||||
]
|
||||
}
|
||||
},
|
||||
"support": {
|
||||
"issues": "https://github.com/zendframework/zend-expressive-skeleton/issues",
|
||||
"source": "https://github.com/zendframework/zend-expressive-skeleton",
|
||||
"rss": "https://github.com/zendframework/zend-expressive-skeleton/releases.atom",
|
||||
"slack": "https://zendframework-slack.herokuapp.com",
|
||||
"forum": "https://discourse.zendframework.com/c/questions/expressive"
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1",
|
||||
"dasprid/container-interop-doctrine": "^1.0",
|
||||
"doctrine/data-fixtures": "^1.2",
|
||||
"dasprid/container-interop-doctrine": "^1.1",
|
||||
"doctrine/data-fixtures": "~2.0",
|
||||
"gedmo/doctrine-extensions": "^2.4",
|
||||
"imagine/imagine": "^0.7.1",
|
||||
"lcobucci/jwt": "^3.2",
|
||||
"monolog/monolog": "^1.23",
|
||||
"imagine/imagine": "^1.1.0",
|
||||
"lcobucci/jwt": "^3.3",
|
||||
"monolog/monolog": "^1.24",
|
||||
"oro/doctrine-extensions": "^1.2",
|
||||
"phpoffice/phpexcel": "1.8.1",
|
||||
"psliwa/php-pdf": "^1.2",
|
||||
"roave/security-advisories": "dev-master",
|
||||
"symfony/yaml": "^3.3",
|
||||
"tuupola/cors-middleware": "^0.5.2",
|
||||
"tuupola/slim-jwt-auth": "^2.3",
|
||||
"zendframework/zend-component-installer": "^1.0",
|
||||
"symfony/yaml": "^4.1",
|
||||
"tuupola/cors-middleware": "^0.9.1",
|
||||
"tuupola/slim-jwt-auth": "^3.1.1",
|
||||
"zendframework/zend-component-installer": "^2.1.1",
|
||||
"zendframework/zend-config": "^3.1",
|
||||
"zendframework/zend-config-aggregator": "^1.0",
|
||||
"zendframework/zend-crypt": "^3.2",
|
||||
"zendframework/zend-expressive": "^2.0.2",
|
||||
"zendframework/zend-expressive-fastroute": "^2.0",
|
||||
"zendframework/zend-expressive-helpers": "^4.0",
|
||||
"zendframework/zend-hydrator": "^2.2",
|
||||
"zendframework/zend-json": "^3.0",
|
||||
"zendframework/zend-mail": "^2.8",
|
||||
"zendframework/zend-permissions-rbac": "^2.5",
|
||||
"zendframework/zend-diactoros": "^1.7.1 || ^2.0",
|
||||
"zendframework/zend-expressive": "^3.0.1",
|
||||
"zendframework/zend-expressive-fastroute": "^3.0",
|
||||
"zendframework/zend-expressive-helpers": "^5.0",
|
||||
"zendframework/zend-hydrator": "^2.3",
|
||||
"zendframework/zend-json": "^3.1",
|
||||
"zendframework/zend-mail": "^2.10.0",
|
||||
"zendframework/zend-permissions-rbac": "^3.0.0",
|
||||
"zendframework/zend-servicemanager": "^3.3",
|
||||
"zendframework/zend-stdlib": "^3.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^6.0.8 || ^5.7.15",
|
||||
"squizlabs/php_codesniffer": "^2.8.1",
|
||||
"phpunit/phpunit": "^7.0.1",
|
||||
"roave/security-advisories": "dev-master",
|
||||
"squizlabs/php_codesniffer": "^2.9.1",
|
||||
"zendframework/zend-expressive-tooling": "^1.0",
|
||||
"zfcampus/zf-development-mode": "^3.1",
|
||||
"filp/whoops": "^2.1.7"
|
||||
"filp/whoops": "^2.1.12"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "src/App/"
|
||||
"App\\": "src/App/",
|
||||
"ApiLibs\\": "src/ApiLibs/",
|
||||
"DoctrineExpressiveModule\\": "src/DoctrineExpressiveModule/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
|
||||
2842
composer.lock
generated
2842
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,7 @@
|
||||
return [
|
||||
'acl_config' => [
|
||||
'unguarded_routes' => [
|
||||
'home',
|
||||
'api.auth.login',
|
||||
'api.ping',
|
||||
'api.xlsx',
|
||||
|
||||
@ -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,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@ -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,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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' => [
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Zend\Expressive\Router\FastRouteRouter;
|
||||
use Zend\Expressive\Router\RouterInterface;
|
||||
|
||||
return [
|
||||
'dependencies' => [
|
||||
'invokables' => [
|
||||
RouterInterface::class => FastRouteRouter::class,
|
||||
],
|
||||
],
|
||||
];
|
||||
@ -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' => [
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 [
|
||||
|
||||
@ -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);
|
||||
};
|
||||
|
||||
@ -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
|
||||
};
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// Delegate static file requests back to the PHP built-in webserver
|
||||
if (php_sapi_name() === 'cli-server'
|
||||
&& is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))
|
||||
) {
|
||||
if (PHP_SAPI === 'cli-server' && $_SERVER['SCRIPT_FILENAME'] !== __FILE__) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -13,17 +13,18 @@ require 'vendor/autoload.php';
|
||||
/**
|
||||
* Self-called anonymous function that creates its own scope and keep the global namespace clean.
|
||||
*/
|
||||
call_user_func(function () {
|
||||
/** @var \Interop\Container\ContainerInterface $container */
|
||||
(function () {
|
||||
/** @var \Psr\Container\ContainerInterface $container */
|
||||
$container = require 'config/container.php';
|
||||
|
||||
/** @var \Zend\Expressive\Application $app */
|
||||
$app = $container->get(\Zend\Expressive\Application::class);
|
||||
$factory = $container->get(\Zend\Expressive\MiddlewareFactory::class);
|
||||
|
||||
// Import programmatic/declarative middleware pipeline and routing
|
||||
// Execute programmatic/declarative middleware pipeline and routing
|
||||
// configuration statements
|
||||
require 'config/pipeline.php';
|
||||
require 'config/routes.php';
|
||||
(require 'config/pipeline.php')($app, $factory, $container);
|
||||
(require 'config/routes.php')($app, $factory, $container);
|
||||
|
||||
$app->run();
|
||||
});
|
||||
})();
|
||||
|
||||
166
src/ApiLibs/AbstractHandler/CrudHandler.php
Normal file
166
src/ApiLibs/AbstractHandler/CrudHandler.php
Normal file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ApiLibs\AbstractHandler;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Json\Json;
|
||||
|
||||
abstract class CrudHandler implements RequestHandlerInterface
|
||||
{
|
||||
const IDENTIFIER_NAME = 'id';
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$requestMethod = strtoupper($request->getMethod());
|
||||
$id = $request->getAttribute(static::IDENTIFIER_NAME);
|
||||
|
||||
switch ($requestMethod) {
|
||||
case 'GET':
|
||||
return isset($id)
|
||||
? $this->get($request)
|
||||
: $this->getList($request);
|
||||
case 'POST':
|
||||
return $this->create($request);
|
||||
case 'PUT':
|
||||
return $this->update($request);
|
||||
case 'DELETE':
|
||||
return isset($id)
|
||||
? $this->delete($request)
|
||||
: $this->deleteList($request);
|
||||
case 'HEAD':
|
||||
return $this->head($request);
|
||||
case 'OPTIONS':
|
||||
return $this->options($request);
|
||||
case 'PATCH':
|
||||
return $this->patch($request);
|
||||
default:
|
||||
return $this->notAllowed();
|
||||
}
|
||||
}
|
||||
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->notAllowed();
|
||||
}
|
||||
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->notAllowed();
|
||||
}
|
||||
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->notAllowed();
|
||||
}
|
||||
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->notAllowed();
|
||||
}
|
||||
|
||||
public function delete(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->notAllowed();
|
||||
}
|
||||
|
||||
public function deleteList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->notAllowed();
|
||||
}
|
||||
|
||||
public function head(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->notAllowed();
|
||||
}
|
||||
|
||||
public function options(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new EmptyResponse(200);
|
||||
}
|
||||
|
||||
public function patch(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->notAllowed();
|
||||
}
|
||||
|
||||
final public function notAllowed(): ResponseInterface
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
final protected function createResponse($data, $status = 200): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($data, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return array|object
|
||||
*/
|
||||
public function getRequestData(ServerRequestInterface $request)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
|
||||
if (!empty($body)) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
return $this->parseRequestData(
|
||||
$request->getBody()->getContents(),
|
||||
$request->getHeaderLine('content-type')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $contentType
|
||||
* @return mixed
|
||||
*/
|
||||
private function parseRequestData($input, $contentType)
|
||||
{
|
||||
$contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType);
|
||||
$parser = $this->returnParserContentType($contentTypeParts[0]);
|
||||
|
||||
return $parser($input);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $contentType
|
||||
* @return callable
|
||||
*/
|
||||
private function returnParserContentType(string $contentType): callable
|
||||
{
|
||||
if ($contentType === 'application/x-www-form-urlencoded') {
|
||||
return function ($input) {
|
||||
parse_str($input, $data);
|
||||
return $data;
|
||||
};
|
||||
} elseif ($contentType === 'application/json') {
|
||||
return function ($input) {
|
||||
$jsonDecoder = new Json();
|
||||
try {
|
||||
return $jsonDecoder->decode($input, Json::TYPE_ARRAY);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
} elseif ($contentType === 'multipart/form-data') {
|
||||
return function ($input) {
|
||||
return $input;
|
||||
};
|
||||
}
|
||||
|
||||
return function ($input) {
|
||||
return $input;
|
||||
};
|
||||
}
|
||||
}
|
||||
43
src/ApiLibs/ConfigProvider.php
Normal file
43
src/ApiLibs/ConfigProvider.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ApiLibs;
|
||||
|
||||
/**
|
||||
* The configuration provider for the App module
|
||||
*
|
||||
* @see https://docs.zendframework.com/zend-component-installer/
|
||||
*/
|
||||
class ConfigProvider
|
||||
{
|
||||
/**
|
||||
* Returns the configuration array
|
||||
*
|
||||
* To add a bit of a structure, each section is defined in a separate
|
||||
* method which returns an array with its configuration.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __invoke()
|
||||
{
|
||||
return [
|
||||
'dependencies' => $this->getDependencies(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the container dependencies
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDependencies()
|
||||
{
|
||||
return [
|
||||
'invokables' => [],
|
||||
'factories' => [
|
||||
\Tuupola\Middleware\CorsMiddleware::class => Middleware\CorsMiddlewareFactory::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
23
src/ApiLibs/Middleware/CorsMiddlewareFactory.php
Normal file
23
src/ApiLibs/Middleware/CorsMiddlewareFactory.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ApiLibs\Middleware;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Tuupola\Middleware\CorsMiddleware;
|
||||
|
||||
class CorsMiddlewareFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container): CorsMiddleware
|
||||
{
|
||||
return new CorsMiddleware([
|
||||
"headers.allow" => [
|
||||
"Authorization",
|
||||
"If-Match",
|
||||
"If-Unmodified-Since",
|
||||
"Content-type",
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -1,182 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Json\Json;
|
||||
|
||||
abstract class AbstractCrudAction implements ServerMiddlewareInterface
|
||||
{
|
||||
const IDENTIFIER_NAME = 'id';
|
||||
const CORS_ALLOW_HEADERS = [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Modified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
];
|
||||
|
||||
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$requestMethod = strtoupper($request->getMethod());
|
||||
$id = $request->getAttribute(static::IDENTIFIER_NAME);
|
||||
|
||||
switch ($requestMethod) {
|
||||
case 'GET':
|
||||
return isset($id)
|
||||
? $this->get($request, $delegate)
|
||||
: $this->getList($request, $delegate);
|
||||
case 'POST':
|
||||
return $this->create($request, $delegate);
|
||||
case 'PUT':
|
||||
return $this->update($request, $delegate);
|
||||
case 'DELETE':
|
||||
return isset($id)
|
||||
? $this->delete($request, $delegate)
|
||||
: $this->deleteList($request, $delegate);
|
||||
case 'HEAD':
|
||||
return $this->head($request, $delegate);
|
||||
case 'OPTIONS':
|
||||
return $this->options($request, $delegate);
|
||||
case 'PATCH':
|
||||
return $this->patch($request, $delegate);
|
||||
default:
|
||||
return $delegate->process($request);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function delete(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function deleteList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function head(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function patch(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
final protected function createResponse($data, $status = 200)
|
||||
{
|
||||
return new JsonResponse($data, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return array|object
|
||||
*/
|
||||
public function getRequestData(ServerRequestInterface $request)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
|
||||
if (!empty($body)) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
return $this->parseRequestData(
|
||||
$request->getBody()->getContents(),
|
||||
$request->getHeaderLine('content-type')
|
||||
);
|
||||
}
|
||||
|
||||
protected function withCorsHeaders(ResponseInterface $response, iterable $methods = [])
|
||||
{
|
||||
if ($methods) {
|
||||
$methodsHeader = implode(',', $methods);
|
||||
$response = $response->withHeader('Accept', $methodsHeader)
|
||||
->withHeader('Access-Control-Allow-Methods', $methodsHeader);
|
||||
}
|
||||
return $response
|
||||
->withHeader('Access-Control-Allow-Origin', '*')
|
||||
->withHeader('Access-Control-Allow-Headers', implode(",", self::CORS_ALLOW_HEADERS));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $contentType
|
||||
* @return mixed
|
||||
*/
|
||||
private function parseRequestData($input, $contentType)
|
||||
{
|
||||
$contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType);
|
||||
$parser = $this->returnParserContentType($contentTypeParts[0]);
|
||||
|
||||
return $parser($input);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $contentType
|
||||
* @return callable
|
||||
*/
|
||||
private function returnParserContentType(string $contentType)
|
||||
{
|
||||
if ($contentType === 'application/x-www-form-urlencoded') {
|
||||
return function ($input) {
|
||||
parse_str($input, $data);
|
||||
return $data;
|
||||
};
|
||||
} elseif ($contentType === 'application/json') {
|
||||
return function ($input) {
|
||||
$jsonDecoder = new Json();
|
||||
try {
|
||||
return $jsonDecoder->decode($input, Json::TYPE_ARRAY);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
} elseif ($contentType === 'multipart/form-data') {
|
||||
return function ($input) {
|
||||
return $input;
|
||||
};
|
||||
}
|
||||
|
||||
return function ($input) {
|
||||
return $input;
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Auth;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\AuthService;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class AuthAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var AuthService
|
||||
*/
|
||||
private $authService;
|
||||
|
||||
public function __construct(AuthService $authService)
|
||||
{
|
||||
$this->authService = $authService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new auth token (login)
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$authData = $this->getRequestData($request);
|
||||
try {
|
||||
return new JsonCorsResponse($this->authService->authenticate($authData['login'], $authData['password']));
|
||||
} catch (NoResultException $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 403);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
try {
|
||||
$token = $request->getAttribute('token', false);
|
||||
return new JsonCorsResponse($this->authService->renewToken($token));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\ErrorCategoryService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class ErrorCategoryAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ErrorCategoryService
|
||||
*/
|
||||
private $errorCategoryService;
|
||||
|
||||
public function __construct(ErrorCategoryService $errorCategoryService)
|
||||
{
|
||||
$this->errorCategoryService = $errorCategoryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->errorCategoryService->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\ErrorOriginService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class ErrorOriginAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ErrorOriginService
|
||||
*/
|
||||
private $errorOriginService;
|
||||
|
||||
public function __construct(ErrorOriginService $errorOriginService)
|
||||
{
|
||||
$this->errorOriginService = $errorOriginService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->errorOriginService->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FacilityLocationService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FacilityLocationAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FacilityLocationService
|
||||
*/
|
||||
private $facilityLocationService;
|
||||
|
||||
public function __construct(FacilityLocationService $facilityLocationService)
|
||||
{
|
||||
$this->facilityLocationService = $facilityLocationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->facilityLocationService->getFacilityLocationListFlat());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,122 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
'PUT',
|
||||
'PATCH',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->faultManagerService->getFaultList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single fault
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
return new JsonCorsResponse($this->faultManagerService->getFault($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
$token = $request->getAttribute('token');
|
||||
return new JsonCorsResponse($this->faultManagerService->createFault($data, $token->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$token = $request->getAttribute('token');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->updateFault($id, $data, $token->uid));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a fault report (NYI)
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function delete(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
return new JsonCorsResponse($this->faultManagerService->deleteFault($id));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultCommentAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$jwt = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->addFaultComment($faultId, $data, $jwt->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultRejectAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$jwt = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->rejectFault($faultId, $data, $jwt->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS2ConfirmAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->confirmFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS3AcknowledgeAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->ackFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS4RepairedAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->repairFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS5AcceptedAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->acceptFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class MaintenanceAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var MaintenanceManagerService
|
||||
*/
|
||||
private $maintenanceManagerService;
|
||||
|
||||
public function __construct(MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->maintenanceManagerService = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->getMaintenanceList()->getValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse|\Zend\Diactoros\Response\JsonResponse
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->get($hash));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse|\Zend\Diactoros\Response\JsonResponse
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||
$data = $this->getRequestData($request);
|
||||
$jwt = $request->getAttribute('token');
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->update($hash, $data, $jwt->uid));
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class MaintenanceUpcomingAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var MaintenanceManagerService
|
||||
*/
|
||||
private $maintenanceManagerService;
|
||||
|
||||
public function __construct(MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->maintenanceManagerService = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->getUpcomingMaintenanceList()->getValues());
|
||||
}
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use App\Service\PdfService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\TextResponse;
|
||||
|
||||
class GenerateMaintenanceSheetAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var PdfService
|
||||
*/
|
||||
private $pdfService;
|
||||
|
||||
/**
|
||||
* @var MaintenanceManagerService
|
||||
*/
|
||||
private $maintenanceManager;
|
||||
|
||||
public function __construct(PdfService $pdfService, MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->pdfService = $pdfService;
|
||||
$this->maintenanceManager = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse|TextResponse|static
|
||||
* @throws \PHPPdf\Core\PHPPdf\Exception\Exception
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
try {
|
||||
return (new TextResponse($this->pdfService->getMaintenanceSheet($id)))
|
||||
->withHeader('Content-type', 'application/pdf');
|
||||
} catch (\Exception $e) {
|
||||
return new TextResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class PingAction implements ServerMiddlewareInterface
|
||||
{
|
||||
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return new JsonCorsResponse(['ack' => time()]);
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\SolutionTimeIntervalService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class SolutionTimeIntervalAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var SolutionTimeIntervalService
|
||||
*/
|
||||
private $solutionTimeIntervalService;
|
||||
|
||||
public function __construct(SolutionTimeIntervalService $facilityLocationService)
|
||||
{
|
||||
$this->solutionTimeIntervalService = $facilityLocationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->solutionTimeIntervalService->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\UserService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class PasswordAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var UserService
|
||||
*/
|
||||
private $userService;
|
||||
|
||||
public function __construct(UserService $userService)
|
||||
{
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$token = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->userService->changePassword($token->uid, $data['old'], $data['new']));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,93 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\UserService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class UserAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var UserService
|
||||
*/
|
||||
private $userService;
|
||||
|
||||
public function __construct(UserService $userService)
|
||||
{
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
try {
|
||||
return new JsonCorsResponse($this->userService->getList());
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
try {
|
||||
return new JsonCorsResponse($this->userService->get($id));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->userService->update($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,6 @@
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\DeviceGroup;
|
||||
use App\Entity\DeviceMaintenanceTask;
|
||||
use App\Entity\Maintenance;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
@ -37,6 +36,7 @@ class ConvertMaintenanceHashCommand extends Command
|
||||
* @param OutputInterface $output
|
||||
* @return int|null|void
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
@ -2,16 +2,14 @@
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\Mailer\MailerService;
|
||||
use App\Service\MailerService;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class MailTestCommand extends Command
|
||||
class DebugMailCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var MailerService
|
||||
*/
|
||||
/** @var MailerService */
|
||||
private $mailerService;
|
||||
|
||||
public function __construct(MailerService $mailerService)
|
||||
@ -2,15 +2,15 @@
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\Mailer\MailerService;
|
||||
use App\Service\MailerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class MailTestCommandFactory
|
||||
class DebugMailCommandFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var MailerService $mailerService */
|
||||
$mailerService = $container->get(MailerService::class);
|
||||
return new MailTestCommand($mailerService);
|
||||
return new DebugMailCommand($mailerService);
|
||||
}
|
||||
}
|
||||
@ -4,15 +4,12 @@ namespace App\Command;
|
||||
|
||||
use App\Service\FixtureLoaderService;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class InitializeFixtureCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var FixtureLoaderService
|
||||
*/
|
||||
/** @var FixtureLoaderService */
|
||||
private $fixtureLoaderService;
|
||||
|
||||
public function __construct(FixtureLoaderService $fixtureLoaderService)
|
||||
|
||||
@ -36,26 +36,26 @@ class ConfigProvider
|
||||
{
|
||||
return [
|
||||
'invokables' => [
|
||||
Action\PingAction::class => Action\PingAction::class,
|
||||
Handler\PingHandler::class => Handler\PingHandler::class,
|
||||
|
||||
],
|
||||
'factories' => [
|
||||
Action\MaintenanceAction::class => Action\MaintenanceFactory::class,
|
||||
Action\MaintenanceUpcomingAction::class => Action\MaintenanceUpcomingFactory::class,
|
||||
Handler\MaintenanceHandler::class => Handler\MaintenanceFactory::class,
|
||||
Handler\MaintenanceUpcomingHandler::class => Handler\MaintenanceUpcomingFactory::class,
|
||||
|
||||
Action\Auth\AuthAction::class => Action\Auth\AuthFactory::class,
|
||||
Action\User\UserAction::class => Action\User\UserFactory::class,
|
||||
Action\User\PasswordAction::class => Action\User\PasswordFactory::class,
|
||||
Action\Fault\FaultAction::class => Action\Fault\FaultFactory::class,
|
||||
Action\Fault\FaultAttachmentAction::class => Action\Fault\FaultAttachmentFactory::class,
|
||||
Action\Fault\FaultCommentAction::class => Action\Fault\FaultCommentFactory::class,
|
||||
Action\Fault\FaultRejectAction::class => Action\Fault\FaultRejectFactory::class,
|
||||
Action\ErrorOriginAction::class => Action\ErrorOriginFactory::class,
|
||||
Action\ErrorCategoryAction::class => Action\ErrorCategoryFactory::class,
|
||||
Action\FacilityLocationAction::class => Action\FacilityLocationFactory::class,
|
||||
Action\SolutionTimeIntervalAction::class => Action\SolutionTimeIntervalFactory::class,
|
||||
Action\Pdf\GenerateWorksheetAction::class => Action\Pdf\GenerateWorksheetFactory::class,
|
||||
Action\Pdf\GenerateMaintenanceSheetAction::class => Action\Pdf\GenerateMaintenanceSheetFactory::class,
|
||||
Handler\Auth\AuthHandler::class => Handler\Auth\AuthFactory::class,
|
||||
Handler\User\UserHandler::class => Handler\User\UserFactory::class,
|
||||
Handler\User\PasswordHandler::class => Handler\User\PasswordFactory::class,
|
||||
Handler\Fault\FaultHandler::class => Handler\Fault\FaultFactory::class,
|
||||
Handler\Fault\FaultAttachmentHandler::class => Handler\Fault\FaultAttachmentFactory::class,
|
||||
Handler\Fault\FaultCommentHandler::class => Handler\Fault\FaultCommentFactory::class,
|
||||
Handler\Fault\FaultRejectHandler::class => Handler\Fault\FaultRejectFactory::class,
|
||||
Handler\ErrorOriginHandler::class => Handler\ErrorOriginFactory::class,
|
||||
Handler\ErrorCategoryHandler::class => Handler\ErrorCategoryFactory::class,
|
||||
Handler\FacilityLocationHandler::class => Handler\FacilityLocationFactory::class,
|
||||
Handler\SolutionTimeIntervalHandler::class => Handler\SolutionTimeIntervalFactory::class,
|
||||
Handler\Pdf\GenerateWorksheetHandler::class => Handler\Pdf\GenerateWorksheetFactory::class,
|
||||
Handler\Pdf\GenerateMaintenanceSheetHandler::class => Handler\Pdf\GenerateMaintenanceSheetFactory::class,
|
||||
|
||||
Service\AuthService::class => Service\AuthServiceFactory::class,
|
||||
Service\UserService::class => Service\UserServiceFactory::class,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Auth;
|
||||
namespace App\Handler\Auth;
|
||||
|
||||
use App\Service\AuthService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -10,6 +10,6 @@ class AuthFactory
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(AuthService::class);
|
||||
return new AuthAction($faultManagerService);
|
||||
return new AuthHandler($faultManagerService);
|
||||
}
|
||||
}
|
||||
59
src/App/Handler/Auth/AuthHandler.php
Normal file
59
src/App/Handler/Auth/AuthHandler.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Auth;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\AuthService;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class AuthHandler extends CrudHandler
|
||||
{
|
||||
/** @var AuthService */
|
||||
private $authService;
|
||||
|
||||
public function __construct(AuthService $authService)
|
||||
{
|
||||
$this->authService = $authService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new auth token (login)
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$authData = $this->getRequestData($request);
|
||||
try {
|
||||
return new JsonResponse($this->authService->authenticate($authData['login'], $authData['password']));
|
||||
} catch (NoResultException $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 403);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$token = $request->getAttribute('token', false);
|
||||
return new JsonResponse($this->authService->renewToken($token));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\ErrorCategoryService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -11,6 +11,6 @@ class ErrorCategoryFactory
|
||||
{
|
||||
/** @var ErrorCategoryService $errorCategoryService */
|
||||
$errorCategoryService = $container->get(ErrorCategoryService::class);
|
||||
return new ErrorCategoryAction($errorCategoryService);
|
||||
return new ErrorCategoryHandler($errorCategoryService);
|
||||
}
|
||||
}
|
||||
30
src/App/Handler/ErrorCategoryHandler.php
Normal file
30
src/App/Handler/ErrorCategoryHandler.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\ErrorCategoryService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class ErrorCategoryHandler extends CrudHandler
|
||||
{
|
||||
/** @var ErrorCategoryService */
|
||||
private $errorCategoryService;
|
||||
|
||||
public function __construct(ErrorCategoryService $errorCategoryService)
|
||||
{
|
||||
$this->errorCategoryService = $errorCategoryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->errorCategoryService->getList());
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\ErrorOriginService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -11,6 +11,6 @@ class ErrorOriginFactory
|
||||
{
|
||||
/** @var ErrorOriginService $errorOriginService */
|
||||
$errorOriginService = $container->get(ErrorOriginService::class);
|
||||
return new ErrorOriginAction($errorOriginService);
|
||||
return new ErrorOriginHandler($errorOriginService);
|
||||
}
|
||||
}
|
||||
31
src/App/Handler/ErrorOriginHandler.php
Normal file
31
src/App/Handler/ErrorOriginHandler.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\ErrorOriginService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class ErrorOriginHandler extends CrudHandler
|
||||
{
|
||||
/** @var ErrorOriginService */
|
||||
private $errorOriginService;
|
||||
|
||||
public function __construct(ErrorOriginService $errorOriginService)
|
||||
{
|
||||
$this->errorOriginService = $errorOriginService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->errorOriginService->getList());
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\FacilityLocationService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -11,6 +11,6 @@ class FacilityLocationFactory
|
||||
{
|
||||
/** @var FacilityLocationService $facilityLocationService */
|
||||
$facilityLocationService = $container->get(FacilityLocationService::class);
|
||||
return new FacilityLocationAction($facilityLocationService);
|
||||
return new FacilityLocationHandler($facilityLocationService);
|
||||
}
|
||||
}
|
||||
31
src/App/Handler/FacilityLocationHandler.php
Normal file
31
src/App/Handler/FacilityLocationHandler.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FacilityLocationService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class FacilityLocationHandler extends CrudHandler
|
||||
{
|
||||
/** @var FacilityLocationService */
|
||||
private $facilityLocationService;
|
||||
|
||||
public function __construct(FacilityLocationService $facilityLocationService)
|
||||
{
|
||||
$this->facilityLocationService = $facilityLocationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->facilityLocationService->getFacilityLocationListFlat());
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use App\Service\FaultAttachmentService;
|
||||
use App\Service\FaultManagerService;
|
||||
@ -12,6 +12,6 @@ class FaultAttachmentFactory
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
$attachmentService = $container->get(FaultAttachmentService::class);
|
||||
return new FaultAttachmentAction($faultManagerService, $attachmentService);
|
||||
return new FaultAttachmentHandler($faultManagerService, $attachmentService);
|
||||
}
|
||||
}
|
||||
@ -1,52 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultAttachmentService;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
class FaultAttachmentAction extends AbstractCrudAction
|
||||
class FaultAttachmentHandler extends CrudHandler
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
/**
|
||||
* @var FaultAttachmentService
|
||||
*/
|
||||
/** @var FaultAttachmentService */
|
||||
private $attachmentService;
|
||||
|
||||
public function __construct(
|
||||
FaultManagerService $faultManagerService,
|
||||
FaultAttachmentService $attachmentService
|
||||
) {
|
||||
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
$this->attachmentService = $attachmentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$type = $request->getAttribute('type', 'file');
|
||||
@ -54,21 +41,22 @@ class FaultAttachmentAction extends AbstractCrudAction
|
||||
try {
|
||||
/** @var UploadedFileInterface[] $files */
|
||||
$files = $request->getUploadedFiles()['file'];
|
||||
return new JsonCorsResponse(
|
||||
return new JsonResponse(
|
||||
$this->attachmentService->createAttachments($faultId, $files, $token->uid, $type),
|
||||
201
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
return new JsonResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return Response
|
||||
* @return ResponseInterface
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
$attachment = $this->attachmentService->get($id);
|
||||
@ -89,16 +77,4 @@ class FaultAttachmentAction extends AbstractCrudAction
|
||||
// ->withHeader('Content-disposition', 'attachment;filename='.$attachment->getFileName())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -10,6 +10,6 @@ class FaultCommentFactory
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
return new FaultCommentAction($faultManagerService);
|
||||
return new FaultCommentHandler($faultManagerService);
|
||||
}
|
||||
}
|
||||
38
src/App/Handler/Fault/FaultCommentHandler.php
Normal file
38
src/App/Handler/Fault/FaultCommentHandler.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class FaultCommentHandler extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$jwt = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->addFaultComment($faultId, $data, $jwt->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -10,6 +10,6 @@ class FaultFactory
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
return new FaultAction($faultManagerService);
|
||||
return new FaultHandler($faultManagerService);
|
||||
}
|
||||
}
|
||||
97
src/App/Handler/Fault/FaultHandler.php
Normal file
97
src/App/Handler/Fault/FaultHandler.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class FaultHandler extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->faultManagerService->getFaultList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single fault
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
return new JsonResponse($this->faultManagerService->getFault($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
$token = $request->getAttribute('token');
|
||||
return new JsonResponse($this->faultManagerService->createFault($data, $token->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$token = $request->getAttribute('token');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->updateFault($id, $data, $token->uid));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a fault report (NYI)
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function delete(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
return new JsonResponse($this->faultManagerService->deleteFault($id));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -10,6 +10,6 @@ class FaultRejectFactory
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
return new FaultRejectAction($faultManagerService);
|
||||
return new FaultRejectHandler($faultManagerService);
|
||||
}
|
||||
}
|
||||
38
src/App/Handler/Fault/FaultRejectHandler.php
Normal file
38
src/App/Handler/Fault/FaultRejectHandler.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class FaultRejectHandler extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$jwt = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->rejectFault($faultId, $data, $jwt->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/App/Handler/Fault/X_FaultS2ConfirmAction.php
Normal file
37
src/App/Handler/Fault/X_FaultS2ConfirmAction.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class X_FaultS2ConfirmAction extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->confirmFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/App/Handler/Fault/X_FaultS3AcknowledgeAction.php
Normal file
37
src/App/Handler/Fault/X_FaultS3AcknowledgeAction.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class X_FaultS3AcknowledgeAction extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->ackFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/App/Handler/Fault/X_FaultS4RepairedAction.php
Normal file
37
src/App/Handler/Fault/X_FaultS4RepairedAction.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class X_FaultS4RepairedAction extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->repairFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/App/Handler/Fault/X_FaultS5AcceptedAction.php
Normal file
36
src/App/Handler/Fault/X_FaultS5AcceptedAction.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class X_FaultS5AcceptedAction extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->acceptFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -9,13 +9,13 @@ class MaintenanceFactory
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return MaintenanceAction
|
||||
* @return MaintenanceHandler
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$maintenanceManagerService = $container->get(MaintenanceManagerService::class);
|
||||
return new MaintenanceAction($maintenanceManagerService);
|
||||
return new MaintenanceHandler($maintenanceManagerService);
|
||||
}
|
||||
}
|
||||
59
src/App/Handler/MaintenanceHandler.php
Normal file
59
src/App/Handler/MaintenanceHandler.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class MaintenanceHandler extends CrudHandler
|
||||
{
|
||||
/** @var MaintenanceManagerService */
|
||||
private $maintenanceManagerService;
|
||||
|
||||
public function __construct(MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->maintenanceManagerService = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->maintenanceManagerService->getMaintenanceList()->getValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||
return new JsonResponse($this->maintenanceManagerService->get($hash));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||
$data = $this->getRequestData($request);
|
||||
$jwt = $request->getAttribute('token');
|
||||
return new JsonResponse($this->maintenanceManagerService->update($hash, $data, $jwt->uid));
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -9,13 +9,13 @@ class MaintenanceUpcomingFactory
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return MaintenanceUpcomingAction
|
||||
* @return MaintenanceUpcomingHandler
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$maintenanceManagerService = $container->get(MaintenanceManagerService::class);
|
||||
return new MaintenanceUpcomingAction($maintenanceManagerService);
|
||||
return new MaintenanceUpcomingHandler($maintenanceManagerService);
|
||||
}
|
||||
}
|
||||
31
src/App/Handler/MaintenanceUpcomingHandler.php
Normal file
31
src/App/Handler/MaintenanceUpcomingHandler.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class MaintenanceUpcomingHandler extends CrudHandler
|
||||
{
|
||||
/** @var MaintenanceManagerService */
|
||||
private $maintenanceManagerService;
|
||||
|
||||
public function __construct(MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->maintenanceManagerService = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->maintenanceManagerService->getUpcomingMaintenanceList()->getValues());
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
namespace App\Handler\Pdf;
|
||||
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use App\Service\PdfService;
|
||||
@ -10,7 +10,7 @@ class GenerateMaintenanceSheetFactory
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return GenerateMaintenanceSheetAction
|
||||
* @return GenerateMaintenanceSheetHandler
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
@ -20,6 +20,6 @@ class GenerateMaintenanceSheetFactory
|
||||
$pdfService = $container->get(PdfService::class);
|
||||
/** @var MaintenanceManagerService $maintenanceManagerService */
|
||||
$maintenanceManagerService = $container->get(MaintenanceManagerService::class);
|
||||
return new GenerateMaintenanceSheetAction($pdfService, $maintenanceManagerService);
|
||||
return new GenerateMaintenanceSheetHandler($pdfService, $maintenanceManagerService);
|
||||
}
|
||||
}
|
||||
40
src/App/Handler/Pdf/GenerateMaintenanceSheetHandler.php
Normal file
40
src/App/Handler/Pdf/GenerateMaintenanceSheetHandler.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Pdf;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use App\Service\PdfService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\TextResponse;
|
||||
|
||||
class GenerateMaintenanceSheetHandler extends CrudHandler
|
||||
{
|
||||
/** @var PdfService */
|
||||
private $pdfService;
|
||||
|
||||
/** @var MaintenanceManagerService */
|
||||
private $maintenanceManager;
|
||||
|
||||
public function __construct(PdfService $pdfService, MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->pdfService = $pdfService;
|
||||
$this->maintenanceManager = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
try {
|
||||
return (new TextResponse($this->pdfService->getMaintenanceSheet($id)))
|
||||
->withHeader('Content-type', 'application/pdf');
|
||||
} catch (\Exception $e) {
|
||||
return new TextResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
namespace App\Handler\Pdf;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use App\Service\PdfService;
|
||||
@ -14,6 +14,6 @@ class GenerateWorksheetFactory
|
||||
$pdfService = $container->get(PdfService::class);
|
||||
/** @var FaultManagerService $faultManager */
|
||||
$faultManager = $container->get(FaultManagerService::class);
|
||||
return new GenerateWorksheetAction($pdfService, $faultManager);
|
||||
return new GenerateWorksheetHandler($pdfService, $faultManager);
|
||||
}
|
||||
}
|
||||
@ -1,29 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
namespace App\Handler\Pdf;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use App\Service\PdfService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\TextResponse;
|
||||
|
||||
class GenerateWorksheetAction extends AbstractCrudAction
|
||||
class GenerateWorksheetHandler extends CrudHandler
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var PdfService
|
||||
*/
|
||||
/** @var PdfService */
|
||||
private $pdfService;
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
/** @var FaultManagerService */
|
||||
private $faultManager;
|
||||
|
||||
public function __construct(PdfService $pdfService, FaultManagerService $faultManagerService)
|
||||
@ -34,12 +25,10 @@ class GenerateWorksheetAction extends AbstractCrudAction
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
try {
|
||||
@ -52,16 +41,4 @@ class GenerateWorksheetAction extends AbstractCrudAction
|
||||
return new TextResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
18
src/App/Handler/PingHandler.php
Normal file
18
src/App/Handler/PingHandler.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class PingHandler implements RequestHandlerInterface
|
||||
{
|
||||
public function handle(ServerRequestInterface $request) : ResponseInterface
|
||||
{
|
||||
return new JsonResponse(['ack' => time()]);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\SolutionTimeIntervalService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -11,6 +11,6 @@ class SolutionTimeIntervalFactory
|
||||
{
|
||||
/** @var SolutionTimeIntervalService $facilityLocationService */
|
||||
$facilityLocationService = $container->get(SolutionTimeIntervalService::class);
|
||||
return new SolutionTimeIntervalAction($facilityLocationService);
|
||||
return new SolutionTimeIntervalHandler($facilityLocationService);
|
||||
}
|
||||
}
|
||||
31
src/App/Handler/SolutionTimeIntervalHandler.php
Normal file
31
src/App/Handler/SolutionTimeIntervalHandler.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\SolutionTimeIntervalService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class SolutionTimeIntervalHandler extends CrudHandler
|
||||
{
|
||||
/** @var SolutionTimeIntervalService */
|
||||
private $solutionTimeIntervalService;
|
||||
|
||||
public function __construct(SolutionTimeIntervalService $facilityLocationService)
|
||||
{
|
||||
$this->solutionTimeIntervalService = $facilityLocationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->solutionTimeIntervalService->getList());
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Handler\User;
|
||||
|
||||
use App\Service\UserService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -11,6 +11,6 @@ class PasswordFactory
|
||||
{
|
||||
/** @var UserService $userService */
|
||||
$userService = $container->get(UserService::class);
|
||||
return new PasswordAction($userService);
|
||||
return new PasswordHandler($userService);
|
||||
}
|
||||
}
|
||||
37
src/App/Handler/User/PasswordHandler.php
Normal file
37
src/App/Handler/User/PasswordHandler.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\User;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\UserService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class PasswordHandler extends CrudHandler
|
||||
{
|
||||
/** @var UserService */
|
||||
private $userService;
|
||||
|
||||
public function __construct(UserService $userService)
|
||||
{
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$token = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->userService->changePassword($token->uid, $data['old'], $data['new']));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Handler\User;
|
||||
|
||||
use App\Service\UserService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@ -11,6 +11,6 @@ class UserFactory
|
||||
{
|
||||
/** @var UserService $userService */
|
||||
$userService = $container->get(UserService::class);
|
||||
return new UserAction($userService);
|
||||
return new UserHandler($userService);
|
||||
}
|
||||
}
|
||||
70
src/App/Handler/User/UserHandler.php
Normal file
70
src/App/Handler/User/UserHandler.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\User;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\UserService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class UserHandler extends CrudHandler
|
||||
{
|
||||
/** @var UserService */
|
||||
private $userService;
|
||||
|
||||
public function __construct(UserService $userService)
|
||||
{
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
return new JsonResponse($this->userService->getList());
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
try {
|
||||
return new JsonResponse($this->userService->get($id));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->userService->update($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,40 +3,30 @@
|
||||
namespace App\Middleware;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Tuupola\Middleware\Cors;
|
||||
use Tuupola\Middleware\CorsMiddleware;
|
||||
|
||||
class CorsMiddlewareFactory
|
||||
{
|
||||
const CORS_ALLOW_HEADERS = [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Modified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Match',
|
||||
'If-Modified-Since',
|
||||
'If-Unmodified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
];
|
||||
|
||||
public function __invoke(ContainerInterface $container): Cors
|
||||
public function __invoke(ContainerInterface $container): CorsMiddleware
|
||||
{
|
||||
return new Cors([
|
||||
return new CorsMiddleware([
|
||||
"origin" => ["*"],
|
||||
"methods" => ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
"headers.allow" => [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Match',
|
||||
'If-Modified-Since',
|
||||
'If-Unmodified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
],
|
||||
"headers.allow" => self::CORS_ALLOW_HEADERS,
|
||||
"headers.expose" => ["Etag"],
|
||||
"credentials" => true,
|
||||
// "cache" => 86400
|
||||
|
||||
@ -2,12 +2,11 @@
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Slim\Middleware\JwtAuthentication;
|
||||
use Tuupola\Middleware\JwtAuthentication;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Expressive\Application;
|
||||
use Zend\Expressive\Router\Route;
|
||||
|
||||
@ -15,9 +14,7 @@ class JwtAuthenticationFactory
|
||||
{
|
||||
const DEFAULT_HMAC = 'thisShouldBeChangedForReal';
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
/** @var Config */
|
||||
private $config;
|
||||
|
||||
public function __invoke(ContainerInterface $container): JwtAuthentication
|
||||
@ -27,16 +24,16 @@ class JwtAuthenticationFactory
|
||||
return new JwtAuthentication([
|
||||
"secret" => $this->config->get('hmac_key', self::DEFAULT_HMAC),
|
||||
"path" => "/api",
|
||||
"passthrough" => $this->getPassThroughRoutes($container),
|
||||
"ignore" => $this->getPassThroughRoutes($container),
|
||||
"secure" => true,
|
||||
"relaxed" => [
|
||||
"localhost",
|
||||
"wnapi.yvan.hu",
|
||||
],
|
||||
"error" => function (RequestInterface $request, ResponseInterface $response, $arguments) {
|
||||
"error" => function (ResponseInterface $response, $arguments) {
|
||||
$data["status"] = "error";
|
||||
$data["message"] = $arguments["message"];
|
||||
return new JsonCorsResponse($data, 401);
|
||||
return new JsonResponse($data, 401);
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
@ -2,14 +2,16 @@
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Expressive\Router\RouteResult;
|
||||
use Zend\Permissions\Rbac\Rbac;
|
||||
|
||||
class RouteAuthorization
|
||||
class RouteAuthorization implements MiddlewareInterface
|
||||
{
|
||||
|
||||
private $config;
|
||||
@ -25,10 +27,17 @@ class RouteAuthorization
|
||||
$this->aclService = $aclService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
/**
|
||||
* Process an incoming server request and return a response, optionally delegating
|
||||
* response creation to a handler.
|
||||
* @param ServerRequestInterface $request
|
||||
* @param RequestHandlerInterface $handler
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if ($request->getMethod() == 'OPTIONS') {
|
||||
return $next($request, $response);
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
/** @var RouteResult $routeResult */
|
||||
@ -36,10 +45,10 @@ class RouteAuthorization
|
||||
$token = $request->getAttribute('token');
|
||||
|
||||
if ($this->hasRouteAccess($routeResult->getMatchedRouteName(), $token->roles ?? [])) {
|
||||
return $next($request, $response);
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
return new JsonCorsResponse([
|
||||
return new JsonResponse([
|
||||
'status' => 'err',
|
||||
'message' => "Access denied to " . $routeResult->getMatchedRouteName(),
|
||||
], 401);
|
||||
@ -72,4 +81,5 @@ class RouteAuthorization
|
||||
{
|
||||
return $this->aclService->isGranted($role, $routeName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,12 +3,13 @@
|
||||
namespace App\Middleware;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Permissions\Rbac\Rbac;
|
||||
|
||||
class RouteAuthorizationFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container): RouteAuthorization
|
||||
public function __invoke(ContainerInterface $container): MiddlewareInterface
|
||||
{
|
||||
/** @var Config $config */
|
||||
$config = new Config($container->get('config')['acl_config']);
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Response;
|
||||
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class JsonCorsResponse extends JsonResponse
|
||||
{
|
||||
const ALLOW_HEADERS = [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Modified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
$data,
|
||||
$status = 200,
|
||||
array $headers = [],
|
||||
$encodingOptions = self::DEFAULT_JSON_FLAGS
|
||||
) {
|
||||
$headers['Access-Control-Allow-Origin'] = '*';
|
||||
$headers['Access-Control-Allow-Methods'] = 'OPTIONS,GET,POST,PUT,PATCH,DELETE';
|
||||
$headers['Access-Control-Allow-Headers'] = implode(",", self::ALLOW_HEADERS);
|
||||
parent::__construct($data, $status, $headers, $encodingOptions);
|
||||
}
|
||||
}
|
||||
@ -44,7 +44,6 @@ class FaultManagerService
|
||||
MailerService $mailer,
|
||||
UserService $userService
|
||||
) {
|
||||
|
||||
$this->em = $em;
|
||||
$this->hydrator = $hydrator;
|
||||
$this->authService = $authService;
|
||||
@ -64,6 +63,9 @@ class FaultManagerService
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Fault|null
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function getFault(int $id): ?Fault
|
||||
{
|
||||
@ -72,6 +74,14 @@ class FaultManagerService
|
||||
return $fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $uid
|
||||
* @return Fault
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function createFault($data, $uid): Fault
|
||||
{
|
||||
/** @var User $user */
|
||||
@ -100,6 +110,9 @@ class FaultManagerService
|
||||
* @param array $data
|
||||
* @param int $uid
|
||||
* @return Fault
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function updateFault(int $id, array $data, int $uid): Fault
|
||||
{
|
||||
@ -174,6 +187,15 @@ class FaultManagerService
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param $data
|
||||
* @param int $uid
|
||||
* @return Fault
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function addFaultComment(int $id, $data, int $uid): Fault
|
||||
{
|
||||
/** @var Fault $fault */
|
||||
@ -195,6 +217,9 @@ class FaultManagerService
|
||||
* @param $data
|
||||
* @param int $uid
|
||||
* @return Fault
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function rejectFault(int $id, $data, int $uid): Fault
|
||||
{
|
||||
@ -224,6 +249,8 @@ class FaultManagerService
|
||||
* @param User $user
|
||||
* @param $newState
|
||||
* @param string $comment
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
*/
|
||||
private function snapshotHandler(Fault $fault, User $user, $newState, $comment = '')
|
||||
{
|
||||
|
||||
66
src/DoctrineExpressiveModule/ConfigProvider.php
Normal file
66
src/DoctrineExpressiveModule/ConfigProvider.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineExpressiveModule;
|
||||
|
||||
use Zend\EventManager\EventManager;
|
||||
|
||||
/**
|
||||
* The configuration provider for the DoctrineExpressiveModule module
|
||||
*
|
||||
* @see https://docs.zendframework.com/zend-component-installer/
|
||||
*/
|
||||
class ConfigProvider
|
||||
{
|
||||
/**
|
||||
* Returns the configuration array
|
||||
*
|
||||
* To add a bit of a structure, each section is defined in a separate
|
||||
* method which returns an array with its configuration.
|
||||
*
|
||||
*/
|
||||
public function __invoke() : array
|
||||
{
|
||||
return [
|
||||
'dependencies' => $this->getDependencies(),
|
||||
'form_elements' => $this->getFormElements(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the container dependencies
|
||||
*/
|
||||
public function getDependencies() : array
|
||||
{
|
||||
return [
|
||||
'aliases' => [
|
||||
'doctrine.hydrator' => Hydrator\DoctrineObject::class,
|
||||
'EventManager' => EventManager::class,
|
||||
\Doctrine\ORM\EntityManager::class => 'doctrine.entity_manager.orm_default',
|
||||
],
|
||||
'invokables' => [
|
||||
EventManager::class => EventManager::class,
|
||||
],
|
||||
'factories' => [
|
||||
Hydrator\DoctrineObject::class => Hydrator\DoctrineObjectFactory::class,
|
||||
'doctrine.entity_manager.orm_default' => \ContainerInteropDoctrine\EntityManagerFactory::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the form dependencies
|
||||
*/
|
||||
public function getFormElements() : array
|
||||
{
|
||||
return [
|
||||
'aliases' => [
|
||||
'doctrine.object_select' => Form\Element\ObjectSelect::class,
|
||||
],
|
||||
'factories' => [
|
||||
Form\Element\ObjectSelect::class => Form\Element\ElementFactory::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
18
src/DoctrineExpressiveModule/Form/Element/ElementFactory.php
Normal file
18
src/DoctrineExpressiveModule/Form/Element/ElementFactory.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace DoctrineExpressiveModule\Form\Element;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class ElementFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container, string $elementClass)
|
||||
{
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
/** @var ObjectSelect|ObjectRadio|ObjectMultiCheckbox $element */
|
||||
$element = new $elementClass();
|
||||
$element->setOption('object_manager', $em);
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace DoctrineExpressiveModule\Form\Element\Exception;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class InvalidRepositoryResultException extends InvalidArgumentException
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace DoctrineExpressiveModule\Form\Element;
|
||||
|
||||
use DoctrineModule\Form\Element\Proxy;
|
||||
use Zend\Form\Element\MultiCheckbox;
|
||||
use Zend\Form\Form;
|
||||
use Zend\Stdlib\ArrayUtils;
|
||||
|
||||
class ObjectMultiCheckbox extends MultiCheckbox
|
||||
{
|
||||
/**
|
||||
* @var Proxy
|
||||
*/
|
||||
protected $proxy;
|
||||
|
||||
/**
|
||||
* @return Proxy
|
||||
*/
|
||||
public function getProxy()
|
||||
{
|
||||
if (null === $this->proxy) {
|
||||
$this->proxy = new Proxy();
|
||||
}
|
||||
return $this->proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Traversable $options
|
||||
* @return self
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->getProxy()->setOptions($options);
|
||||
return parent::setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return self
|
||||
*/
|
||||
public function setOption($key, $value)
|
||||
{
|
||||
$this->getProxy()->setOptions([$key => $value]);
|
||||
return parent::setOption($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
if ($value instanceof \Traversable) {
|
||||
$value = ArrayUtils::iteratorToArray($value);
|
||||
} elseif ($value == null) {
|
||||
return parent::setValue([]);
|
||||
} elseif (! is_array($value)) {
|
||||
$value = (array)$value;
|
||||
}
|
||||
|
||||
return parent::setValue(array_map([$this->getProxy(), 'getValue'], $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getValueOptions()
|
||||
{
|
||||
if (! empty($this->valueOptions)) {
|
||||
return $this->valueOptions;
|
||||
}
|
||||
|
||||
$proxyValueOptions = $this->getProxy()->getValueOptions();
|
||||
|
||||
if (! empty($proxyValueOptions)) {
|
||||
$this->setValueOptions($proxyValueOptions);
|
||||
}
|
||||
|
||||
return $this->valueOptions;
|
||||
}
|
||||
}
|
||||
73
src/DoctrineExpressiveModule/Form/Element/ObjectRadio.php
Normal file
73
src/DoctrineExpressiveModule/Form/Element/ObjectRadio.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace DoctrineExpressiveModule\Form\Element;
|
||||
|
||||
use DoctrineExpressiveModule\Form\Element\Proxy;
|
||||
use Zend\Form\Element\Radio as RadioElement;
|
||||
use Zend\Form\Form;
|
||||
|
||||
class ObjectRadio extends RadioElement
|
||||
{
|
||||
/**
|
||||
* @var Proxy
|
||||
*/
|
||||
protected $proxy;
|
||||
|
||||
/**
|
||||
* @return Proxy
|
||||
*/
|
||||
public function getProxy()
|
||||
{
|
||||
if (null === $this->proxy) {
|
||||
$this->proxy = new Proxy();
|
||||
}
|
||||
return $this->proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Traversable $options
|
||||
* @return self
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->getProxy()->setOptions($options);
|
||||
return parent::setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return self
|
||||
*/
|
||||
public function setOption($key, $value)
|
||||
{
|
||||
$this->getProxy()->setOptions([$key => $value]);
|
||||
return parent::setOption($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
return parent::setValue($this->getProxy()->getValue($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getValueOptions()
|
||||
{
|
||||
if (! empty($this->valueOptions)) {
|
||||
return $this->valueOptions;
|
||||
}
|
||||
|
||||
$proxyValueOptions = $this->getProxy()->getValueOptions();
|
||||
|
||||
if (! empty($proxyValueOptions)) {
|
||||
$this->setValueOptions($proxyValueOptions);
|
||||
}
|
||||
|
||||
return $this->valueOptions;
|
||||
}
|
||||
}
|
||||
88
src/DoctrineExpressiveModule/Form/Element/ObjectSelect.php
Normal file
88
src/DoctrineExpressiveModule/Form/Element/ObjectSelect.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace DoctrineExpressiveModule\Form\Element;
|
||||
|
||||
use DoctrineExpressiveModule\Form\Element\Proxy;
|
||||
use Zend\Form\Element\Select as SelectElement;
|
||||
use Zend\Form\Form;
|
||||
use Zend\Stdlib\ArrayUtils;
|
||||
|
||||
class ObjectSelect extends SelectElement
|
||||
{
|
||||
/**
|
||||
* @var Proxy
|
||||
*/
|
||||
protected $proxy;
|
||||
|
||||
/**
|
||||
* @return Proxy
|
||||
*/
|
||||
public function getProxy()
|
||||
{
|
||||
if (null === $this->proxy) {
|
||||
$this->proxy = new Proxy();
|
||||
}
|
||||
return $this->proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Traversable $options
|
||||
* @return self
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->getProxy()->setOptions($options);
|
||||
return parent::setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return self
|
||||
*/
|
||||
public function setOption($key, $value)
|
||||
{
|
||||
$this->getProxy()->setOptions([$key => $value]);
|
||||
return parent::setOption($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$multiple = $this->getAttribute('multiple');
|
||||
|
||||
if (true === $multiple || 'multiple' === $multiple) {
|
||||
if ($value instanceof \Traversable) {
|
||||
$value = ArrayUtils::iteratorToArray($value);
|
||||
} elseif ($value == null) {
|
||||
return parent::setValue([]);
|
||||
} elseif (! is_array($value)) {
|
||||
$value = (array) $value;
|
||||
}
|
||||
|
||||
return parent::setValue(array_map([$this->getProxy(), 'getValue'], $value));
|
||||
}
|
||||
|
||||
return parent::setValue($this->getProxy()->getValue($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getValueOptions()
|
||||
{
|
||||
if (! empty($this->valueOptions)) {
|
||||
return $this->valueOptions;
|
||||
}
|
||||
|
||||
$proxyValueOptions = $this->getProxy()->getValueOptions();
|
||||
|
||||
if (! empty($proxyValueOptions)) {
|
||||
$this->setValueOptions($proxyValueOptions);
|
||||
}
|
||||
|
||||
return $this->valueOptions;
|
||||
}
|
||||
}
|
||||
653
src/DoctrineExpressiveModule/Form/Element/Proxy.php
Normal file
653
src/DoctrineExpressiveModule/Form/Element/Proxy.php
Normal file
@ -0,0 +1,653 @@
|
||||
<?php
|
||||
|
||||
namespace DoctrineExpressiveModule\Form\Element;
|
||||
|
||||
use Traversable;
|
||||
use ReflectionMethod;
|
||||
use RuntimeException;
|
||||
use InvalidArgumentException;
|
||||
use Zend\Stdlib\Guard\ArrayOrTraversableGuardTrait;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Doctrine\Common\Util\Inflector;
|
||||
|
||||
class Proxy
|
||||
{
|
||||
use ArrayOrTraversableGuardTrait;
|
||||
|
||||
/**
|
||||
* @var array|Traversable
|
||||
*/
|
||||
protected $objects;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $targetClass;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $valueOptions = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $findMethod = [];
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $property;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $option_attributes = [];
|
||||
|
||||
/**
|
||||
* @var callable $labelGenerator A callable used to create a label based on an item in the collection an Entity
|
||||
*/
|
||||
protected $labelGenerator;
|
||||
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
protected $isMethod;
|
||||
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $displayEmptyItem = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $emptyItemLabel = '';
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $optgroupIdentifier;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $optgroupDefault;
|
||||
|
||||
public function setOptions($options)
|
||||
{
|
||||
if (isset($options['object_manager'])) {
|
||||
$this->setObjectManager($options['object_manager']);
|
||||
}
|
||||
|
||||
if (isset($options['target_class'])) {
|
||||
$this->setTargetClass($options['target_class']);
|
||||
}
|
||||
|
||||
if (isset($options['property'])) {
|
||||
$this->setProperty($options['property']);
|
||||
}
|
||||
|
||||
if (isset($options['label_generator'])) {
|
||||
$this->setLabelGenerator($options['label_generator']);
|
||||
}
|
||||
|
||||
if (isset($options['find_method'])) {
|
||||
$this->setFindMethod($options['find_method']);
|
||||
}
|
||||
|
||||
if (isset($options['is_method'])) {
|
||||
$this->setIsMethod($options['is_method']);
|
||||
}
|
||||
|
||||
if (isset($options['display_empty_item'])) {
|
||||
$this->setDisplayEmptyItem($options['display_empty_item']);
|
||||
}
|
||||
|
||||
if (isset($options['empty_item_label'])) {
|
||||
$this->setEmptyItemLabel($options['empty_item_label']);
|
||||
}
|
||||
|
||||
if (isset($options['option_attributes'])) {
|
||||
$this->setOptionAttributes($options['option_attributes']);
|
||||
}
|
||||
|
||||
if (isset($options['optgroup_identifier'])) {
|
||||
$this->setOptgroupIdentifier($options['optgroup_identifier']);
|
||||
}
|
||||
|
||||
if (isset($options['optgroup_default'])) {
|
||||
$this->setOptgroupDefault($options['optgroup_default']);
|
||||
}
|
||||
}
|
||||
|
||||
public function getValueOptions()
|
||||
{
|
||||
if (empty($this->valueOptions)) {
|
||||
$this->loadValueOptions();
|
||||
}
|
||||
|
||||
return $this->valueOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|Traversable
|
||||
*/
|
||||
public function getObjects()
|
||||
{
|
||||
$this->loadObjects();
|
||||
|
||||
return $this->objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the label for the empty option
|
||||
*
|
||||
* @param string $emptyItemLabel
|
||||
*
|
||||
* @return Proxy
|
||||
*/
|
||||
public function setEmptyItemLabel($emptyItemLabel)
|
||||
{
|
||||
$this->emptyItemLabel = $emptyItemLabel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmptyItemLabel()
|
||||
{
|
||||
return $this->emptyItemLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOptionAttributes()
|
||||
{
|
||||
return $this->option_attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $option_attributes
|
||||
*/
|
||||
public function setOptionAttributes(array $option_attributes)
|
||||
{
|
||||
$this->option_attributes = $option_attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a flag, whether to include the empty option at the beginning or not
|
||||
*
|
||||
* @param boolean $displayEmptyItem
|
||||
*
|
||||
* @return Proxy
|
||||
*/
|
||||
public function setDisplayEmptyItem($displayEmptyItem)
|
||||
{
|
||||
$this->displayEmptyItem = $displayEmptyItem;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getDisplayEmptyItem()
|
||||
{
|
||||
return $this->displayEmptyItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object manager
|
||||
*
|
||||
* @param ObjectManager $objectManager
|
||||
*
|
||||
* @return Proxy
|
||||
*/
|
||||
public function setObjectManager(ObjectManager $objectManager)
|
||||
{
|
||||
$this->objectManager = $objectManager;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object manager
|
||||
*
|
||||
* @return ObjectManager
|
||||
*/
|
||||
public function getObjectManager()
|
||||
{
|
||||
return $this->objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the FQCN of the target object
|
||||
*
|
||||
* @param string $targetClass
|
||||
*
|
||||
* @return Proxy
|
||||
*/
|
||||
public function setTargetClass($targetClass)
|
||||
{
|
||||
$this->targetClass = $targetClass;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTargetClass()
|
||||
{
|
||||
return $this->targetClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the property to use as the label in the options
|
||||
*
|
||||
* @param string $property
|
||||
*
|
||||
* @return Proxy
|
||||
*/
|
||||
public function setProperty($property)
|
||||
{
|
||||
$this->property = $property;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getProperty()
|
||||
{
|
||||
return $this->property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the label generator callable that is responsible for generating labels for the items in the collection
|
||||
*
|
||||
* @param callable $callable A callable used to create a label based off of an Entity
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setLabelGenerator($callable)
|
||||
{
|
||||
if (! is_callable($callable)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Property "label_generator" needs to be a callable function or a \Closure'
|
||||
);
|
||||
}
|
||||
|
||||
$this->labelGenerator = $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return callable|null
|
||||
*/
|
||||
public function getLabelGenerator()
|
||||
{
|
||||
return $this->labelGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getOptgroupIdentifier()
|
||||
{
|
||||
return $this->optgroupIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $optgroupIdentifier
|
||||
*/
|
||||
public function setOptgroupIdentifier($optgroupIdentifier)
|
||||
{
|
||||
$this->optgroupIdentifier = (string) $optgroupIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getOptgroupDefault()
|
||||
{
|
||||
return $this->optgroupDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $optgroupDefault
|
||||
*/
|
||||
public function setOptgroupDefault($optgroupDefault)
|
||||
{
|
||||
$this->optgroupDefault = (string) $optgroupDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the property is a method to use as the label in the options
|
||||
*
|
||||
* @param boolean $method
|
||||
*
|
||||
* @return Proxy
|
||||
*/
|
||||
public function setIsMethod($method)
|
||||
{
|
||||
$this->isMethod = (bool) $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIsMethod()
|
||||
{
|
||||
return $this->isMethod;
|
||||
}
|
||||
|
||||
/** Set the findMethod property to specify the method to use on repository
|
||||
*
|
||||
* @param array $findMethod
|
||||
*
|
||||
* @return Proxy
|
||||
*/
|
||||
public function setFindMethod($findMethod)
|
||||
{
|
||||
$this->findMethod = $findMethod;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get findMethod definition
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFindMethod()
|
||||
{
|
||||
return $this->findMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $targetEntity
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function generateLabel($targetEntity)
|
||||
{
|
||||
if (null === ($labelGenerator = $this->getLabelGenerator())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return call_user_func($labelGenerator, $targetEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return array|mixed|object
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function getValue($value)
|
||||
{
|
||||
if (! ($om = $this->getObjectManager())) {
|
||||
throw new RuntimeException('No object manager was set');
|
||||
}
|
||||
|
||||
if (! ($targetClass = $this->getTargetClass())) {
|
||||
throw new RuntimeException('No target class was set');
|
||||
}
|
||||
|
||||
$metadata = $om->getClassMetadata($targetClass);
|
||||
|
||||
if (is_object($value)) {
|
||||
if ($value instanceof Collection) {
|
||||
$data = [];
|
||||
|
||||
foreach ($value as $object) {
|
||||
$values = $metadata->getIdentifierValues($object);
|
||||
$data[] = array_shift($values);
|
||||
}
|
||||
|
||||
$value = $data;
|
||||
} else {
|
||||
$metadata = $om->getClassMetadata(get_class($value));
|
||||
$identifier = $metadata->getIdentifierFieldNames();
|
||||
|
||||
// TODO: handle composite (multiple) identifiers
|
||||
if (null !== $identifier && count($identifier) > 1) {
|
||||
//$value = $key;
|
||||
} else {
|
||||
$value = current($metadata->getIdentifierValues($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load objects
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* @throws Exception\InvalidRepositoryResultException
|
||||
* @return void
|
||||
*/
|
||||
protected function loadObjects()
|
||||
{
|
||||
if (! empty($this->objects)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$findMethod = (array) $this->getFindMethod();
|
||||
|
||||
if (! $findMethod) {
|
||||
$findMethodName = 'findAll';
|
||||
$repository = $this->objectManager->getRepository($this->targetClass);
|
||||
$objects = $repository->findAll();
|
||||
} else {
|
||||
if (! isset($findMethod['name'])) {
|
||||
throw new RuntimeException('No method name was set');
|
||||
}
|
||||
$findMethodName = $findMethod['name'];
|
||||
$findMethodParams = isset($findMethod['params']) ? array_change_key_case($findMethod['params']) : [];
|
||||
$repository = $this->objectManager->getRepository($this->targetClass);
|
||||
|
||||
if (! method_exists($repository, $findMethodName)) {
|
||||
throw new RuntimeException(
|
||||
sprintf(
|
||||
'Method "%s" could not be found in repository "%s"',
|
||||
$findMethodName,
|
||||
get_class($repository)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$r = new ReflectionMethod($repository, $findMethodName);
|
||||
$args = [];
|
||||
|
||||
foreach ($r->getParameters() as $param) {
|
||||
if (array_key_exists(strtolower($param->getName()), $findMethodParams)) {
|
||||
$args[] = $findMethodParams[strtolower($param->getName())];
|
||||
} elseif ($param->isDefaultValueAvailable()) {
|
||||
$args[] = $param->getDefaultValue();
|
||||
} elseif (! $param->isOptional()) {
|
||||
throw new RuntimeException(
|
||||
sprintf(
|
||||
'Required parameter "%s" with no default value for method "%s" in repository "%s"'
|
||||
. ' was not provided',
|
||||
$param->getName(),
|
||||
$findMethodName,
|
||||
get_class($repository)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
$objects = $r->invokeArgs($repository, $args);
|
||||
}
|
||||
|
||||
$this->guardForArrayOrTraversable(
|
||||
$objects,
|
||||
sprintf('%s::%s() return value', get_class($repository), $findMethodName),
|
||||
'DoctrineModule\Form\Element\Exception\InvalidRepositoryResultException'
|
||||
);
|
||||
|
||||
$this->objects = $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load value options
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* @return void
|
||||
*/
|
||||
protected function loadValueOptions()
|
||||
{
|
||||
if (! ($om = $this->objectManager)) {
|
||||
throw new RuntimeException('No object manager was set');
|
||||
}
|
||||
|
||||
if (! ($targetClass = $this->targetClass)) {
|
||||
throw new RuntimeException('No target class was set');
|
||||
}
|
||||
|
||||
$metadata = $om->getClassMetadata($targetClass);
|
||||
$identifier = $metadata->getIdentifierFieldNames();
|
||||
$objects = $this->getObjects();
|
||||
$options = [];
|
||||
$optionAttributes = [];
|
||||
|
||||
if ($this->displayEmptyItem) {
|
||||
$options[''] = $this->getEmptyItemLabel();
|
||||
}
|
||||
|
||||
foreach ($objects as $key => $object) {
|
||||
if (null !== ($generatedLabel = $this->generateLabel($object))) {
|
||||
$label = $generatedLabel;
|
||||
} elseif ($property = $this->property) {
|
||||
if ($this->isMethod == false && ! $metadata->hasField($property)) {
|
||||
throw new RuntimeException(
|
||||
sprintf(
|
||||
'Property "%s" could not be found in object "%s"',
|
||||
$property,
|
||||
$targetClass
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$getter = 'get' . Inflector::classify($property);
|
||||
|
||||
if (! is_callable([$object, $getter])) {
|
||||
throw new RuntimeException(
|
||||
sprintf('Method "%s::%s" is not callable', $this->targetClass, $getter)
|
||||
);
|
||||
}
|
||||
|
||||
$label = $object->{$getter}();
|
||||
} else {
|
||||
if (! is_callable([$object, '__toString'])) {
|
||||
throw new RuntimeException(
|
||||
sprintf(
|
||||
'%s must have a "__toString()" method defined if you have not set a property'
|
||||
. ' or method to use.',
|
||||
$targetClass
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$label = (string) $object;
|
||||
}
|
||||
|
||||
if (null !== $identifier && count($identifier) > 1) {
|
||||
$value = $key;
|
||||
} else {
|
||||
$value = current($metadata->getIdentifierValues($object));
|
||||
}
|
||||
|
||||
foreach ($this->getOptionAttributes() as $optionKey => $optionValue) {
|
||||
if (is_string($optionValue)) {
|
||||
$optionAttributes[$optionKey] = $optionValue;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_callable($optionValue)) {
|
||||
$callableValue = call_user_func($optionValue, $object);
|
||||
$optionAttributes[$optionKey] = (string) $callableValue;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new RuntimeException(
|
||||
sprintf(
|
||||
'Parameter "option_attributes" expects an array of key => value where value is of type'
|
||||
. '"string" or "callable". Value of type "%s" found.',
|
||||
gettype($optionValue)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// If no optgroup_identifier has been configured, apply default handling and continue
|
||||
if (is_null($this->getOptgroupIdentifier())) {
|
||||
$options[] = ['label' => $label, 'value' => $value, 'attributes' => $optionAttributes];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// optgroup_identifier found, handle grouping
|
||||
$optgroupGetter = 'get' . Inflector::classify($this->getOptgroupIdentifier());
|
||||
|
||||
if (! is_callable([$object, $optgroupGetter])) {
|
||||
throw new RuntimeException(
|
||||
sprintf('Method "%s::%s" is not callable', $this->targetClass, $optgroupGetter)
|
||||
);
|
||||
}
|
||||
|
||||
$optgroup = $object->{$optgroupGetter}();
|
||||
|
||||
// optgroup_identifier contains a valid group-name. Handle default grouping.
|
||||
if (false === is_null($optgroup) && trim($optgroup) !== '') {
|
||||
$options[$optgroup]['label'] = $optgroup;
|
||||
$options[$optgroup]['options'][] = [
|
||||
'label' => $label,
|
||||
'value' => $value,
|
||||
'attributes' => $optionAttributes,
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$optgroupDefault = $this->getOptgroupDefault();
|
||||
|
||||
// No optgroup_default has been provided. Line up without a group
|
||||
if (is_null($optgroupDefault)) {
|
||||
$options[] = ['label' => $label, 'value' => $value, 'attributes' => $optionAttributes];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Line up entry with optgroup_default
|
||||
$options[$optgroupDefault]['label'] = $optgroupDefault;
|
||||
$options[$optgroupDefault]['options'][] = [
|
||||
'label' => $label,
|
||||
'value' => $value,
|
||||
'attributes' => $optionAttributes,
|
||||
];
|
||||
}
|
||||
|
||||
$this->valueOptions = $options;
|
||||
}
|
||||
}
|
||||
613
src/DoctrineExpressiveModule/Hydrator/DoctrineObject.php
Executable file
613
src/DoctrineExpressiveModule/Hydrator/DoctrineObject.php
Executable file
@ -0,0 +1,613 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace DoctrineExpressiveModule\Hydrator;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Doctrine\Common\Util\Inflector;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Traversable;
|
||||
use Zend\Stdlib\ArrayUtils;
|
||||
use Zend\Hydrator\AbstractHydrator;
|
||||
use Zend\Hydrator\Filter\FilterProviderInterface;
|
||||
|
||||
/**
|
||||
* This hydrator has been completely refactored for DoctrineModule 0.7.0. It provides an easy and powerful way
|
||||
* of extracting/hydrator objects in Doctrine, by handling most associations types.
|
||||
*
|
||||
* Starting from DoctrineModule 0.8.0, the hydrator can be used multiple times with different objects
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
class DoctrineObject extends AbstractHydrator
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @var ClassMetadata
|
||||
*/
|
||||
protected $metadata;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $byValue = true;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ObjectManager $objectManager The ObjectManager to use
|
||||
* @param bool $byValue If set to true, hydrator will always use entity's public API
|
||||
*/
|
||||
public function __construct(ObjectManager $objectManager, $byValue = true)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->objectManager = $objectManager;
|
||||
$this->byValue = (bool) $byValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract values from an object
|
||||
*
|
||||
* @param object $object
|
||||
* @return array
|
||||
*/
|
||||
public function extract($object)
|
||||
{
|
||||
$this->prepare($object);
|
||||
|
||||
if ($this->byValue) {
|
||||
return $this->extractByValue($object);
|
||||
}
|
||||
|
||||
return $this->extractByReference($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate $object with the provided $data.
|
||||
*
|
||||
* @param array $data
|
||||
* @param object $object
|
||||
* @return object
|
||||
*/
|
||||
public function hydrate(array $data, $object)
|
||||
{
|
||||
$this->prepare($object);
|
||||
|
||||
if ($this->byValue) {
|
||||
return $this->hydrateByValue($data, $object);
|
||||
}
|
||||
|
||||
return $this->hydrateByReference($data, $object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the hydrator by adding strategies to every collection valued associations
|
||||
*
|
||||
* @param object $object
|
||||
* @return void
|
||||
*/
|
||||
protected function prepare($object)
|
||||
{
|
||||
$this->metadata = $this->objectManager->getClassMetadata(get_class($object));
|
||||
$this->prepareStrategies();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare strategies before the hydrator is used
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareStrategies()
|
||||
{
|
||||
$associations = $this->metadata->getAssociationNames();
|
||||
|
||||
foreach ($associations as $association) {
|
||||
if ($this->metadata->isCollectionValuedAssociation($association)) {
|
||||
// Add a strategy if the association has none set by user
|
||||
if (!$this->hasStrategy($association)) {
|
||||
if ($this->byValue) {
|
||||
$this->addStrategy($association, new Strategy\AllowRemoveByValue());
|
||||
} else {
|
||||
$this->addStrategy($association, new Strategy\AllowRemoveByReference());
|
||||
}
|
||||
}
|
||||
|
||||
$strategy = $this->getStrategy($association);
|
||||
|
||||
if (!$strategy instanceof Strategy\AbstractCollectionStrategy) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'Strategies used for collections valued associations must inherit from '
|
||||
. 'Strategy\AbstractCollectionStrategy, %s given',
|
||||
get_class($strategy)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$strategy->setCollectionName($association)
|
||||
->setClassMetadata($this->metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract values from an object using a by-value logic (this means that it uses the entity
|
||||
* API, in this case, getters)
|
||||
*
|
||||
* @param object $object
|
||||
* @throws RuntimeException
|
||||
* @return array
|
||||
*/
|
||||
protected function extractByValue($object)
|
||||
{
|
||||
$fieldNames = array_merge($this->metadata->getFieldNames(), $this->metadata->getAssociationNames());
|
||||
$methods = get_class_methods($object);
|
||||
$filter = $object instanceof FilterProviderInterface
|
||||
? $object->getFilter()
|
||||
: $this->filterComposite;
|
||||
|
||||
$data = [];
|
||||
foreach ($fieldNames as $fieldName) {
|
||||
if ($filter && !$filter->filter($fieldName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$getter = 'get' . Inflector::classify($fieldName);
|
||||
$isser = 'is' . Inflector::classify($fieldName);
|
||||
|
||||
$dataFieldName = $this->computeExtractFieldName($fieldName);
|
||||
if (in_array($getter, $methods)) {
|
||||
$data[$dataFieldName] = $this->extractValue($fieldName, $object->$getter(), $object);
|
||||
} elseif (in_array($isser, $methods)) {
|
||||
$data[$dataFieldName] = $this->extractValue($fieldName, $object->$isser(), $object);
|
||||
} elseif (substr($fieldName, 0, 2) === 'is'
|
||||
&& ctype_upper(substr($fieldName, 2, 1))
|
||||
&& in_array($fieldName, $methods)) {
|
||||
$data[$dataFieldName] = $this->extractValue($fieldName, $object->$fieldName(), $object);
|
||||
}
|
||||
|
||||
// Unknown fields are ignored
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract values from an object using a by-reference logic (this means that values are
|
||||
* directly fetched without using the public API of the entity, in this case, getters)
|
||||
*
|
||||
* @param object $object
|
||||
* @return array
|
||||
*/
|
||||
protected function extractByReference($object)
|
||||
{
|
||||
$fieldNames = array_merge($this->metadata->getFieldNames(), $this->metadata->getAssociationNames());
|
||||
$refl = $this->metadata->getReflectionClass();
|
||||
$filter = $object instanceof FilterProviderInterface
|
||||
? $object->getFilter()
|
||||
: $this->filterComposite;
|
||||
|
||||
$data = [];
|
||||
foreach ($fieldNames as $fieldName) {
|
||||
if ($filter && !$filter->filter($fieldName)) {
|
||||
continue;
|
||||
}
|
||||
$reflProperty = $refl->getProperty($fieldName);
|
||||
$reflProperty->setAccessible(true);
|
||||
|
||||
$dataFieldName = $this->computeExtractFieldName($fieldName);
|
||||
$data[$dataFieldName] = $this->extractValue($fieldName, $reflProperty->getValue($object), $object);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the object using a by-value logic (this means that it uses the entity API, in this
|
||||
* case, setters)
|
||||
*
|
||||
* @param array $data
|
||||
* @param object $object
|
||||
* @throws RuntimeException
|
||||
* @return object
|
||||
*/
|
||||
protected function hydrateByValue(array $data, $object)
|
||||
{
|
||||
$tryObject = $this->tryConvertArrayToObject($data, $object);
|
||||
$metadata = $this->metadata;
|
||||
|
||||
if (is_object($tryObject)) {
|
||||
$object = $tryObject;
|
||||
}
|
||||
|
||||
foreach ($data as $field => $value) {
|
||||
$field = $this->computeHydrateFieldName($field);
|
||||
$value = $this->handleTypeConversions($value, $metadata->getTypeOfField($field));
|
||||
$setter = 'set' . Inflector::classify($field);
|
||||
|
||||
if ($metadata->hasAssociation($field)) {
|
||||
$target = $metadata->getAssociationTargetClass($field);
|
||||
|
||||
if ($metadata->isSingleValuedAssociation($field)) {
|
||||
if (! method_exists($object, $setter)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $this->toOne($target, $this->hydrateValue($field, $value, $data));
|
||||
|
||||
if (null === $value
|
||||
&& !current($metadata->getReflectionClass()->getMethod($setter)->getParameters())->allowsNull()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$object->$setter($value);
|
||||
} elseif ($metadata->isCollectionValuedAssociation($field)) {
|
||||
$this->toMany($object, $field, $target, $value);
|
||||
}
|
||||
} else {
|
||||
if (! method_exists($object, $setter)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$object->$setter($this->hydrateValue($field, $value, $data));
|
||||
}
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the object using a by-reference logic (this means that values are modified directly without
|
||||
* using the public API, in this case setters, and hence override any logic that could be done in those
|
||||
* setters)
|
||||
*
|
||||
* @param array $data
|
||||
* @param object $object
|
||||
* @return object
|
||||
*/
|
||||
protected function hydrateByReference(array $data, $object)
|
||||
{
|
||||
$tryObject = $this->tryConvertArrayToObject($data, $object);
|
||||
$metadata = $this->metadata;
|
||||
$refl = $metadata->getReflectionClass();
|
||||
|
||||
if (is_object($tryObject)) {
|
||||
$object = $tryObject;
|
||||
}
|
||||
|
||||
foreach ($data as $field => $value) {
|
||||
$field = $this->computeHydrateFieldName($field);
|
||||
|
||||
// Ignore unknown fields
|
||||
if (!$refl->hasProperty($field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $this->handleTypeConversions($value, $metadata->getTypeOfField($field));
|
||||
$reflProperty = $refl->getProperty($field);
|
||||
$reflProperty->setAccessible(true);
|
||||
|
||||
if ($metadata->hasAssociation($field)) {
|
||||
$target = $metadata->getAssociationTargetClass($field);
|
||||
|
||||
if ($metadata->isSingleValuedAssociation($field)) {
|
||||
$value = $this->toOne($target, $this->hydrateValue($field, $value, $data));
|
||||
$reflProperty->setValue($object, $value);
|
||||
} elseif ($metadata->isCollectionValuedAssociation($field)) {
|
||||
$this->toMany($object, $field, $target, $value);
|
||||
}
|
||||
} else {
|
||||
$reflProperty->setValue($object, $this->hydrateValue($field, $value, $data));
|
||||
}
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function tries, given an array of data, to convert it to an object if the given array contains
|
||||
* an identifier for the object. This is useful in a context of updating existing entities, without ugly
|
||||
* tricks like setting manually the existing id directly into the entity
|
||||
*
|
||||
* @param array $data The data that may contain identifiers keys
|
||||
* @param object $object
|
||||
* @return object
|
||||
*/
|
||||
protected function tryConvertArrayToObject($data, $object)
|
||||
{
|
||||
$metadata = $this->metadata;
|
||||
$identifierNames = $metadata->getIdentifierFieldNames($object);
|
||||
$identifierValues = [];
|
||||
|
||||
if (empty($identifierNames)) {
|
||||
return $object;
|
||||
}
|
||||
|
||||
foreach ($identifierNames as $identifierName) {
|
||||
if (!isset($data[$identifierName])) {
|
||||
return $object;
|
||||
}
|
||||
|
||||
$identifierValues[$identifierName] = $data[$identifierName];
|
||||
}
|
||||
|
||||
return $this->find($identifierValues, $metadata->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ToOne associations
|
||||
*
|
||||
* When $value is an array but is not the $target's identifiers, $value is
|
||||
* most likely an array of fieldset data. The identifiers will be determined
|
||||
* and a target instance will be initialized and then hydrated. The hydrated
|
||||
* target will be returned.
|
||||
*
|
||||
* @param string $target
|
||||
* @param mixed $value
|
||||
* @return object
|
||||
*/
|
||||
protected function toOne($target, $value)
|
||||
{
|
||||
$metadata = $this->objectManager->getClassMetadata($target);
|
||||
|
||||
if (is_array($value) && array_keys($value) != $metadata->getIdentifier()) {
|
||||
// $value is most likely an array of fieldset data
|
||||
$identifiers = array_intersect_key(
|
||||
$value,
|
||||
array_flip($metadata->getIdentifier())
|
||||
);
|
||||
$object = $this->find($identifiers, $target) ?: new $target;
|
||||
return $this->hydrate($value, $object);
|
||||
}
|
||||
|
||||
return $this->find($value, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ToMany associations. In proper Doctrine design, Collections should not be swapped, so
|
||||
* collections are always handled by reference. Internally, every collection is handled using specials
|
||||
* strategies that inherit from AbstractCollectionStrategy class, and that add or remove elements but without
|
||||
* changing the collection of the object
|
||||
*
|
||||
* @param object $object
|
||||
* @param mixed $collectionName
|
||||
* @param string $target
|
||||
* @param mixed $values
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function toMany($object, $collectionName, $target, $values)
|
||||
{
|
||||
$metadata = $this->objectManager->getClassMetadata(ltrim($target, '\\'));
|
||||
$identifier = $metadata->getIdentifier();
|
||||
|
||||
if (!is_array($values) && !$values instanceof Traversable) {
|
||||
$values = (array)$values;
|
||||
}
|
||||
|
||||
$collection = [];
|
||||
|
||||
// If the collection contains identifiers, fetch the objects from database
|
||||
foreach ($values as $value) {
|
||||
if ($value instanceof $target) {
|
||||
// assumes modifications have already taken place in object
|
||||
$collection[] = $value;
|
||||
continue;
|
||||
} elseif (empty($value)) {
|
||||
// assumes no id and retrieves new $target
|
||||
$collection[] = $this->find($value, $target);
|
||||
continue;
|
||||
}
|
||||
|
||||
$find = [];
|
||||
if (is_array($identifier)) {
|
||||
foreach ($identifier as $field) {
|
||||
switch (gettype($value)) {
|
||||
case 'object':
|
||||
$getter = 'get' . ucfirst($field);
|
||||
if (method_exists($value, $getter)) {
|
||||
$find[$field] = $value->$getter();
|
||||
} elseif (property_exists($value, $field)) {
|
||||
$find[$field] = $value->$field;
|
||||
}
|
||||
break;
|
||||
case 'array':
|
||||
if (array_key_exists($field, $value) && $value[$field] != null) {
|
||||
$find[$field] = $value[$field];
|
||||
unset($value[$field]); // removed identifier from persistable data
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$find[$field] = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($find) && $found = $this->find($find, $target)) {
|
||||
$collection[] = (is_array($value)) ? $this->hydrate($value, $found) : $found;
|
||||
} else {
|
||||
$collection[] = (is_array($value)) ? $this->hydrate($value, new $target) : new $target;
|
||||
}
|
||||
}
|
||||
|
||||
$collection = array_filter(
|
||||
$collection,
|
||||
function ($item) {
|
||||
return null !== $item;
|
||||
}
|
||||
);
|
||||
|
||||
// Set the object so that the strategy can extract the Collection from it
|
||||
|
||||
/** @var \DoctrineModule\Stdlib\Hydrator\Strategy\AbstractCollectionStrategy $collectionStrategy */
|
||||
$collectionStrategy = $this->getStrategy($collectionName);
|
||||
$collectionStrategy->setObject($object);
|
||||
|
||||
// We could directly call hydrate method from the strategy, but if people want to override
|
||||
// hydrateValue function, they can do it and do their own stuff
|
||||
$this->hydrateValue($collectionName, $collection, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle various type conversions that should be supported natively by Doctrine (like DateTime)
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $typeOfField
|
||||
* @return DateTime|DateTimeImmutable
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function handleTypeConversions($value, $typeOfField)
|
||||
{
|
||||
switch ($typeOfField) {
|
||||
case 'datetimetz':
|
||||
case 'datetime':
|
||||
case 'time':
|
||||
case 'date':
|
||||
if ('' === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_int($value)) {
|
||||
$dateTime = new DateTime();
|
||||
$dateTime->setTimestamp($value);
|
||||
$value = $dateTime;
|
||||
} elseif (is_string($value)) {
|
||||
$value = new DateTime($value);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'datetimetz_immutable':
|
||||
case 'datetime_immutable':
|
||||
case 'time_immutable':
|
||||
case 'date_immutable':
|
||||
if ('' === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_int($value)) {
|
||||
$dateTime = new DateTimeImmutable();
|
||||
$dateTime->setTimestamp($value);
|
||||
$value = $dateTime;
|
||||
} elseif (is_string($value)) {
|
||||
$value = new DateTimeImmutable($value);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find an object by a given target class and identifier
|
||||
*
|
||||
* @param mixed $identifiers
|
||||
* @param string $targetClass
|
||||
*
|
||||
* @return object|null
|
||||
*/
|
||||
protected function find($identifiers, $targetClass)
|
||||
{
|
||||
if ($identifiers instanceof $targetClass) {
|
||||
return $identifiers;
|
||||
}
|
||||
|
||||
if ($this->isNullIdentifier($identifiers)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->objectManager->find($targetClass, $identifiers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if a provided identifier is to be considered null
|
||||
*
|
||||
* @param mixed $identifier
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isNullIdentifier($identifier)
|
||||
{
|
||||
if (null === $identifier) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($identifier instanceof Traversable || is_array($identifier)) {
|
||||
$nonNullIdentifiers = array_filter(
|
||||
ArrayUtils::iteratorToArray($identifier),
|
||||
function ($value) {
|
||||
return null !== $value;
|
||||
}
|
||||
);
|
||||
|
||||
return empty($nonNullIdentifiers);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the naming strategy if there is one set
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function computeHydrateFieldName($field)
|
||||
{
|
||||
if ($this->hasNamingStrategy()) {
|
||||
$field = $this->getNamingStrategy()->hydrate($field);
|
||||
}
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the naming strategy if there is one set
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function computeExtractFieldName($field)
|
||||
{
|
||||
if ($this->hasNamingStrategy()) {
|
||||
$field = $this->getNamingStrategy()->extract($field);
|
||||
}
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace DoctrineExpressiveModule\Hydrator;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class DoctrineObjectFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
return new DoctrineObject($em);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace DoctrineExpressiveModule\Hydrator\Filter;
|
||||
|
||||
use Zend\Hydrator\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* Provides a filter to restrict returned fields by whitelisting or
|
||||
* blacklisting property names.
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @author Liam O'Boyle <liam@ontheroad.net.nz>
|
||||
*/
|
||||
class PropertyName implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* The propteries to exclude.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $properties = [];
|
||||
|
||||
/**
|
||||
* Either an exclude or an include.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $exclude = null;
|
||||
|
||||
/**
|
||||
* @param [ string | array ] $properties The properties to exclude or include.
|
||||
* @param bool $exclude If the method should be excluded
|
||||
*/
|
||||
public function __construct($properties, $exclude = true)
|
||||
{
|
||||
$this->exclude = $exclude;
|
||||
$this->properties = is_array($properties)
|
||||
? $properties
|
||||
: [$properties];
|
||||
}
|
||||
|
||||
public function filter($property)
|
||||
{
|
||||
return in_array($property, $this->properties)
|
||||
? !$this->exclude
|
||||
: $this->exclude;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace DoctrineExpressiveModule\Hydrator\Strategy;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Zend\Hydrator\Strategy\StrategyInterface;
|
||||
|
||||
/**
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
abstract class AbstractCollectionStrategy implements StrategyInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $collectionName;
|
||||
|
||||
/**
|
||||
* @var ClassMetadata
|
||||
*/
|
||||
protected $metadata;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
|
||||
/**
|
||||
* Set the name of the collection
|
||||
*
|
||||
* @param string $collectionName
|
||||
* @return AbstractCollectionStrategy
|
||||
*/
|
||||
public function setCollectionName($collectionName)
|
||||
{
|
||||
$this->collectionName = (string) $collectionName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCollectionName()
|
||||
{
|
||||
return $this->collectionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class metadata
|
||||
*
|
||||
* @param ClassMetadata $classMetadata
|
||||
* @return AbstractCollectionStrategy
|
||||
*/
|
||||
public function setClassMetadata(ClassMetadata $classMetadata)
|
||||
{
|
||||
$this->metadata = $classMetadata;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class metadata
|
||||
*
|
||||
* @return ClassMetadata
|
||||
*/
|
||||
public function getClassMetadata()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return AbstractCollectionStrategy
|
||||
*/
|
||||
public function setObject($object)
|
||||
{
|
||||
if (!is_object($object)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('The parameter given to setObject method of %s class is not an object', get_called_class())
|
||||
);
|
||||
}
|
||||
|
||||
$this->object = $object;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getObject()
|
||||
{
|
||||
return $this->object;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function extract($value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the collection by value (using the public API)
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
protected function getCollectionFromObjectByValue()
|
||||
{
|
||||
$object = $this->getObject();
|
||||
$getter = 'get' . ucfirst($this->getCollectionName());
|
||||
|
||||
if (!method_exists($object, $getter)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'The getter %s to access collection %s in object %s does not exist',
|
||||
$getter,
|
||||
$this->getCollectionName(),
|
||||
get_class($object)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $object->$getter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the collection by reference (not using the public API)
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
protected function getCollectionFromObjectByReference()
|
||||
{
|
||||
$object = $this->getObject();
|
||||
$refl = $this->getClassMetadata()->getReflectionClass();
|
||||
$reflProperty = $refl->getProperty($this->getCollectionName());
|
||||
|
||||
$reflProperty->setAccessible(true);
|
||||
|
||||
return $reflProperty->getValue($object);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is used internally by array_udiff to check if two objects are equal, according to their
|
||||
* SPL hash. This is needed because the native array_diff only compare strings
|
||||
*
|
||||
* @param object $a
|
||||
* @param object $b
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function compareObjects($a, $b)
|
||||
{
|
||||
return strcmp(spl_object_hash($a), spl_object_hash($b));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace DoctrineExpressiveModule\Hydrator\Strategy;
|
||||
|
||||
/**
|
||||
* When this strategy is used for Collections, if the new collection does not contain elements that are present in
|
||||
* the original collection, then this strategy remove elements from the original collection. For instance, if the
|
||||
* collection initially contains elements A and B, and that the new collection contains elements B and C, then the
|
||||
* final collection will contain elements B and C (while element A will be asked to be removed).
|
||||
*
|
||||
* This strategy is by reference, this means it won't use public API to add/remove elements to the collection
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
class AllowRemoveByReference extends AbstractCollectionStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hydrate($value)
|
||||
{
|
||||
$collection = $this->getCollectionFromObjectByReference();
|
||||
$collectionArray = $collection->toArray();
|
||||
|
||||
$toAdd = array_udiff($value, $collectionArray, [$this, 'compareObjects']);
|
||||
$toRemove = array_udiff($collectionArray, $value, [$this, 'compareObjects']);
|
||||
|
||||
foreach ($toAdd as $element) {
|
||||
$collection->add($element);
|
||||
}
|
||||
|
||||
foreach ($toRemove as $element) {
|
||||
$collection->removeElement($element);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace DoctrineExpressiveModule\Hydrator\Strategy;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use LogicException;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* When this strategy is used for Collections, if the new collection does not contain elements that are present in
|
||||
* the original collection, then this strategy remove elements from the original collection. For instance, if the
|
||||
* collection initially contains elements A and B, and that the new collection contains elements B and C, then the
|
||||
* final collection will contain elements B and C (while element A will be asked to be removed).
|
||||
*
|
||||
* This strategy is by value, this means it will use the public API (in this case, adder and remover)
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
class AllowRemoveByValue extends AbstractCollectionStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hydrate($value)
|
||||
{
|
||||
// AllowRemove strategy need "adder" and "remover"
|
||||
$adder = 'add' . ucfirst($this->collectionName);
|
||||
$remover = 'remove' . ucfirst($this->collectionName);
|
||||
|
||||
if (!method_exists($this->object, $adder) || !method_exists($this->object, $remover)) {
|
||||
throw new LogicException(
|
||||
sprintf(
|
||||
'AllowRemove strategy for DoctrineModule hydrator requires both %s and %s to be defined in %s
|
||||
entity domain code, but one or both seem to be missing',
|
||||
$adder,
|
||||
$remover,
|
||||
get_class($this->object)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$collection = $this->getCollectionFromObjectByValue();
|
||||
|
||||
if ($collection instanceof Collection) {
|
||||
$collection = $collection->toArray();
|
||||
}
|
||||
|
||||
$toAdd = new ArrayCollection(array_udiff($value, $collection, [$this, 'compareObjects']));
|
||||
$toRemove = new ArrayCollection(array_udiff($collection, $value, [$this, 'compareObjects']));
|
||||
|
||||
$this->object->$adder($toAdd);
|
||||
$this->object->$remover($toRemove);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace DoctrineExpressiveModule\Hydrator\Strategy;
|
||||
|
||||
/**
|
||||
* When this strategy is used for Collections, if the new collection does not contain elements that are present in
|
||||
* the original collection, then this strategy will not remove those elements. At most, it will add new elements. For
|
||||
* instance, if the collection initially contains elements A and B, and that the new collection contains elements B
|
||||
* and C, then the final collection will contain elements A, B and C.
|
||||
*
|
||||
* This strategy is by reference, this means it won't use the public API to remove elements
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
class DisallowRemoveByReference extends AbstractCollectionStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hydrate($value)
|
||||
{
|
||||
$collection = $this->getCollectionFromObjectByReference();
|
||||
$collectionArray = $collection->toArray();
|
||||
|
||||
$toAdd = array_udiff($value, $collectionArray, [$this, 'compareObjects']);
|
||||
|
||||
foreach ($toAdd as $element) {
|
||||
$collection->add($element);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace DoctrineExpressiveModule\Hydrator\Strategy;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use LogicException;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* When this strategy is used for Collections, if the new collection does not contain elements that are present in
|
||||
* the original collection, then this strategy will not remove those elements. At most, it will add new elements. For
|
||||
* instance, if the collection initially contains elements A and B, and that the new collection contains elements B
|
||||
* and C, then the final collection will contain elements A, B and C.
|
||||
*
|
||||
* This strategy is by value, this means it will use the public API (in this case, remover)
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
class DisallowRemoveByValue extends AbstractCollectionStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hydrate($value)
|
||||
{
|
||||
// AllowRemove strategy need "adder"
|
||||
$adder = 'add' . ucfirst($this->collectionName);
|
||||
|
||||
if (!method_exists($this->object, $adder)) {
|
||||
throw new LogicException(
|
||||
sprintf(
|
||||
'DisallowRemove strategy for DoctrineModule hydrator requires %s to
|
||||
be defined in %s entity domain code, but it seems to be missing',
|
||||
$adder,
|
||||
get_class($this->object)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$collection = $this->getCollectionFromObjectByValue();
|
||||
|
||||
if ($collection instanceof Collection) {
|
||||
$collection = $collection->toArray();
|
||||
}
|
||||
|
||||
$toAdd = new ArrayCollection(array_udiff($value, $collection, [$this, 'compareObjects']));
|
||||
|
||||
$this->object->$adder($toAdd);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
43
src/DoctrineExpressiveModule/Validator/NoObjectExists.php
Normal file
43
src/DoctrineExpressiveModule/Validator/NoObjectExists.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace DoctrineModule\Validator;
|
||||
|
||||
/**
|
||||
* Class that validates if objects does not exist in a given repository with a given list of matched fields
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.4.0
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
*/
|
||||
class NoObjectExists extends ObjectExists
|
||||
{
|
||||
/**
|
||||
* Error constants
|
||||
*/
|
||||
const ERROR_OBJECT_FOUND = 'objectFound';
|
||||
|
||||
/**
|
||||
* @var array Message templates
|
||||
*/
|
||||
protected $messageTemplates = [
|
||||
self::ERROR_OBJECT_FOUND => "An object matching '%value%' was found",
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
$cleanedValue = $this->cleanSearchValue($value);
|
||||
$match = $this->objectRepository->findOneBy($cleanedValue);
|
||||
|
||||
if (is_object($match)) {
|
||||
$this->error(self::ERROR_OBJECT_FOUND, $value);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
175
src/DoctrineExpressiveModule/Validator/ObjectExists.php
Normal file
175
src/DoctrineExpressiveModule/Validator/ObjectExists.php
Normal file
@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace DoctrineModule\Validator;
|
||||
|
||||
use Zend\Validator\AbstractValidator;
|
||||
use Zend\Validator\Exception;
|
||||
use Doctrine\Common\Persistence\ObjectRepository;
|
||||
use Zend\Stdlib\ArrayUtils;
|
||||
|
||||
/**
|
||||
* Class that validates if objects exist in a given repository with a given list of matched fields
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.4.0
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
*/
|
||||
class ObjectExists extends AbstractValidator
|
||||
{
|
||||
/**
|
||||
* Error constants
|
||||
*/
|
||||
const ERROR_NO_OBJECT_FOUND = 'noObjectFound';
|
||||
|
||||
/**
|
||||
* @var array Message templates
|
||||
*/
|
||||
protected $messageTemplates = [
|
||||
self::ERROR_NO_OBJECT_FOUND => "No object matching '%value%' was found",
|
||||
];
|
||||
|
||||
/**
|
||||
* ObjectRepository from which to search for entities
|
||||
*
|
||||
* @var ObjectRepository
|
||||
*/
|
||||
protected $objectRepository;
|
||||
|
||||
/**
|
||||
* Fields to be checked
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fields;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options required keys are `object_repository`, which must be an instance of
|
||||
* Doctrine\Common\Persistence\ObjectRepository, and `fields`, with either
|
||||
* a string or an array of strings representing the fields to be matched by the validator.
|
||||
* @throws \Zend\Validator\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function __construct(array $options)
|
||||
{
|
||||
if (! isset($options['object_repository']) || ! $options['object_repository'] instanceof ObjectRepository) {
|
||||
if (! array_key_exists('object_repository', $options)) {
|
||||
$provided = 'nothing';
|
||||
} else {
|
||||
if (is_object($options['object_repository'])) {
|
||||
$provided = get_class($options['object_repository']);
|
||||
} else {
|
||||
$provided = getType($options['object_repository']);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception\InvalidArgumentException(
|
||||
sprintf(
|
||||
'Option "object_repository" is required and must be an instance of'
|
||||
. ' Doctrine\Common\Persistence\ObjectRepository, %s given',
|
||||
$provided
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->objectRepository = $options['object_repository'];
|
||||
|
||||
if (! isset($options['fields'])) {
|
||||
throw new Exception\InvalidArgumentException(
|
||||
'Key `fields` must be provided and be a field or a list of fields to be used when searching for'
|
||||
. ' existing instances'
|
||||
);
|
||||
}
|
||||
|
||||
$this->fields = $options['fields'];
|
||||
$this->validateFields();
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters and validates the fields passed to the constructor
|
||||
*
|
||||
* @throws \Zend\Validator\Exception\InvalidArgumentException
|
||||
* @return array
|
||||
*/
|
||||
private function validateFields()
|
||||
{
|
||||
$fields = (array) $this->fields;
|
||||
|
||||
if (empty($fields)) {
|
||||
throw new Exception\InvalidArgumentException('Provided fields list was empty!');
|
||||
}
|
||||
|
||||
foreach ($fields as $key => $field) {
|
||||
if (! is_string($field)) {
|
||||
throw new Exception\InvalidArgumentException(
|
||||
sprintf('Provided fields must be strings, %s provided for key %s', gettype($field), $key)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->fields = array_values($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $value a field value or an array of field values if more fields have been configured to be
|
||||
* matched
|
||||
* @return array
|
||||
* @throws \Zend\Validator\Exception\RuntimeException
|
||||
*/
|
||||
protected function cleanSearchValue($value)
|
||||
{
|
||||
$value = is_object($value) ? [$value] : (array) $value;
|
||||
|
||||
if (ArrayUtils::isHashTable($value)) {
|
||||
$matchedFieldsValues = [];
|
||||
|
||||
foreach ($this->fields as $field) {
|
||||
if (! array_key_exists($field, $value)) {
|
||||
throw new Exception\RuntimeException(
|
||||
sprintf(
|
||||
'Field "%s" was not provided, but was expected since the configured field lists needs'
|
||||
. ' it for validation',
|
||||
$field
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$matchedFieldsValues[$field] = $value[$field];
|
||||
}
|
||||
} else {
|
||||
$matchedFieldsValues = @array_combine($this->fields, $value);
|
||||
|
||||
if (false === $matchedFieldsValues) {
|
||||
throw new Exception\RuntimeException(
|
||||
sprintf(
|
||||
'Provided values count is %s, while expected number of fields to be matched is %s',
|
||||
count($value),
|
||||
count($this->fields)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $matchedFieldsValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
$cleanedValue = $this->cleanSearchValue($value);
|
||||
$match = $this->objectRepository->findOneBy($cleanedValue);
|
||||
|
||||
if (is_object($match)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->error(self::ERROR_NO_OBJECT_FOUND, $value);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user