@@ -9,7 +9,7 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | interface SeedInterface |
| 11 | 11 | { |
| 12 | - static public function build($id = 1); |
|
| 12 | + static public function build($id = 1); |
|
| 13 | 13 | |
| 14 | - static public function reset(); |
|
| 14 | + static public function reset(); |
|
| 15 | 15 | } |
@@ -17,7 +17,6 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * IndexController, constructed by container |
| 19 | 19 | * |
| 20 | - * @param Twig_Environment $twig |
|
| 21 | 20 | */ |
| 22 | 21 | public function __construct( UserList $userListModule) { |
| 23 | 22 | |
@@ -28,7 +27,7 @@ discard block |
||
| 28 | 27 | * Return index page (/) |
| 29 | 28 | * |
| 30 | 29 | * @param array $args |
| 31 | - * @return Response |
|
| 30 | + * @return \Symfony\Component\HttpFoundation\Response |
|
| 32 | 31 | */ |
| 33 | 32 | public function get($args) { |
| 34 | 33 | return $this->render('pages/index.html.twig', [ |
@@ -6,34 +6,34 @@ |
||
| 6 | 6 | |
| 7 | 7 | class IndexController extends BaseController { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * |
|
| 11 | - * @var \Models\User\UserRepository $UserRepository |
|
| 12 | - */ |
|
| 13 | - protected $UserRepository; |
|
| 14 | - |
|
| 15 | - protected $userListModule; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * IndexController, constructed by container |
|
| 19 | - * |
|
| 20 | - * @param Twig_Environment $twig |
|
| 21 | - */ |
|
| 22 | - public function __construct( UserList $userListModule) { |
|
| 23 | - |
|
| 24 | - $this->userListModule = $userListModule; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Return index page (/) |
|
| 29 | - * |
|
| 30 | - * @param array $args |
|
| 31 | - * @return Response |
|
| 32 | - */ |
|
| 33 | - public function get($args) { |
|
| 34 | - return $this->render('pages/index.html.twig', [ |
|
| 35 | - "content" => $this->userListModule->process($args), |
|
| 36 | - ]); |
|
| 37 | - } |
|
| 9 | + /** |
|
| 10 | + * |
|
| 11 | + * @var \Models\User\UserRepository $UserRepository |
|
| 12 | + */ |
|
| 13 | + protected $UserRepository; |
|
| 14 | + |
|
| 15 | + protected $userListModule; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * IndexController, constructed by container |
|
| 19 | + * |
|
| 20 | + * @param Twig_Environment $twig |
|
| 21 | + */ |
|
| 22 | + public function __construct( UserList $userListModule) { |
|
| 23 | + |
|
| 24 | + $this->userListModule = $userListModule; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Return index page (/) |
|
| 29 | + * |
|
| 30 | + * @param array $args |
|
| 31 | + * @return Response |
|
| 32 | + */ |
|
| 33 | + public function get($args) { |
|
| 34 | + return $this->render('pages/index.html.twig', [ |
|
| 35 | + "content" => $this->userListModule->process($args), |
|
| 36 | + ]); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | } |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | * |
| 20 | 20 | * @param Twig_Environment $twig |
| 21 | 21 | */ |
| 22 | - public function __construct( UserList $userListModule) { |
|
| 22 | + public function __construct(UserList $userListModule) { |
|
| 23 | 23 | |
| 24 | 24 | $this->userListModule = $userListModule; |
| 25 | 25 | } |
@@ -9,6 +9,9 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class ModuleController extends BaseController {
|
| 11 | 11 | |
| 12 | + /** |
|
| 13 | + * @param string $view |
|
| 14 | + */ |
|
| 12 | 15 | protected function render($view, array $data = array()) {
|
| 13 | 16 | |
| 14 | 17 | $ref = new \ReflectionClass($this); |
@@ -9,15 +9,15 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class ModuleController extends BaseController {
|
| 11 | 11 | |
| 12 | - protected function render($view, array $data = array()) {
|
|
| 12 | + protected function render($view, array $data = array()) {
|
|
| 13 | 13 | |
| 14 | - $ref = new \ReflectionClass($this); |
|
| 14 | + $ref = new \ReflectionClass($this); |
|
| 15 | 15 | |
| 16 | - $tpl = (new \SplFileInfo($ref->getFileName()))->getPath() . DIRECTORY_SEPARATOR .'tpl'; |
|
| 16 | + $tpl = (new \SplFileInfo($ref->getFileName()))->getPath() . DIRECTORY_SEPARATOR .'tpl'; |
|
| 17 | 17 | |
| 18 | - $twig = new \Twig_Environment(new \Twig_Loader_Filesystem($tpl)); |
|
| 18 | + $twig = new \Twig_Environment(new \Twig_Loader_Filesystem($tpl)); |
|
| 19 | 19 | |
| 20 | - return $twig->render($view . '.twig',$data); |
|
| 21 | - } |
|
| 20 | + return $twig->render($view . '.twig',$data); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | } |
@@ -13,11 +13,11 @@ |
||
| 13 | 13 | |
| 14 | 14 | $ref = new \ReflectionClass($this); |
| 15 | 15 | |
| 16 | - $tpl = (new \SplFileInfo($ref->getFileName()))->getPath() . DIRECTORY_SEPARATOR .'tpl'; |
|
| 16 | + $tpl = (new \SplFileInfo($ref->getFileName()))->getPath() . DIRECTORY_SEPARATOR . 'tpl'; |
|
| 17 | 17 | |
| 18 | 18 | $twig = new \Twig_Environment(new \Twig_Loader_Filesystem($tpl)); |
| 19 | 19 | |
| 20 | - return $twig->render($view . '.twig',$data); |
|
| 20 | + return $twig->render($view . '.twig', $data); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | } |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Core\Modules\UserList; |
| 3 | 3 | |
| 4 | -use Frameworkless\Controllers; |
|
| 4 | +use Frameworkless\Controllers; |
|
| 5 | 5 | use Donquixote\Cellbrush\Table\Table; |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -12,76 +12,76 @@ |
||
| 12 | 12 | class UserList extends Controllers\ModuleController implements Controllers\ModuleInterface |
| 13 | 13 | {
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * |
|
| 17 | - * @var \Core\Models\User\UserRepository |
|
| 18 | - */ |
|
| 19 | - protected $userRepository; |
|
| 20 | - |
|
| 21 | - function __construct(\Core\Models\User\UserRepository $userRepository) |
|
| 22 | - {
|
|
| 23 | - $this->userRepository = $userRepository; |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - public function process($args = []) |
|
| 27 | - {
|
|
| 28 | - |
|
| 29 | - $this->logger->debug('UserList start');
|
|
| 30 | - |
|
| 31 | - if ($args['fn'] == 'add') {
|
|
| 32 | - $this->add(); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - $Users = $this->userRepository->findMany(); |
|
| 36 | - |
|
| 37 | - $table = Table::create(); |
|
| 38 | - $table->addColNames([0, 1, 2]); |
|
| 39 | - $table->addClass('table table-striped');
|
|
| 40 | - $table->thead() |
|
| 41 | - ->addRowName('head row')
|
|
| 42 | - ->th('head row', 0, 'Id')
|
|
| 43 | - ->th('head row', 1, 'Имя')
|
|
| 44 | - ->th('head row', 2, 'Email');
|
|
| 45 | - $i = 0; |
|
| 46 | - foreach ($Users as $User) {
|
|
| 47 | - $table->addRow($i)->tdMultiple([ |
|
| 48 | - $User->getId(), |
|
| 49 | - $User->getName(), |
|
| 50 | - $User->getEmail()]); |
|
| 51 | - $i++; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return $this->render('default', [
|
|
| 55 | - 'table' => $table->render() |
|
| 56 | - ]); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - protected function add() |
|
| 60 | - {
|
|
| 61 | - |
|
| 62 | - try {
|
|
| 63 | - |
|
| 64 | - $User = $this->userRepository->build(); |
|
| 65 | - $User->setEmail('[email protected]');
|
|
| 66 | - |
|
| 67 | - if (!$this->UserRepository->save($User)) {
|
|
| 68 | - throw new Exception('User not save');
|
|
| 69 | - } else {
|
|
| 70 | - $this->logger->info("Пользователь успешно сохранен!");
|
|
| 71 | - } |
|
| 72 | - } catch(\Frameworkless\Exceptions\ValidationException $ex) {
|
|
| 73 | - |
|
| 74 | - foreach ($ex->getFailures() as $failure) {
|
|
| 75 | - $this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n");
|
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $this->logger->info("Произошла ошибка при сохранении пользователя");
|
|
| 79 | - } catch(\Exception $ex) {
|
|
| 80 | - |
|
| 81 | - $this->logger->error("system error:" . $ex->getMessage());
|
|
| 82 | - |
|
| 83 | - $this->logger->info("Произошла ошибка при сохранении пользователя");
|
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - } |
|
| 15 | + /** |
|
| 16 | + * |
|
| 17 | + * @var \Core\Models\User\UserRepository |
|
| 18 | + */ |
|
| 19 | + protected $userRepository; |
|
| 20 | + |
|
| 21 | + function __construct(\Core\Models\User\UserRepository $userRepository) |
|
| 22 | + {
|
|
| 23 | + $this->userRepository = $userRepository; |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + public function process($args = []) |
|
| 27 | + {
|
|
| 28 | + |
|
| 29 | + $this->logger->debug('UserList start');
|
|
| 30 | + |
|
| 31 | + if ($args['fn'] == 'add') {
|
|
| 32 | + $this->add(); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + $Users = $this->userRepository->findMany(); |
|
| 36 | + |
|
| 37 | + $table = Table::create(); |
|
| 38 | + $table->addColNames([0, 1, 2]); |
|
| 39 | + $table->addClass('table table-striped');
|
|
| 40 | + $table->thead() |
|
| 41 | + ->addRowName('head row')
|
|
| 42 | + ->th('head row', 0, 'Id')
|
|
| 43 | + ->th('head row', 1, 'Имя')
|
|
| 44 | + ->th('head row', 2, 'Email');
|
|
| 45 | + $i = 0; |
|
| 46 | + foreach ($Users as $User) {
|
|
| 47 | + $table->addRow($i)->tdMultiple([ |
|
| 48 | + $User->getId(), |
|
| 49 | + $User->getName(), |
|
| 50 | + $User->getEmail()]); |
|
| 51 | + $i++; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return $this->render('default', [
|
|
| 55 | + 'table' => $table->render() |
|
| 56 | + ]); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + protected function add() |
|
| 60 | + {
|
|
| 61 | + |
|
| 62 | + try {
|
|
| 63 | + |
|
| 64 | + $User = $this->userRepository->build(); |
|
| 65 | + $User->setEmail('[email protected]');
|
|
| 66 | + |
|
| 67 | + if (!$this->UserRepository->save($User)) {
|
|
| 68 | + throw new Exception('User not save');
|
|
| 69 | + } else {
|
|
| 70 | + $this->logger->info("Пользователь успешно сохранен!");
|
|
| 71 | + } |
|
| 72 | + } catch(\Frameworkless\Exceptions\ValidationException $ex) {
|
|
| 73 | + |
|
| 74 | + foreach ($ex->getFailures() as $failure) {
|
|
| 75 | + $this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n");
|
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $this->logger->info("Произошла ошибка при сохранении пользователя");
|
|
| 79 | + } catch(\Exception $ex) {
|
|
| 80 | + |
|
| 81 | + $this->logger->error("system error:" . $ex->getMessage());
|
|
| 82 | + |
|
| 83 | + $this->logger->info("Произошла ошибка при сохранении пользователя");
|
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | $Users = $this->userRepository->findMany(); |
| 36 | 36 | |
| 37 | - $table = Table::create(); |
|
| 37 | + $table = Table::create(); |
|
| 38 | 38 | $table->addColNames([0, 1, 2]); |
| 39 | 39 | $table->addClass('table table-striped');
|
| 40 | 40 | $table->thead() |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | ->th('head row', 0, 'Id')
|
| 43 | 43 | ->th('head row', 1, 'Имя')
|
| 44 | 44 | ->th('head row', 2, 'Email');
|
| 45 | - $i = 0; |
|
| 45 | + $i = 0; |
|
| 46 | 46 | foreach ($Users as $User) {
|
| 47 | 47 | $table->addRow($i)->tdMultiple([ |
| 48 | 48 | $User->getId(), |
@@ -69,14 +69,14 @@ discard block |
||
| 69 | 69 | } else {
|
| 70 | 70 | $this->logger->info("Пользователь успешно сохранен!");
|
| 71 | 71 | } |
| 72 | - } catch(\Frameworkless\Exceptions\ValidationException $ex) {
|
|
| 72 | + } catch (\Frameworkless\Exceptions\ValidationException $ex) {
|
|
| 73 | 73 | |
| 74 | 74 | foreach ($ex->getFailures() as $failure) {
|
| 75 | 75 | $this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n");
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $this->logger->info("Произошла ошибка при сохранении пользователя");
|
| 79 | - } catch(\Exception $ex) {
|
|
| 79 | + } catch (\Exception $ex) {
|
|
| 80 | 80 | |
| 81 | 81 | $this->logger->error("system error:" . $ex->getMessage());
|
| 82 | 82 | |
@@ -8,6 +8,6 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | interface ModuleInterface {
|
| 10 | 10 | |
| 11 | - public function process(); |
|
| 11 | + public function process(); |
|
| 12 | 12 | |
| 13 | 13 | } |
@@ -12,38 +12,38 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | abstract class BaseController implements \Psr\Log\LoggerAwareInterface, PageInterface {
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var Twig_Environment |
|
| 17 | - */ |
|
| 18 | - protected $twig; |
|
| 15 | + /** |
|
| 16 | + * @var Twig_Environment |
|
| 17 | + */ |
|
| 18 | + protected $twig; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * |
|
| 22 | - * @var StandardDebugBar |
|
| 23 | - */ |
|
| 24 | - protected $debugbar; |
|
| 20 | + /** |
|
| 21 | + * |
|
| 22 | + * @var StandardDebugBar |
|
| 23 | + */ |
|
| 24 | + protected $debugbar; |
|
| 25 | 25 | |
| 26 | - use \Psr\Log\LoggerAwareTrait; |
|
| 26 | + use \Psr\Log\LoggerAwareTrait; |
|
| 27 | 27 | |
| 28 | - protected function render($view,array $data = []){
|
|
| 28 | + protected function render($view,array $data = []){
|
|
| 29 | 29 | |
| 30 | - $debugbarRenderer = $this->debugbar->getJavascriptRenderer("/assets/debug_bar");
|
|
| 30 | + $debugbarRenderer = $this->debugbar->getJavascriptRenderer("/assets/debug_bar");
|
|
| 31 | 31 | |
| 32 | - $data["debugbar_Head"] = $debugbarRenderer->renderHead(); |
|
| 33 | - $data["debugbar_Body"] = $debugbarRenderer->render(); |
|
| 32 | + $data["debugbar_Head"] = $debugbarRenderer->renderHead(); |
|
| 33 | + $data["debugbar_Body"] = $debugbarRenderer->render(); |
|
| 34 | 34 | |
| 35 | - return new Response($this->twig->render($view,$data)); |
|
| 36 | - } |
|
| 35 | + return new Response($this->twig->render($view,$data)); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - public function setTwig(Twig_Environment $twig) {
|
|
| 39 | - $this->twig = $twig; |
|
| 40 | - return $this; |
|
| 41 | - } |
|
| 38 | + public function setTwig(Twig_Environment $twig) {
|
|
| 39 | + $this->twig = $twig; |
|
| 40 | + return $this; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function setDebugbar(StandardDebugBar $debugbar) {
|
|
| 44 | - $this->debugbar = $debugbar; |
|
| 45 | - return $this; |
|
| 46 | - } |
|
| 43 | + public function setDebugbar(StandardDebugBar $debugbar) {
|
|
| 44 | + $this->debugbar = $debugbar; |
|
| 45 | + return $this; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | |
@@ -25,14 +25,14 @@ |
||
| 25 | 25 | |
| 26 | 26 | use \Psr\Log\LoggerAwareTrait; |
| 27 | 27 | |
| 28 | - protected function render($view,array $data = []){
|
|
| 28 | + protected function render($view, array $data = []) {
|
|
| 29 | 29 | |
| 30 | 30 | $debugbarRenderer = $this->debugbar->getJavascriptRenderer("/assets/debug_bar");
|
| 31 | 31 | |
| 32 | 32 | $data["debugbar_Head"] = $debugbarRenderer->renderHead(); |
| 33 | 33 | $data["debugbar_Body"] = $debugbarRenderer->render(); |
| 34 | 34 | |
| 35 | - return new Response($this->twig->render($view,$data)); |
|
| 35 | + return new Response($this->twig->render($view, $data)); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function setTwig(Twig_Environment $twig) {
|
@@ -13,8 +13,8 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | interface PageInterface {
|
| 15 | 15 | |
| 16 | - public function setTwig(Twig_Environment $twig); |
|
| 16 | + public function setTwig(Twig_Environment $twig); |
|
| 17 | 17 | |
| 18 | - public function setDebugbar(StandardDebugBar $debugbar); |
|
| 18 | + public function setDebugbar(StandardDebugBar $debugbar); |
|
| 19 | 19 | |
| 20 | 20 | } |
@@ -9,17 +9,17 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class ValidationException extends \Exception { |
| 11 | 11 | |
| 12 | - private $failures; |
|
| 12 | + private $failures; |
|
| 13 | 13 | |
| 14 | - public function __construct($failures, $message = "", $code = 0, $previous = null) { |
|
| 14 | + public function __construct($failures, $message = "", $code = 0, $previous = null) { |
|
| 15 | 15 | |
| 16 | - parent::__construct($message, $code, $previous); |
|
| 16 | + parent::__construct($message, $code, $previous); |
|
| 17 | 17 | |
| 18 | - $this->failures = $failures; |
|
| 19 | - } |
|
| 18 | + $this->failures = $failures; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - function getFailures() { |
|
| 22 | - return $this->failures; |
|
| 23 | - } |
|
| 21 | + function getFailures() { |
|
| 22 | + return $this->failures; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | } |