@@ -36,11 +36,11 @@ |
||
36 | 36 | |
37 | 37 | public function findMany(array $conditions = [], $limit = false) |
38 | 38 | { |
39 | - $Users = UserQuery::create() |
|
40 | - ->_if($limit) |
|
41 | - ->limit($limit) |
|
42 | - ->_endif() |
|
43 | - ->findByArray($conditions); |
|
39 | + $Users = UserQuery::create() |
|
40 | + ->_if($limit) |
|
41 | + ->limit($limit) |
|
42 | + ->_endif() |
|
43 | + ->findByArray($conditions); |
|
44 | 44 | return $Users; |
45 | 45 | } |
46 | 46 |
@@ -13,82 +13,82 @@ |
||
13 | 13 | class UserList extends Controllers\ModuleController |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * UserRepository |
|
18 | - * @var \Core\Models\User\UserRepository |
|
19 | - */ |
|
20 | - protected $userRepository; |
|
21 | - |
|
22 | - /** |
|
23 | - * Request |
|
24 | - * @var Symfony\Component\HttpFoundation\Request |
|
25 | - */ |
|
26 | - protected $request; |
|
27 | - |
|
28 | - protected $limit = 5; |
|
29 | - |
|
30 | - function __construct(\Core\Models\User\UserRepository $userRepository, Request $request) |
|
31 | - { |
|
32 | - $this->userRepository = $userRepository; |
|
33 | - $this->request = $request; |
|
34 | - } |
|
35 | - |
|
36 | - public function process() |
|
37 | - { |
|
38 | - |
|
39 | - if ($this->request->query->get('fn') == 'add') { |
|
40 | - $this->add(); |
|
41 | - } |
|
42 | - |
|
43 | - $Users = $this->userRepository->findMany([],$this->limit); |
|
44 | - |
|
45 | - $table = Table::create(); |
|
46 | - $table->addColNames([0, 1, 2]); |
|
47 | - $table->addClass('table table-striped'); |
|
48 | - $table->thead() |
|
49 | - ->addRowName('head row') |
|
50 | - ->th('head row', 0, 'Id') |
|
51 | - ->th('head row', 1, 'Имя') |
|
52 | - ->th('head row', 2, 'Email'); |
|
53 | - $i = 0; |
|
54 | - foreach ($Users as $User) { |
|
55 | - $table->addRow($i)->tdMultiple([ |
|
56 | - $User->getId(), |
|
57 | - $User->getName(), |
|
58 | - $User->getEmail()]); |
|
59 | - $i++; |
|
60 | - } |
|
61 | - |
|
62 | - return $this->render('default', [ |
|
63 | - 'table' => $table->render() |
|
64 | - ]); |
|
65 | - } |
|
66 | - |
|
67 | - protected function add() |
|
68 | - { |
|
69 | - |
|
70 | - try { |
|
71 | - |
|
72 | - $User = $this->userRepository->build(); |
|
73 | - $User->setEmail('[email protected]'); |
|
74 | - |
|
75 | - if (!$this->userRepository->save($User)) { |
|
76 | - throw new Exception('User not save'); |
|
77 | - } else { |
|
78 | - $this->logger->info("Пользователь успешно сохранен!"); |
|
79 | - } |
|
80 | - } catch(\Frameworkless\Exceptions\ValidationException $ex) { |
|
81 | - |
|
82 | - foreach ($ex->getFailures() as $failure) { |
|
83 | - $this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n"); |
|
84 | - } |
|
85 | - |
|
86 | - $this->logger->info("Произошла ошибка при сохранении пользователя"); |
|
87 | - } catch(\Exception $ex) { |
|
88 | - |
|
89 | - $this->logger->error("system error:" . $ex->getMessage()); |
|
90 | - |
|
91 | - $this->logger->info("Произошла ошибка при сохранении пользователя"); |
|
92 | - } |
|
93 | - } |
|
16 | + /** |
|
17 | + * UserRepository |
|
18 | + * @var \Core\Models\User\UserRepository |
|
19 | + */ |
|
20 | + protected $userRepository; |
|
21 | + |
|
22 | + /** |
|
23 | + * Request |
|
24 | + * @var Symfony\Component\HttpFoundation\Request |
|
25 | + */ |
|
26 | + protected $request; |
|
27 | + |
|
28 | + protected $limit = 5; |
|
29 | + |
|
30 | + function __construct(\Core\Models\User\UserRepository $userRepository, Request $request) |
|
31 | + { |
|
32 | + $this->userRepository = $userRepository; |
|
33 | + $this->request = $request; |
|
34 | + } |
|
35 | + |
|
36 | + public function process() |
|
37 | + { |
|
38 | + |
|
39 | + if ($this->request->query->get('fn') == 'add') { |
|
40 | + $this->add(); |
|
41 | + } |
|
42 | + |
|
43 | + $Users = $this->userRepository->findMany([],$this->limit); |
|
44 | + |
|
45 | + $table = Table::create(); |
|
46 | + $table->addColNames([0, 1, 2]); |
|
47 | + $table->addClass('table table-striped'); |
|
48 | + $table->thead() |
|
49 | + ->addRowName('head row') |
|
50 | + ->th('head row', 0, 'Id') |
|
51 | + ->th('head row', 1, 'Имя') |
|
52 | + ->th('head row', 2, 'Email'); |
|
53 | + $i = 0; |
|
54 | + foreach ($Users as $User) { |
|
55 | + $table->addRow($i)->tdMultiple([ |
|
56 | + $User->getId(), |
|
57 | + $User->getName(), |
|
58 | + $User->getEmail()]); |
|
59 | + $i++; |
|
60 | + } |
|
61 | + |
|
62 | + return $this->render('default', [ |
|
63 | + 'table' => $table->render() |
|
64 | + ]); |
|
65 | + } |
|
66 | + |
|
67 | + protected function add() |
|
68 | + { |
|
69 | + |
|
70 | + try { |
|
71 | + |
|
72 | + $User = $this->userRepository->build(); |
|
73 | + $User->setEmail('[email protected]'); |
|
74 | + |
|
75 | + if (!$this->userRepository->save($User)) { |
|
76 | + throw new Exception('User not save'); |
|
77 | + } else { |
|
78 | + $this->logger->info("Пользователь успешно сохранен!"); |
|
79 | + } |
|
80 | + } catch(\Frameworkless\Exceptions\ValidationException $ex) { |
|
81 | + |
|
82 | + foreach ($ex->getFailures() as $failure) { |
|
83 | + $this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n"); |
|
84 | + } |
|
85 | + |
|
86 | + $this->logger->info("Произошла ошибка при сохранении пользователя"); |
|
87 | + } catch(\Exception $ex) { |
|
88 | + |
|
89 | + $this->logger->error("system error:" . $ex->getMessage()); |
|
90 | + |
|
91 | + $this->logger->info("Произошла ошибка при сохранении пользователя"); |
|
92 | + } |
|
93 | + } |
|
94 | 94 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | |
30 | 30 | function __construct(\Core\Models\User\UserRepository $userRepository, Request $request) |
31 | 31 | { |
32 | - $this->userRepository = $userRepository; |
|
33 | - $this->request = $request; |
|
32 | + $this->userRepository = $userRepository; |
|
33 | + $this->request = $request; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | public function process() |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | $this->add(); |
41 | 41 | } |
42 | 42 | |
43 | - $Users = $this->userRepository->findMany([],$this->limit); |
|
43 | + $Users = $this->userRepository->findMany([], $this->limit); |
|
44 | 44 | |
45 | - $table = Table::create(); |
|
45 | + $table = Table::create(); |
|
46 | 46 | $table->addColNames([0, 1, 2]); |
47 | 47 | $table->addClass('table table-striped'); |
48 | 48 | $table->thead() |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | ->th('head row', 0, 'Id') |
51 | 51 | ->th('head row', 1, 'Имя') |
52 | 52 | ->th('head row', 2, 'Email'); |
53 | - $i = 0; |
|
53 | + $i = 0; |
|
54 | 54 | foreach ($Users as $User) { |
55 | 55 | $table->addRow($i)->tdMultiple([ |
56 | 56 | $User->getId(), |
@@ -77,14 +77,14 @@ discard block |
||
77 | 77 | } else { |
78 | 78 | $this->logger->info("Пользователь успешно сохранен!"); |
79 | 79 | } |
80 | - } catch(\Frameworkless\Exceptions\ValidationException $ex) { |
|
80 | + } catch (\Frameworkless\Exceptions\ValidationException $ex) { |
|
81 | 81 | |
82 | 82 | foreach ($ex->getFailures() as $failure) { |
83 | 83 | $this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n"); |
84 | 84 | } |
85 | 85 | |
86 | 86 | $this->logger->info("Произошла ошибка при сохранении пользователя"); |
87 | - } catch(\Exception $ex) { |
|
87 | + } catch (\Exception $ex) { |
|
88 | 88 | |
89 | 89 | $this->logger->error("system error:" . $ex->getMessage()); |
90 | 90 |
@@ -3,53 +3,53 @@ |
||
3 | 3 | class App |
4 | 4 | { |
5 | 5 | |
6 | - private $settings = array(); |
|
6 | + private $settings = array(); |
|
7 | 7 | |
8 | - private static $_instance = null; |
|
9 | - |
|
10 | - private function __construct() |
|
11 | - { |
|
12 | - // приватный конструктор ограничивает реализацию getInstance () |
|
13 | - } |
|
14 | - |
|
15 | - protected function __clone() |
|
16 | - { |
|
17 | - // ограничивает клонирование объекта |
|
18 | - } |
|
19 | - |
|
20 | - /** |
|
21 | - * Вызов модуля |
|
22 | - * @param type $name |
|
23 | - * @param array $params |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - static function getModule($name, array $params = []) |
|
27 | - { |
|
28 | - $DI = self::getInstance()->load("DI"); |
|
29 | - $debugbar = $DI->get(DebugBar\StandardDebugBar::class); |
|
30 | - $debugbar['messages']->debug(sprintf('App::getModule %s, with params %s' , $name, json_encode($params) )); |
|
31 | - $debugbar['time']->startMeasure($name, 'Load module ' . $name); |
|
32 | - $module = $DI->get($name); |
|
33 | - $result = $module->setParams($params)->process(); |
|
34 | - $debugbar['time']->stopMeasure($name); |
|
35 | - return $result; |
|
36 | - } |
|
37 | - |
|
38 | - static public function getInstance() |
|
39 | - { |
|
40 | - if (is_null(self::$_instance)) { |
|
41 | - self::$_instance = new self(); |
|
42 | - } |
|
43 | - return self::$_instance; |
|
44 | - } |
|
45 | - |
|
46 | - public function import($key,$value) |
|
47 | - { |
|
48 | - $this->settings[$key] = $value; |
|
49 | - } |
|
50 | - |
|
51 | - public function load($key) |
|
52 | - { |
|
53 | - return $this->settings[$key]; |
|
54 | - } |
|
8 | + private static $_instance = null; |
|
9 | + |
|
10 | + private function __construct() |
|
11 | + { |
|
12 | + // приватный конструктор ограничивает реализацию getInstance () |
|
13 | + } |
|
14 | + |
|
15 | + protected function __clone() |
|
16 | + { |
|
17 | + // ограничивает клонирование объекта |
|
18 | + } |
|
19 | + |
|
20 | + /** |
|
21 | + * Вызов модуля |
|
22 | + * @param type $name |
|
23 | + * @param array $params |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + static function getModule($name, array $params = []) |
|
27 | + { |
|
28 | + $DI = self::getInstance()->load("DI"); |
|
29 | + $debugbar = $DI->get(DebugBar\StandardDebugBar::class); |
|
30 | + $debugbar['messages']->debug(sprintf('App::getModule %s, with params %s' , $name, json_encode($params) )); |
|
31 | + $debugbar['time']->startMeasure($name, 'Load module ' . $name); |
|
32 | + $module = $DI->get($name); |
|
33 | + $result = $module->setParams($params)->process(); |
|
34 | + $debugbar['time']->stopMeasure($name); |
|
35 | + return $result; |
|
36 | + } |
|
37 | + |
|
38 | + static public function getInstance() |
|
39 | + { |
|
40 | + if (is_null(self::$_instance)) { |
|
41 | + self::$_instance = new self(); |
|
42 | + } |
|
43 | + return self::$_instance; |
|
44 | + } |
|
45 | + |
|
46 | + public function import($key,$value) |
|
47 | + { |
|
48 | + $this->settings[$key] = $value; |
|
49 | + } |
|
50 | + |
|
51 | + public function load($key) |
|
52 | + { |
|
53 | + return $this->settings[$key]; |
|
54 | + } |
|
55 | 55 | } |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | */ |
26 | 26 | static function getModule($name, array $params = []) |
27 | 27 | { |
28 | - $DI = self::getInstance()->load("DI"); |
|
29 | - $debugbar = $DI->get(DebugBar\StandardDebugBar::class); |
|
30 | - $debugbar['messages']->debug(sprintf('App::getModule %s, with params %s' , $name, json_encode($params) )); |
|
28 | + $DI = self::getInstance()->load("DI"); |
|
29 | + $debugbar = $DI->get(DebugBar\StandardDebugBar::class); |
|
30 | + $debugbar['messages']->debug(sprintf('App::getModule %s, with params %s', $name, json_encode($params))); |
|
31 | 31 | $debugbar['time']->startMeasure($name, 'Load module ' . $name); |
32 | 32 | $module = $DI->get($name); |
33 | 33 | $result = $module->setParams($params)->process(); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | return self::$_instance; |
44 | 44 | } |
45 | 45 | |
46 | - public function import($key,$value) |
|
46 | + public function import($key, $value) |
|
47 | 47 | { |
48 | 48 | $this->settings[$key] = $value; |
49 | 49 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | */ |
9 | 9 | interface ModuleInterface { |
10 | 10 | |
11 | - public function process(); |
|
11 | + public function process(); |
|
12 | 12 | |
13 | - public function setParams(array $params = []); |
|
13 | + public function setParams(array $params = []); |
|
14 | 14 | } |
@@ -9,35 +9,35 @@ |
||
9 | 9 | */ |
10 | 10 | abstract class ModuleController extends BaseController implements \Frameworkless\ModuleInterface{ |
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 | - abstract public function process(); |
|
23 | + abstract public function process(); |
|
24 | 24 | |
25 | - /** |
|
26 | - * set module params |
|
27 | - * @param array $params |
|
28 | - * @return $this |
|
29 | - * @throws \Exception |
|
30 | - */ |
|
31 | - public function setParams(array $params = array()) |
|
32 | - { |
|
25 | + /** |
|
26 | + * set module params |
|
27 | + * @param array $params |
|
28 | + * @return $this |
|
29 | + * @throws \Exception |
|
30 | + */ |
|
31 | + public function setParams(array $params = array()) |
|
32 | + { |
|
33 | 33 | |
34 | - foreach($params as $param => $value){ |
|
35 | - if((new \ReflectionClass($this))->hasProperty($param)===false) |
|
36 | - throw new \Exception(sprintf("param '%s' not found in module '%s'",$param,self::class)); |
|
34 | + foreach($params as $param => $value){ |
|
35 | + if((new \ReflectionClass($this))->hasProperty($param)===false) |
|
36 | + throw new \Exception(sprintf("param '%s' not found in module '%s'",$param,self::class)); |
|
37 | 37 | |
38 | - $this->{$param} = $value; |
|
39 | - } |
|
40 | - return $this; |
|
41 | - } |
|
38 | + $this->{$param} = $value; |
|
39 | + } |
|
40 | + return $this; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | } |
@@ -7,17 +7,17 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @author d.lanec |
9 | 9 | */ |
10 | -abstract class ModuleController extends BaseController implements \Frameworkless\ModuleInterface{ |
|
10 | +abstract class ModuleController extends BaseController implements \Frameworkless\ModuleInterface { |
|
11 | 11 | |
12 | 12 | protected function render($view, array $data = array()) { |
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 | abstract public function process(); |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | public function setParams(array $params = array()) |
32 | 32 | { |
33 | 33 | |
34 | - foreach($params as $param => $value){ |
|
35 | - if((new \ReflectionClass($this))->hasProperty($param)===false) |
|
36 | - throw new \Exception(sprintf("param '%s' not found in module '%s'",$param,self::class)); |
|
34 | + foreach ($params as $param => $value) { |
|
35 | + if ((new \ReflectionClass($this))->hasProperty($param) === false) |
|
36 | + throw new \Exception(sprintf("param '%s' not found in module '%s'", $param, self::class)); |
|
37 | 37 | |
38 | 38 | $this->{$param} = $value; |
39 | 39 | } |
@@ -32,8 +32,9 @@ |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | foreach($params as $param => $value){ |
35 | - if((new \ReflectionClass($this))->hasProperty($param)===false) |
|
36 | - throw new \Exception(sprintf("param '%s' not found in module '%s'",$param,self::class)); |
|
35 | + if((new \ReflectionClass($this))->hasProperty($param)===false) { |
|
36 | + throw new \Exception(sprintf("param '%s' not found in module '%s'",$param,self::class)); |
|
37 | + } |
|
37 | 38 | |
38 | 39 | $this->{$param} = $value; |
39 | 40 | } |
@@ -8,25 +8,25 @@ |
||
8 | 8 | class IndexController extends BaseController { |
9 | 9 | |
10 | 10 | |
11 | - /** |
|
12 | - * Return index page (/) |
|
13 | - * |
|
14 | - * @param array $args |
|
15 | - * @return Response |
|
16 | - */ |
|
17 | - public function get($args) { |
|
11 | + /** |
|
12 | + * Return index page (/) |
|
13 | + * |
|
14 | + * @param array $args |
|
15 | + * @return Response |
|
16 | + */ |
|
17 | + public function get($args) { |
|
18 | 18 | |
19 | - $result = \App::getModule(UserList::class,[ |
|
20 | - "limit" => 2 |
|
21 | - ]); |
|
19 | + $result = \App::getModule(UserList::class,[ |
|
20 | + "limit" => 2 |
|
21 | + ]); |
|
22 | 22 | |
23 | - $result .= \App::getModule(UserList::class,[ |
|
24 | - "limit" => 1 |
|
25 | - ]); |
|
23 | + $result .= \App::getModule(UserList::class,[ |
|
24 | + "limit" => 1 |
|
25 | + ]); |
|
26 | 26 | |
27 | - return $this->render('pages/index.html.twig', [ |
|
28 | - "content" => $result, |
|
29 | - ]); |
|
30 | - } |
|
27 | + return $this->render('pages/index.html.twig', [ |
|
28 | + "content" => $result, |
|
29 | + ]); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | } |
@@ -16,11 +16,11 @@ |
||
16 | 16 | */ |
17 | 17 | public function get($args) { |
18 | 18 | |
19 | - $result = \App::getModule(UserList::class,[ |
|
19 | + $result = \App::getModule(UserList::class, [ |
|
20 | 20 | "limit" => 2 |
21 | 21 | ]); |
22 | 22 | |
23 | - $result .= \App::getModule(UserList::class,[ |
|
23 | + $result .= \App::getModule(UserList::class, [ |
|
24 | 24 | "limit" => 1 |
25 | 25 | ]); |
26 | 26 |