* removed test items, and added "person"
This commit is contained in:
parent
94d05cf890
commit
bcf87d3cdc
@ -21,7 +21,7 @@ return [
|
||||
Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
|
||||
'doctrine.entity_manager.orm_default' => \ContainerInteropDoctrine\EntityManagerFactory::class,
|
||||
'doctrine.hydrator' => \App\Hydrator\DoctrineObjectFactory::class,
|
||||
\App\Service\Article\ArticleService::class => \App\Service\Article\ArticleServiceFactory::class,
|
||||
\App\Service\Person\PersonService::class => \App\Service\Person\PersonServiceFactory::class,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@ -8,11 +8,11 @@ return [
|
||||
],
|
||||
'factories' => [
|
||||
App\Action\HomePageAction::class => App\Action\HomePageFactory::class,
|
||||
App\Action\Article\ListAction::class => App\Action\Article\ListFactory::class,
|
||||
App\Action\Article\GetAction::class => App\Action\Article\GetFactory::class,
|
||||
App\Action\Article\PostAction::class => App\Action\Article\PostFactory::class,
|
||||
App\Action\Article\PutAction::class => App\Action\Article\PutFactory::class,
|
||||
App\Action\Article\DeleteAction::class => App\Action\Article\DeleteFactory::class,
|
||||
App\Action\Person\ListAction::class => App\Action\Person\ListFactory::class,
|
||||
App\Action\Person\GetAction::class => App\Action\Person\GetFactory::class,
|
||||
App\Action\Person\PostAction::class => App\Action\Person\PostFactory::class,
|
||||
App\Action\Person\PutAction::class => App\Action\Person\PutFactory::class,
|
||||
App\Action\Person\DeleteAction::class => App\Action\Person\DeleteFactory::class,
|
||||
],
|
||||
],
|
||||
'routes' => [
|
||||
@ -23,33 +23,33 @@ return [
|
||||
'allowed_methods' => ['GET'],
|
||||
],
|
||||
[
|
||||
'name' => 'api.article.list',
|
||||
'path' => '/api/article',
|
||||
'middleware' => App\Action\Article\ListAction::class,
|
||||
'name' => 'api.person.list',
|
||||
'path' => '/api/person',
|
||||
'middleware' => App\Action\Person\ListAction::class,
|
||||
'allowed_methods' => ['GET'],
|
||||
],
|
||||
[
|
||||
'name' => 'api.article.get',
|
||||
'path' => '/api/article/{id:\d+}',
|
||||
'middleware' => App\Action\Article\GetAction::class,
|
||||
'name' => 'api.person.get',
|
||||
'path' => '/api/person/{id:\d+}',
|
||||
'middleware' => App\Action\Person\GetAction::class,
|
||||
'allowed_methods' => ['GET'],
|
||||
],
|
||||
[
|
||||
'name' => 'api.article.add',
|
||||
'path' => '/api/article',
|
||||
'middleware' => App\Action\Article\PostAction::class,
|
||||
'name' => 'api.person.add',
|
||||
'path' => '/api/person',
|
||||
'middleware' => App\Action\Person\PostAction::class,
|
||||
'allowed_methods' => ['POST'],
|
||||
],
|
||||
[
|
||||
'name' => 'api.article.update',
|
||||
'path' => '/api/article/{id:\d+}',
|
||||
'middleware' => App\Action\Article\PutAction::class,
|
||||
'name' => 'api.person.update',
|
||||
'path' => '/api/person/{id:\d+}',
|
||||
'middleware' => App\Action\Person\PutAction::class,
|
||||
'allowed_methods' => ['PUT'],
|
||||
],
|
||||
[
|
||||
'name' => 'api.article.delete',
|
||||
'path' => '/api/article/{id:\d+}',
|
||||
'middleware' => App\Action\Article\DeleteAction::class,
|
||||
'name' => 'api.person.delete',
|
||||
'path' => '/api/person/{id:\d+}',
|
||||
'middleware' => App\Action\Person\DeleteAction::class,
|
||||
'allowed_methods' => ['DELETE'],
|
||||
],
|
||||
[
|
||||
|
||||
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Article;
|
||||
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class DeleteAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityServiceInterface
|
||||
*/
|
||||
private $entityService;
|
||||
|
||||
public function __construct(EntityServiceInterface $entityService)
|
||||
{
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
|
||||
$result = $this->entityService->delete($id);
|
||||
|
||||
$return = new JsonResponse($result);
|
||||
|
||||
if (false === $result) {
|
||||
return $return->withStatus(500, 'Failed to delete record.');
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Article;
|
||||
|
||||
use App\Action\Article\DeleteAction;
|
||||
use App\Service\Article\ArticleService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class DeleteFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(ArticleService::class);
|
||||
return new DeleteAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Article;
|
||||
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class GetAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityServiceInterface
|
||||
*/
|
||||
private $entityService;
|
||||
|
||||
public function __construct(EntityServiceInterface $entityService)
|
||||
{
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
$entity = $this->entityService->get($id);
|
||||
|
||||
if (null === $entity) {
|
||||
$ret = new JsonResponse(false);
|
||||
return $ret->withStatus(404);
|
||||
}
|
||||
|
||||
return new JsonResponse($entity);
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Article;
|
||||
|
||||
use App\Action\Article\GetAction;
|
||||
use App\Service\Article\ArticleService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class GetFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(ArticleService::class);
|
||||
return new GetAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Article;
|
||||
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class ListAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityServiceInterface
|
||||
*/
|
||||
private $entityService;
|
||||
|
||||
public function __construct(EntityServiceInterface $entityService)
|
||||
{
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
return new JsonResponse($this->entityService->getList());
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Article;
|
||||
|
||||
use App\Action\Article\ListAction;
|
||||
use App\Service\Article\ArticleService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class ListFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(ArticleService::class);
|
||||
return new ListAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Article;
|
||||
|
||||
use App\Action\AbstractFormAction;
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class PostAction extends AbstractFormAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityServiceInterface
|
||||
*/
|
||||
private $entityService;
|
||||
|
||||
public function __construct(EntityServiceInterface $entityService)
|
||||
{
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
$data = $this->getRequestData($request);
|
||||
|
||||
$result = $this->entityService->create($data);
|
||||
|
||||
if (false === $result) {
|
||||
$result = new JsonResponse(false);
|
||||
return $result->withStatus(500, 'Failed to insert record.');
|
||||
}
|
||||
|
||||
return new JsonResponse($result);
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Article;
|
||||
|
||||
use App\Action\Article\PostAction;
|
||||
use App\Service\Article\ArticleService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class PostFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(ArticleService::class);
|
||||
return new PostAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Article;
|
||||
|
||||
use App\Action\AbstractFormAction;
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class PutAction extends AbstractFormAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityServiceInterface
|
||||
*/
|
||||
private $entityService;
|
||||
|
||||
public function __construct(EntityServiceInterface $entityService)
|
||||
{
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
$data = $this->getRequestData($request);
|
||||
|
||||
$result = $this->entityService->modify($id, $data);
|
||||
|
||||
if (false === $result) {
|
||||
$result = new JsonResponse(false);
|
||||
return $result->withStatus(500, 'Failed to update record.');
|
||||
}
|
||||
|
||||
return new JsonResponse($result);
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Article;
|
||||
|
||||
use App\Action\Article\PutAction;
|
||||
use App\Service\Article\ArticleService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class PutFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(ArticleService::class);
|
||||
return new PutAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Comment;
|
||||
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class DeleteAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityServiceInterface
|
||||
*/
|
||||
private $entityService;
|
||||
|
||||
public function __construct(EntityServiceInterface $entityService)
|
||||
{
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
|
||||
$result = $this->entityService->delete($id);
|
||||
|
||||
$return = new JsonResponse($result);
|
||||
|
||||
if (false === $result) {
|
||||
return $return->withStatus(500, 'Failed to delete record.');
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Comment;
|
||||
|
||||
use App\Action\Article\DeleteAction;
|
||||
use App\Service\Article\CommentService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class DeleteFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(CommentService::class);
|
||||
return new DeleteAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Comment;
|
||||
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class GetAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityServiceInterface
|
||||
*/
|
||||
private $entityService;
|
||||
|
||||
public function __construct(EntityServiceInterface $entityService)
|
||||
{
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
$entity = $this->entityService->get($id);
|
||||
|
||||
if (null === $entity) {
|
||||
$ret = new JsonResponse(false);
|
||||
return $ret->withStatus(404);
|
||||
}
|
||||
|
||||
return new JsonResponse($entity);
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Comment;
|
||||
|
||||
use App\Action\Article\GetAction;
|
||||
use App\Service\Article\CommentService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class GetFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(CommentService::class);
|
||||
return new GetAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Comment;
|
||||
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class ListAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityServiceInterface
|
||||
*/
|
||||
private $entityService;
|
||||
|
||||
public function __construct(EntityServiceInterface $entityService)
|
||||
{
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
return new JsonResponse($this->entityService->getList());
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Comment;
|
||||
|
||||
use App\Action\Article\ListAction;
|
||||
use App\Service\Article\CommentService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class ListFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(CommentService::class);
|
||||
return new ListAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Comment;
|
||||
|
||||
use App\Action\AbstractFormAction;
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class PostAction extends AbstractFormAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityServiceInterface
|
||||
*/
|
||||
private $entityService;
|
||||
|
||||
public function __construct(EntityServiceInterface $entityService)
|
||||
{
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
$data = $this->getRequestData($request);
|
||||
|
||||
$result = $this->entityService->create($data);
|
||||
|
||||
if (false === $result) {
|
||||
$result = new JsonResponse(false);
|
||||
return $result->withStatus(500, 'Failed to insert record.');
|
||||
}
|
||||
|
||||
return new JsonResponse($result);
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Comment;
|
||||
|
||||
use App\Action\Article\PostAction;
|
||||
use App\Service\Article\CommentService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class PostFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(CommentService::class);
|
||||
return new PostAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Comment;
|
||||
|
||||
use App\Action\AbstractFormAction;
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class PutAction extends AbstractFormAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityServiceInterface
|
||||
*/
|
||||
private $entityService;
|
||||
|
||||
public function __construct(EntityServiceInterface $entityService)
|
||||
{
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
$data = $this->getRequestData($request);
|
||||
|
||||
$result = $this->entityService->modify($id, $data);
|
||||
|
||||
if (false === $result) {
|
||||
$result = new JsonResponse(false);
|
||||
return $result->withStatus(500, 'Failed to update record.');
|
||||
}
|
||||
|
||||
return new JsonResponse($result);
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Comment;
|
||||
|
||||
use App\Action\Article\PutAction;
|
||||
use App\Service\Article\CommentService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class PutFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(CommentService::class);
|
||||
return new PutAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Action\Person;
|
||||
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Action\Person;
|
||||
|
||||
use App\Action\Article\DeleteAction;
|
||||
use App\Service\Article\UserService;
|
||||
use App\Service\Article\PersonService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class DeleteFactory
|
||||
@ -11,7 +11,7 @@ class DeleteFactory
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(UserService::class);
|
||||
$entityService = $container->get(PersonService::class);
|
||||
return new DeleteAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Action\Person;
|
||||
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Action\Person;
|
||||
|
||||
use App\Action\Article\GetAction;
|
||||
use App\Service\Article\UserService;
|
||||
use App\Action\Person\GetAction;
|
||||
use App\Service\Person\PersonService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class GetFactory
|
||||
@ -11,7 +11,7 @@ class GetFactory
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(UserService::class);
|
||||
$entityService = $container->get(PersonService::class);
|
||||
return new GetAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Action\Person;
|
||||
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Action\Person;
|
||||
|
||||
use App\Action\Article\ListAction;
|
||||
use App\Service\Article\UserService;
|
||||
use App\Action\Person\ListAction;
|
||||
use App\Service\Person\PersonService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class ListFactory
|
||||
@ -11,7 +11,7 @@ class ListFactory
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(UserService::class);
|
||||
$entityService = $container->get(PersonService::class);
|
||||
return new ListAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Action\Person;
|
||||
|
||||
use App\Action\AbstractFormAction;
|
||||
use App\Service\EntityServiceInterface;
|
||||
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Action\Person;
|
||||
|
||||
use App\Action\Article\PostAction;
|
||||
use App\Service\Article\UserService;
|
||||
use App\Action\Person\PostAction;
|
||||
use App\Service\Person\PersonService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class PostFactory
|
||||
@ -11,7 +11,7 @@ class PostFactory
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(UserService::class);
|
||||
$entityService = $container->get(PersonService::class);
|
||||
return new PostAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Action\Person;
|
||||
|
||||
use App\Action\AbstractFormAction;
|
||||
use App\Service\EntityServiceInterface;
|
||||
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Action\Person;
|
||||
|
||||
use App\Action\Article\PutAction;
|
||||
use App\Service\Article\UserService;
|
||||
use App\Action\Person\PutAction;
|
||||
use App\Service\Person\PersonService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class PutFactory
|
||||
@ -11,7 +11,7 @@ class PutFactory
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$entityService = $container->get(UserService::class);
|
||||
$entityService = $container->get(PersonService::class);
|
||||
return new PutAction($entityService);
|
||||
}
|
||||
}
|
||||
@ -1,182 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="article")
|
||||
*/
|
||||
class Article implements JsonSerializable
|
||||
{
|
||||
|
||||
use Traits\GetterSetter;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="title", type="string", length=255)
|
||||
* @var string
|
||||
*/
|
||||
private $title = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="content", type="string", length=65535)
|
||||
* @var string
|
||||
*/
|
||||
private $content = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="articles")
|
||||
* @ORM\JoinColumn(name="author_id", referencedColumnName="id")
|
||||
* @var User
|
||||
*/
|
||||
private $author = null;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Comment", mappedBy="article")
|
||||
* @ORM\JoinColumn(name="id", referencedColumnName="article_id", nullable=false)
|
||||
* @var Comment[]
|
||||
*/
|
||||
private $comments;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="visible", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
private $visible = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->comments = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getAuthor()
|
||||
{
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Comment[]
|
||||
*/
|
||||
public function getComments()
|
||||
{
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getVisible()
|
||||
{
|
||||
return $this->visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Article
|
||||
*/
|
||||
public function setId(int $id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @return Article
|
||||
*/
|
||||
public function setTitle(string $title)
|
||||
{
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @return Article
|
||||
*/
|
||||
public function setContent(string $content)
|
||||
{
|
||||
$this->content = $content;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $author
|
||||
* @return Article
|
||||
*/
|
||||
public function setAuthor(User $author)
|
||||
{
|
||||
$this->author = $author;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Comment[] $comments
|
||||
* @return Article
|
||||
*/
|
||||
public function setComments(array $comments)
|
||||
{
|
||||
$this->comments = $comments;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $visible
|
||||
* @return Article
|
||||
*/
|
||||
public function setVisible(bool $visible)
|
||||
{
|
||||
$this->visible = $visible;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'content' => $this->content,
|
||||
'author' => $this->author,
|
||||
'comments' => $this->comments,
|
||||
'visible' => $this->visible,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -1,180 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use DateTime;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="comment")
|
||||
*/
|
||||
class Comment implements JsonSerializable
|
||||
{
|
||||
|
||||
use Traits\GetterSetter;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="content", type="string", length=65535)
|
||||
* @var string
|
||||
*/
|
||||
private $content = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="created_at", type="datetime")
|
||||
* @var DateTime
|
||||
*/
|
||||
private $createdAt = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Article", inversedBy="comments")
|
||||
* @ORM\JoinColumn(name="article_id", referencedColumnName="id")
|
||||
* @var Article
|
||||
*/
|
||||
private $article = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="comments")
|
||||
* @ORM\JoinColumn(name="author_id", referencedColumnName="id")
|
||||
* @var User
|
||||
*/
|
||||
private $author = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="visible", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
private $visible = true;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Article
|
||||
*/
|
||||
public function getArticle()
|
||||
{
|
||||
return $this->article;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getAuthor()
|
||||
{
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getVisible()
|
||||
{
|
||||
return $this->visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Comment
|
||||
*/
|
||||
public function setId(int $id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @return Comment
|
||||
*/
|
||||
public function setContent(string $content)
|
||||
{
|
||||
$this->content = $content;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $createdAt
|
||||
* @return Comment
|
||||
*/
|
||||
public function setCreatedAt(DateTime $createdAt)
|
||||
{
|
||||
$this->createdAt = clone $createdAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Article $article
|
||||
* @return Comment
|
||||
*/
|
||||
public function setArticle(Article $article)
|
||||
{
|
||||
$this->article = $article;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $author
|
||||
* @return Comment
|
||||
*/
|
||||
public function setAuthor(User $author)
|
||||
{
|
||||
$this->author = $author;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $visible
|
||||
* @return Comment
|
||||
*/
|
||||
public function setVisible(bool $visible)
|
||||
{
|
||||
$this->visible = $visible;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'content' => $this->content,
|
||||
'createdAt' => $this->createdAt,
|
||||
'author' => $this->author,
|
||||
'article' => $this->article,
|
||||
'visible' => $this->visible,
|
||||
];
|
||||
}
|
||||
}
|
||||
387
src/App/Entity/Person.php
Normal file
387
src/App/Entity/Person.php
Normal file
@ -0,0 +1,387 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="person")
|
||||
*/
|
||||
class Person implements JsonSerializable
|
||||
{
|
||||
|
||||
use Traits\GetterSetter;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="person_id", type="string", length=7, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $personId;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="first_name", type="string", length=150, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $firstName;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="middle_name", type="string", length=150)
|
||||
* @var string
|
||||
*/
|
||||
private $middleName;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="last_name", type="string", length=150, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $lastName;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="gender", type="smallint", nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $gender;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="date_of_birth", type="date", nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $dateOfBirth;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="place_of_birth", type="string", length=150, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $placeOfBirth;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="primary_language", type="string", length=150)
|
||||
* @var string
|
||||
*/
|
||||
private $primaryLanguage;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="address", type="string", length=255)
|
||||
* @var string
|
||||
*/
|
||||
private $address;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Person")
|
||||
* @ORM\JoinColumn(name="mother_id", referencedColumnName="id")
|
||||
*/
|
||||
private $mother;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Person")
|
||||
* @ORM\JoinColumn(name="father_id", referencedColumnName="id")
|
||||
*/
|
||||
private $father;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="email", type="string", length=150)
|
||||
* @var string
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="active", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
private $active = true;
|
||||
|
||||
/*
|
||||
public function __construct()
|
||||
{
|
||||
$this->schools = new ArrayCollection();
|
||||
$this->schools = new ArrayCollection();
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPersonId()
|
||||
{
|
||||
return $this->personId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMiddleName()
|
||||
{
|
||||
return $this->middleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getGender()
|
||||
{
|
||||
return $this->gender;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return datetime
|
||||
*/
|
||||
public function getDateOfBirth()
|
||||
{
|
||||
return $this->dateOfBirth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPlaceOfBirth()
|
||||
{
|
||||
return $this->placeOfBirth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPrimaryLanguage()
|
||||
{
|
||||
return $this->primaryLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAddress()
|
||||
{
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Person
|
||||
*/
|
||||
public function getMorher()
|
||||
{
|
||||
return $this->mother;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Person
|
||||
*/
|
||||
public function getFather()
|
||||
{
|
||||
return $this->father;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getActive()
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return User
|
||||
*/
|
||||
public function setId(int $id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $personId
|
||||
* @return User
|
||||
*/
|
||||
public function setPersonId(string $personId)
|
||||
{
|
||||
$this->personId = $personId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $firstName
|
||||
* @return User
|
||||
*/
|
||||
public function setFirstName(string $firstName)
|
||||
{
|
||||
$this->firstName = $firstName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $middleName
|
||||
* @return User
|
||||
*/
|
||||
public function setMiddleName(string $middleName)
|
||||
{
|
||||
$this->middleName = $middleName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $lastName
|
||||
* @return User
|
||||
*/
|
||||
public function setLastName(string $lastName)
|
||||
{
|
||||
$this->lastName = $lastName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $gender
|
||||
* @return User
|
||||
*/
|
||||
public function setGender(int $gender)
|
||||
{
|
||||
$this->gender = $gender;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param datetime $dateOfBirth
|
||||
* @return User
|
||||
*/
|
||||
public function setDateOfBirth(datetime $dateOfBirth)
|
||||
{
|
||||
$this->dateOfBirth = $dateOfBirth;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $placeOfBirth
|
||||
* @return User
|
||||
*/
|
||||
public function setPlaceOfBirth(string $placeOfBirth)
|
||||
{
|
||||
$this->placeOfBirth = $placeOfBirth;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $primaryLanguage
|
||||
* @return User
|
||||
*/
|
||||
public function setPrimaryLanguage(string $primaryLanguage)
|
||||
{
|
||||
$this->primaryLanguage = $primaryLanguage;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $address
|
||||
* @return User
|
||||
*/
|
||||
public function setAddress(string $address)
|
||||
{
|
||||
$this->address = $address;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Person $mother
|
||||
* @return User
|
||||
*/
|
||||
public function setMother(Person $mother)
|
||||
{
|
||||
$this->mother = $mother;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Person $father
|
||||
* @return User
|
||||
*/
|
||||
public function setFather(Person $father)
|
||||
{
|
||||
$this->father = $father;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return User
|
||||
*/
|
||||
public function setEmail(string $email)
|
||||
{
|
||||
$this->email = $email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $active
|
||||
* @return User
|
||||
*/
|
||||
public function setActive(bool $active)
|
||||
{
|
||||
$this->active = $active;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'personId' => $this->personId,
|
||||
'firstName' => $this->firstName,
|
||||
'middleName' => $this->middleName,
|
||||
'lastName' => $this->lastName,
|
||||
'gender' => $this->gender,
|
||||
'dateOfBirth' => $this->dateOfBirth,
|
||||
'placeOfBirth' => $this->placeOfBirth,
|
||||
'primaryLanguage' => $this->primaryLanguage,
|
||||
'address' => $this->address,
|
||||
'mother' => $this->mother,
|
||||
'father' => $this->father,
|
||||
'email' => $this->email,
|
||||
'active' => $this->active,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -1,186 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="user")
|
||||
*/
|
||||
class User implements JsonSerializable
|
||||
{
|
||||
|
||||
use Traits\GetterSetter;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="name", type="string", length=150)
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="email", type="string", length=255)
|
||||
* @var string
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Article", mappedBy="author")
|
||||
* @ORM\JoinColumn(name="id", referencedColumnName="author_id", nullable=false)
|
||||
* @var Article[]
|
||||
*/
|
||||
private $articles;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Comment", mappedBy="author")
|
||||
* @ORM\JoinColumn(name="id", referencedColumnName="author_id", nullable=false)
|
||||
* @var Comment[]
|
||||
*/
|
||||
private $comments;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="active", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
private $active = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->articles = new ArrayCollection();
|
||||
$this->comments = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Article[]
|
||||
*/
|
||||
public function getArticles()
|
||||
{
|
||||
return $this->articles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Comment[]
|
||||
*/
|
||||
public function getComments()
|
||||
{
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getActive()
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return User
|
||||
*/
|
||||
public function setId(int $id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return User
|
||||
*/
|
||||
public function setName(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return User
|
||||
*/
|
||||
public function setEmail(string $email)
|
||||
{
|
||||
$this->email = $email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Article[] $articles
|
||||
* @return User
|
||||
*/
|
||||
public function setArticles(array $articles)
|
||||
{
|
||||
$this->articles = $articles;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Comment[] $comments
|
||||
* @return User
|
||||
*/
|
||||
public function setComments(array $comments)
|
||||
{
|
||||
$this->comments = $comments;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $active
|
||||
* @return User
|
||||
*/
|
||||
public function setActive(bool $active)
|
||||
{
|
||||
$this->active = $active;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'articles' => $this->articles,
|
||||
'comments' => $this->comments,
|
||||
'active' => $this->active,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Article;
|
||||
|
||||
use App\Entity\Article;
|
||||
use App\Hydrator\DoctrineObject;
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Query;
|
||||
use Exception;
|
||||
|
||||
class ArticleService implements EntityServiceInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* @var DoctrineObject
|
||||
*/
|
||||
private $hydrator;
|
||||
|
||||
public function __construct(EntityManager $em, DoctrineObject $hydrator)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->hydrator = $hydrator;
|
||||
}
|
||||
|
||||
public function getList()
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
$entities = $qb->select('a,u,c')
|
||||
->from(Article::class, 'a')
|
||||
->leftJoin('a.author', 'u')
|
||||
->leftJoin('a.comments', 'c')
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
|
||||
$entity = $qb->select('a,u,c')
|
||||
->from(Article::class, 'a')
|
||||
->leftJoin('a.author', 'u')
|
||||
->leftJoin('a.comments', 'c')
|
||||
->where('a.id = :aid')
|
||||
->setParameter('aid', $id)
|
||||
->getQuery()
|
||||
->getOneOrNullResult(Query::HYDRATE_ARRAY);
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function create($data)
|
||||
{
|
||||
$entity = $this->hydrator->hydrate($data, new Article());
|
||||
try {
|
||||
$this->em->persist($entity);
|
||||
$this->em->flush();
|
||||
} catch (Exception $ex) {
|
||||
return false;
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function modify($id, $data)
|
||||
{
|
||||
if (null === ($entity = $this->em->find(Article::class, $id))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$entity = $this->hydrator->hydrate($data, $entity);
|
||||
$this->em->persist($entity);
|
||||
$this->em->flush();
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
if (null === ($entity = $this->em->find(Article::class, $id))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->em->remove($entity);
|
||||
$this->em->flush();
|
||||
} catch (Exception $ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Article;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class ArticleServiceFactory extends \App\Service\AbstractEntityServiceFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$em = $this->getEntityManager($container);
|
||||
$hydrator = $this->getDoctrineHydrator($container);
|
||||
return new ArticleService($em, $hydrator);
|
||||
}
|
||||
}
|
||||
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Comment;
|
||||
|
||||
use App\Entity\Comment;
|
||||
use App\Hydrator\DoctrineObject;
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Query;
|
||||
use Exception;
|
||||
|
||||
class CommentService implements EntityServiceInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* @var DoctrineObject
|
||||
*/
|
||||
private $hydrator;
|
||||
|
||||
public function __construct(EntityManager $em, DoctrineObject $hydrator)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->hydrator = $hydrator;
|
||||
}
|
||||
|
||||
public function getList()
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
$entities = $qb->select('c,u,a')
|
||||
->from(Comment::class, 'c')
|
||||
->leftJoin('c.author', 'u')
|
||||
->leftJoin('c.article', 'a')
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
|
||||
$entity = $qb->select('c,u,a')
|
||||
->from(Comment::class, 'c')
|
||||
->leftJoin('c.author', 'u')
|
||||
->leftJoin('c.article', 'a')
|
||||
->where('c.id = :cid')
|
||||
->setParameter('cid', $id)
|
||||
->getQuery()
|
||||
->getOneOrNullResult(Query::HYDRATE_ARRAY);
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function create($data)
|
||||
{
|
||||
$entity = $this->hydrator->hydrate($data, new Comment());
|
||||
try {
|
||||
$this->em->persist($entity);
|
||||
$this->em->flush();
|
||||
} catch (Exception $ex) {
|
||||
return false;
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function modify($id, $data)
|
||||
{
|
||||
if (null === ($entity = $this->em->find(Comment::class, $id))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$entity = $this->hydrator->hydrate($data, $entity);
|
||||
$this->em->persist($entity);
|
||||
$this->em->flush();
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
if (null === ($entity = $this->em->find(Comment::class, $id))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->em->remove($entity);
|
||||
$this->em->flush();
|
||||
} catch (Exception $ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Comment;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class ArticleServiceFactory extends \App\Service\AbstractEntityServiceFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$em = $this->getEntityManager($container);
|
||||
$hydrator = $this->getDoctrineHydrator($container);
|
||||
return new CommentService($em, $hydrator);
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\User;
|
||||
namespace App\Service\Person;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Person;
|
||||
use App\Hydrator\DoctrineObject;
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Query;
|
||||
use Exception;
|
||||
|
||||
class UserService implements EntityServiceInterface
|
||||
class PersonService implements EntityServiceInterface
|
||||
{
|
||||
|
||||
/**
|
||||
@ -31,10 +31,8 @@ class UserService implements EntityServiceInterface
|
||||
public function getList()
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
$entities = $qb->select('u,a,c')
|
||||
->from(User::class, 'u')
|
||||
->leftJoin('u.articles', 'a')
|
||||
->leftJoin('u.comments', 'c')
|
||||
$entities = $qb->select('p')
|
||||
->from(Person::class, 'p')
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
return $entities;
|
||||
@ -44,12 +42,10 @@ class UserService implements EntityServiceInterface
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
|
||||
$entity = $qb->select('u,a,c')
|
||||
->from(User::class, 'u')
|
||||
->leftJoin('u.articles', 'a')
|
||||
->leftJoin('u.comments', 'c')
|
||||
->where('u.id = :uid')
|
||||
->setParameter('uid', $id)
|
||||
$entity = $qb->select('p')
|
||||
->from(Person::class, 'p')
|
||||
->where('p.id = :id')
|
||||
->setParameter('id', $id)
|
||||
->getQuery()
|
||||
->getOneOrNullResult(Query::HYDRATE_ARRAY);
|
||||
|
||||
@ -58,7 +54,7 @@ class UserService implements EntityServiceInterface
|
||||
|
||||
public function create($data)
|
||||
{
|
||||
$entity = $this->hydrator->hydrate($data, new User());
|
||||
$entity = $this->hydrator->hydrate($data, new Person());
|
||||
try {
|
||||
$this->em->persist($entity);
|
||||
$this->em->flush();
|
||||
@ -70,7 +66,7 @@ class UserService implements EntityServiceInterface
|
||||
|
||||
public function modify($id, $data)
|
||||
{
|
||||
if (null === ($entity = $this->em->find(User::class, $id))) {
|
||||
if (null === ($entity = $this->em->find(Person::class, $id))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -83,7 +79,7 @@ class UserService implements EntityServiceInterface
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
if (null === ($entity = $this->em->find(User::class, $id))) {
|
||||
if (null === ($entity = $this->em->find(Person::class, $id))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\User;
|
||||
namespace App\Service\Person;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class UserServiceFactory extends \App\Service\AbstractEntityServiceFactory
|
||||
class PersonServiceFactory extends \App\Service\AbstractEntityServiceFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$em = $this->getEntityManager($container);
|
||||
$hydrator = $this->getDoctrineHydrator($container);
|
||||
return new userService($em, $hydrator);
|
||||
return new PersonService($em, $hydrator);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user