From bcf87d3cdc34477baa1543e4968d241de13db239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danyi=20D=C3=A1vid?= Date: Mon, 15 Aug 2016 23:30:13 +0200 Subject: [PATCH] * removed test items, and added "person" --- config/autoload/dependencies.global.php | 2 +- config/autoload/routes.global.php | 40 +- src/App/Action/Article/DeleteAction.php | 37 -- src/App/Action/Article/DeleteFactory.php | 17 - src/App/Action/Article/GetAction.php | 35 -- src/App/Action/Article/GetFactory.php | 17 - src/App/Action/Article/ListAction.php | 27 -- src/App/Action/Article/ListFactory.php | 17 - src/App/Action/Article/PostAction.php | 37 -- src/App/Action/Article/PostFactory.php | 17 - src/App/Action/Article/PutAction.php | 38 -- src/App/Action/Article/PutFactory.php | 17 - src/App/Action/Comment/DeleteAction.php | 37 -- src/App/Action/Comment/DeleteFactory.php | 17 - src/App/Action/Comment/GetAction.php | 35 -- src/App/Action/Comment/GetFactory.php | 17 - src/App/Action/Comment/ListAction.php | 27 -- src/App/Action/Comment/ListFactory.php | 17 - src/App/Action/Comment/PostAction.php | 37 -- src/App/Action/Comment/PostFactory.php | 17 - src/App/Action/Comment/PutAction.php | 38 -- src/App/Action/Comment/PutFactory.php | 17 - .../Action/{User => Person}/DeleteAction.php | 2 +- .../Action/{User => Person}/DeleteFactory.php | 6 +- src/App/Action/{User => Person}/GetAction.php | 2 +- .../Action/{User => Person}/GetFactory.php | 8 +- .../Action/{User => Person}/ListAction.php | 2 +- .../Action/{User => Person}/ListFactory.php | 8 +- .../Action/{User => Person}/PostAction.php | 2 +- .../Action/{User => Person}/PostFactory.php | 8 +- src/App/Action/{User => Person}/PutAction.php | 2 +- .../Action/{User => Person}/PutFactory.php | 8 +- src/App/Entity/Article.php | 182 -------- src/App/Entity/Comment.php | 180 -------- src/App/Entity/Person.php | 387 ++++++++++++++++++ src/App/Entity/User.php | 186 --------- src/App/Service/Article/ArticleService.php | 99 ----- .../Service/Article/ArticleServiceFactory.php | 16 - src/App/Service/Comment/CommentService.php | 99 ----- .../Service/Comment/CommentServiceFactory.php | 16 - .../PersonService.php} | 28 +- .../PersonServiceFactory.php} | 6 +- 42 files changed, 447 insertions(+), 1360 deletions(-) delete mode 100644 src/App/Action/Article/DeleteAction.php delete mode 100644 src/App/Action/Article/DeleteFactory.php delete mode 100644 src/App/Action/Article/GetAction.php delete mode 100644 src/App/Action/Article/GetFactory.php delete mode 100644 src/App/Action/Article/ListAction.php delete mode 100644 src/App/Action/Article/ListFactory.php delete mode 100644 src/App/Action/Article/PostAction.php delete mode 100644 src/App/Action/Article/PostFactory.php delete mode 100644 src/App/Action/Article/PutAction.php delete mode 100644 src/App/Action/Article/PutFactory.php delete mode 100644 src/App/Action/Comment/DeleteAction.php delete mode 100644 src/App/Action/Comment/DeleteFactory.php delete mode 100644 src/App/Action/Comment/GetAction.php delete mode 100644 src/App/Action/Comment/GetFactory.php delete mode 100644 src/App/Action/Comment/ListAction.php delete mode 100644 src/App/Action/Comment/ListFactory.php delete mode 100644 src/App/Action/Comment/PostAction.php delete mode 100644 src/App/Action/Comment/PostFactory.php delete mode 100644 src/App/Action/Comment/PutAction.php delete mode 100644 src/App/Action/Comment/PutFactory.php rename src/App/Action/{User => Person}/DeleteAction.php (96%) rename src/App/Action/{User => Person}/DeleteFactory.php (63%) rename src/App/Action/{User => Person}/GetAction.php (96%) rename src/App/Action/{User => Person}/GetFactory.php (53%) rename src/App/Action/{User => Person}/ListAction.php (95%) rename src/App/Action/{User => Person}/ListFactory.php (53%) rename src/App/Action/{User => Person}/PostAction.php (96%) rename src/App/Action/{User => Person}/PostFactory.php (53%) rename src/App/Action/{User => Person}/PutAction.php (97%) rename src/App/Action/{User => Person}/PutFactory.php (53%) delete mode 100644 src/App/Entity/Article.php delete mode 100644 src/App/Entity/Comment.php create mode 100644 src/App/Entity/Person.php delete mode 100644 src/App/Entity/User.php delete mode 100644 src/App/Service/Article/ArticleService.php delete mode 100644 src/App/Service/Article/ArticleServiceFactory.php delete mode 100644 src/App/Service/Comment/CommentService.php delete mode 100644 src/App/Service/Comment/CommentServiceFactory.php rename src/App/Service/{User/UserService.php => Person/PersonService.php} (68%) rename src/App/Service/{User/UserServiceFactory.php => Person/PersonServiceFactory.php} (60%) diff --git a/config/autoload/dependencies.global.php b/config/autoload/dependencies.global.php index c756a36..e19dac3 100644 --- a/config/autoload/dependencies.global.php +++ b/config/autoload/dependencies.global.php @@ -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, ], ], ]; diff --git a/config/autoload/routes.global.php b/config/autoload/routes.global.php index b8fc18d..aa47f85 100644 --- a/config/autoload/routes.global.php +++ b/config/autoload/routes.global.php @@ -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'], ], [ diff --git a/src/App/Action/Article/DeleteAction.php b/src/App/Action/Article/DeleteAction.php deleted file mode 100644 index 1b67ae8..0000000 --- a/src/App/Action/Article/DeleteAction.php +++ /dev/null @@ -1,37 +0,0 @@ -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; - } -} diff --git a/src/App/Action/Article/DeleteFactory.php b/src/App/Action/Article/DeleteFactory.php deleted file mode 100644 index 4f6f1da..0000000 --- a/src/App/Action/Article/DeleteFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get(ArticleService::class); - return new DeleteAction($entityService); - } -} diff --git a/src/App/Action/Article/GetAction.php b/src/App/Action/Article/GetAction.php deleted file mode 100644 index 44d735b..0000000 --- a/src/App/Action/Article/GetAction.php +++ /dev/null @@ -1,35 +0,0 @@ -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); - } -} diff --git a/src/App/Action/Article/GetFactory.php b/src/App/Action/Article/GetFactory.php deleted file mode 100644 index dafe16b..0000000 --- a/src/App/Action/Article/GetFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get(ArticleService::class); - return new GetAction($entityService); - } -} diff --git a/src/App/Action/Article/ListAction.php b/src/App/Action/Article/ListAction.php deleted file mode 100644 index b9d7ec2..0000000 --- a/src/App/Action/Article/ListAction.php +++ /dev/null @@ -1,27 +0,0 @@ -entityService = $entityService; - } - - public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null) - { - return new JsonResponse($this->entityService->getList()); - } -} diff --git a/src/App/Action/Article/ListFactory.php b/src/App/Action/Article/ListFactory.php deleted file mode 100644 index 2e2549d..0000000 --- a/src/App/Action/Article/ListFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get(ArticleService::class); - return new ListAction($entityService); - } -} diff --git a/src/App/Action/Article/PostAction.php b/src/App/Action/Article/PostAction.php deleted file mode 100644 index 1609ab8..0000000 --- a/src/App/Action/Article/PostAction.php +++ /dev/null @@ -1,37 +0,0 @@ -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); - } -} diff --git a/src/App/Action/Article/PostFactory.php b/src/App/Action/Article/PostFactory.php deleted file mode 100644 index d558193..0000000 --- a/src/App/Action/Article/PostFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get(ArticleService::class); - return new PostAction($entityService); - } -} diff --git a/src/App/Action/Article/PutAction.php b/src/App/Action/Article/PutAction.php deleted file mode 100644 index 37374f0..0000000 --- a/src/App/Action/Article/PutAction.php +++ /dev/null @@ -1,38 +0,0 @@ -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); - } -} diff --git a/src/App/Action/Article/PutFactory.php b/src/App/Action/Article/PutFactory.php deleted file mode 100644 index 6afb465..0000000 --- a/src/App/Action/Article/PutFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get(ArticleService::class); - return new PutAction($entityService); - } -} diff --git a/src/App/Action/Comment/DeleteAction.php b/src/App/Action/Comment/DeleteAction.php deleted file mode 100644 index 232da6e..0000000 --- a/src/App/Action/Comment/DeleteAction.php +++ /dev/null @@ -1,37 +0,0 @@ -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; - } -} diff --git a/src/App/Action/Comment/DeleteFactory.php b/src/App/Action/Comment/DeleteFactory.php deleted file mode 100644 index 268a759..0000000 --- a/src/App/Action/Comment/DeleteFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get(CommentService::class); - return new DeleteAction($entityService); - } -} diff --git a/src/App/Action/Comment/GetAction.php b/src/App/Action/Comment/GetAction.php deleted file mode 100644 index 7bdfee0..0000000 --- a/src/App/Action/Comment/GetAction.php +++ /dev/null @@ -1,35 +0,0 @@ -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); - } -} diff --git a/src/App/Action/Comment/GetFactory.php b/src/App/Action/Comment/GetFactory.php deleted file mode 100644 index 7c6d601..0000000 --- a/src/App/Action/Comment/GetFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get(CommentService::class); - return new GetAction($entityService); - } -} diff --git a/src/App/Action/Comment/ListAction.php b/src/App/Action/Comment/ListAction.php deleted file mode 100644 index fef8b95..0000000 --- a/src/App/Action/Comment/ListAction.php +++ /dev/null @@ -1,27 +0,0 @@ -entityService = $entityService; - } - - public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null) - { - return new JsonResponse($this->entityService->getList()); - } -} diff --git a/src/App/Action/Comment/ListFactory.php b/src/App/Action/Comment/ListFactory.php deleted file mode 100644 index 305f42e..0000000 --- a/src/App/Action/Comment/ListFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get(CommentService::class); - return new ListAction($entityService); - } -} diff --git a/src/App/Action/Comment/PostAction.php b/src/App/Action/Comment/PostAction.php deleted file mode 100644 index 871f684..0000000 --- a/src/App/Action/Comment/PostAction.php +++ /dev/null @@ -1,37 +0,0 @@ -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); - } -} diff --git a/src/App/Action/Comment/PostFactory.php b/src/App/Action/Comment/PostFactory.php deleted file mode 100644 index 582712d..0000000 --- a/src/App/Action/Comment/PostFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get(CommentService::class); - return new PostAction($entityService); - } -} diff --git a/src/App/Action/Comment/PutAction.php b/src/App/Action/Comment/PutAction.php deleted file mode 100644 index 826ad5d..0000000 --- a/src/App/Action/Comment/PutAction.php +++ /dev/null @@ -1,38 +0,0 @@ -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); - } -} diff --git a/src/App/Action/Comment/PutFactory.php b/src/App/Action/Comment/PutFactory.php deleted file mode 100644 index 8da0be7..0000000 --- a/src/App/Action/Comment/PutFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get(CommentService::class); - return new PutAction($entityService); - } -} diff --git a/src/App/Action/User/DeleteAction.php b/src/App/Action/Person/DeleteAction.php similarity index 96% rename from src/App/Action/User/DeleteAction.php rename to src/App/Action/Person/DeleteAction.php index 748c43c..8ae3a48 100644 --- a/src/App/Action/User/DeleteAction.php +++ b/src/App/Action/Person/DeleteAction.php @@ -1,6 +1,6 @@ get(UserService::class); + $entityService = $container->get(PersonService::class); return new DeleteAction($entityService); } } diff --git a/src/App/Action/User/GetAction.php b/src/App/Action/Person/GetAction.php similarity index 96% rename from src/App/Action/User/GetAction.php rename to src/App/Action/Person/GetAction.php index 15b51b2..8443529 100644 --- a/src/App/Action/User/GetAction.php +++ b/src/App/Action/Person/GetAction.php @@ -1,6 +1,6 @@ get(UserService::class); + $entityService = $container->get(PersonService::class); return new GetAction($entityService); } } diff --git a/src/App/Action/User/ListAction.php b/src/App/Action/Person/ListAction.php similarity index 95% rename from src/App/Action/User/ListAction.php rename to src/App/Action/Person/ListAction.php index f727ade..79c5562 100644 --- a/src/App/Action/User/ListAction.php +++ b/src/App/Action/Person/ListAction.php @@ -1,6 +1,6 @@ get(UserService::class); + $entityService = $container->get(PersonService::class); return new ListAction($entityService); } } diff --git a/src/App/Action/User/PostAction.php b/src/App/Action/Person/PostAction.php similarity index 96% rename from src/App/Action/User/PostAction.php rename to src/App/Action/Person/PostAction.php index b6dd119..7a91f3d 100644 --- a/src/App/Action/User/PostAction.php +++ b/src/App/Action/Person/PostAction.php @@ -1,6 +1,6 @@ get(UserService::class); + $entityService = $container->get(PersonService::class); return new PostAction($entityService); } } diff --git a/src/App/Action/User/PutAction.php b/src/App/Action/Person/PutAction.php similarity index 97% rename from src/App/Action/User/PutAction.php rename to src/App/Action/Person/PutAction.php index 6fd60c6..de6873c 100644 --- a/src/App/Action/User/PutAction.php +++ b/src/App/Action/Person/PutAction.php @@ -1,6 +1,6 @@ get(UserService::class); + $entityService = $container->get(PersonService::class); return new PutAction($entityService); } } diff --git a/src/App/Entity/Article.php b/src/App/Entity/Article.php deleted file mode 100644 index cab18a4..0000000 --- a/src/App/Entity/Article.php +++ /dev/null @@ -1,182 +0,0 @@ -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, - ]; - } -} diff --git a/src/App/Entity/Comment.php b/src/App/Entity/Comment.php deleted file mode 100644 index 190ddfb..0000000 --- a/src/App/Entity/Comment.php +++ /dev/null @@ -1,180 +0,0 @@ -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, - ]; - } -} diff --git a/src/App/Entity/Person.php b/src/App/Entity/Person.php new file mode 100644 index 0000000..576c77d --- /dev/null +++ b/src/App/Entity/Person.php @@ -0,0 +1,387 @@ +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, + ]; + } +} \ No newline at end of file diff --git a/src/App/Entity/User.php b/src/App/Entity/User.php deleted file mode 100644 index 1403aaf..0000000 --- a/src/App/Entity/User.php +++ /dev/null @@ -1,186 +0,0 @@ -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, - ]; - } -} diff --git a/src/App/Service/Article/ArticleService.php b/src/App/Service/Article/ArticleService.php deleted file mode 100644 index 5b80c89..0000000 --- a/src/App/Service/Article/ArticleService.php +++ /dev/null @@ -1,99 +0,0 @@ -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; - } -} diff --git a/src/App/Service/Article/ArticleServiceFactory.php b/src/App/Service/Article/ArticleServiceFactory.php deleted file mode 100644 index 89e3fd9..0000000 --- a/src/App/Service/Article/ArticleServiceFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -getEntityManager($container); - $hydrator = $this->getDoctrineHydrator($container); - return new ArticleService($em, $hydrator); - } -} diff --git a/src/App/Service/Comment/CommentService.php b/src/App/Service/Comment/CommentService.php deleted file mode 100644 index 9ebe6d1..0000000 --- a/src/App/Service/Comment/CommentService.php +++ /dev/null @@ -1,99 +0,0 @@ -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; - } -} diff --git a/src/App/Service/Comment/CommentServiceFactory.php b/src/App/Service/Comment/CommentServiceFactory.php deleted file mode 100644 index fcda262..0000000 --- a/src/App/Service/Comment/CommentServiceFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -getEntityManager($container); - $hydrator = $this->getDoctrineHydrator($container); - return new CommentService($em, $hydrator); - } -} diff --git a/src/App/Service/User/UserService.php b/src/App/Service/Person/PersonService.php similarity index 68% rename from src/App/Service/User/UserService.php rename to src/App/Service/Person/PersonService.php index 0a1e444..f47dadd 100644 --- a/src/App/Service/User/UserService.php +++ b/src/App/Service/Person/PersonService.php @@ -1,15 +1,15 @@ 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; } diff --git a/src/App/Service/User/UserServiceFactory.php b/src/App/Service/Person/PersonServiceFactory.php similarity index 60% rename from src/App/Service/User/UserServiceFactory.php rename to src/App/Service/Person/PersonServiceFactory.php index 4278673..41197ab 100644 --- a/src/App/Service/User/UserServiceFactory.php +++ b/src/App/Service/Person/PersonServiceFactory.php @@ -1,16 +1,16 @@ getEntityManager($container); $hydrator = $this->getDoctrineHydrator($container); - return new userService($em, $hydrator); + return new PersonService($em, $hydrator); } }