@@ -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 | } |
@@ -1,8 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Core\Modules\UserList; |
| 3 | 3 | |
| 4 | -use Frameworkless\Controllers; |
|
| 5 | -use Donquixote\Cellbrush\Table\Table; |
|
| 4 | +use Frameworkless\Controllers; |
|
| 5 | +use Donquixote\Cellbrush\Table\Table; |
|
| 6 | 6 | use Symfony\Component\HttpFoundation\Request; |
| 7 | 7 | |
| 8 | 8 | /** |
@@ -13,84 +13,84 @@ |
||
| 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,3]); |
|
| 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, 'Имя')
|
|
| 53 | - ->th('head row', 3, 'Email');
|
|
| 54 | - $i = 0; |
|
| 55 | - foreach ($Users as $User) {
|
|
| 56 | - $table->addRow($i)->tdMultiple([ |
|
| 57 | - $User->getId(), |
|
| 58 | - $User->getCreatedAt("d.m.Y"),
|
|
| 59 | - $User->getName(), |
|
| 60 | - $User->getEmail()]); |
|
| 61 | - $i++; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - return $this->render('default', [
|
|
| 65 | - 'table' => $table->render() |
|
| 66 | - ]); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - protected function add() |
|
| 70 | - {
|
|
| 71 | - |
|
| 72 | - try {
|
|
| 73 | - |
|
| 74 | - $User = $this->userRepository->build(); |
|
| 75 | - $User->setEmail('[email protected]');
|
|
| 76 | - |
|
| 77 | - if (!$this->userRepository->save($User)) {
|
|
| 78 | - throw new Exception('User not save');
|
|
| 79 | - } else {
|
|
| 80 | - $this->logger->info("Пользователь успешно сохранен!");
|
|
| 81 | - } |
|
| 82 | - } catch(\Frameworkless\Exceptions\ValidationException $ex) {
|
|
| 83 | - |
|
| 84 | - foreach ($ex->getFailures() as $failure) {
|
|
| 85 | - $this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n");
|
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $this->logger->info("Произошла ошибка при сохранении пользователя");
|
|
| 89 | - } catch(\Exception $ex) {
|
|
| 90 | - |
|
| 91 | - $this->logger->error("system error:" . $ex->getMessage());
|
|
| 92 | - |
|
| 93 | - $this->logger->info("Произошла ошибка при сохранении пользователя");
|
|
| 94 | - } |
|
| 95 | - } |
|
| 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,3]); |
|
| 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, 'Имя')
|
|
| 53 | + ->th('head row', 3, 'Email');
|
|
| 54 | + $i = 0; |
|
| 55 | + foreach ($Users as $User) {
|
|
| 56 | + $table->addRow($i)->tdMultiple([ |
|
| 57 | + $User->getId(), |
|
| 58 | + $User->getCreatedAt("d.m.Y"),
|
|
| 59 | + $User->getName(), |
|
| 60 | + $User->getEmail()]); |
|
| 61 | + $i++; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + return $this->render('default', [
|
|
| 65 | + 'table' => $table->render() |
|
| 66 | + ]); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + protected function add() |
|
| 70 | + {
|
|
| 71 | + |
|
| 72 | + try {
|
|
| 73 | + |
|
| 74 | + $User = $this->userRepository->build(); |
|
| 75 | + $User->setEmail('[email protected]');
|
|
| 76 | + |
|
| 77 | + if (!$this->userRepository->save($User)) {
|
|
| 78 | + throw new Exception('User not save');
|
|
| 79 | + } else {
|
|
| 80 | + $this->logger->info("Пользователь успешно сохранен!");
|
|
| 81 | + } |
|
| 82 | + } catch(\Frameworkless\Exceptions\ValidationException $ex) {
|
|
| 83 | + |
|
| 84 | + foreach ($ex->getFailures() as $failure) {
|
|
| 85 | + $this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n");
|
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $this->logger->info("Произошла ошибка при сохранении пользователя");
|
|
| 89 | + } catch(\Exception $ex) {
|
|
| 90 | + |
|
| 91 | + $this->logger->error("system error:" . $ex->getMessage());
|
|
| 92 | + |
|
| 93 | + $this->logger->info("Произошла ошибка при сохранении пользователя");
|
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -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,10 +40,10 @@ 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(); |
|
| 46 | - $table->addColNames([0, 1, 2,3]); |
|
| 45 | + $table = Table::create(); |
|
| 46 | + $table->addColNames([0, 1, 2, 3]); |
|
| 47 | 47 | $table->addClass('table table-striped');
|
| 48 | 48 | $table->thead() |
| 49 | 49 | ->addRowName('head row')
|
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | ->th('head row', 1, 'Регистрация')
|
| 52 | 52 | ->th('head row', 2, 'Имя')
|
| 53 | 53 | ->th('head row', 3, 'Email');
|
| 54 | - $i = 0; |
|
| 54 | + $i = 0; |
|
| 55 | 55 | foreach ($Users as $User) {
|
| 56 | 56 | $table->addRow($i)->tdMultiple([ |
| 57 | 57 | $User->getId(), |
@@ -79,14 +79,14 @@ discard block |
||
| 79 | 79 | } else {
|
| 80 | 80 | $this->logger->info("Пользователь успешно сохранен!");
|
| 81 | 81 | } |
| 82 | - } catch(\Frameworkless\Exceptions\ValidationException $ex) {
|
|
| 82 | + } catch (\Frameworkless\Exceptions\ValidationException $ex) {
|
|
| 83 | 83 | |
| 84 | 84 | foreach ($ex->getFailures() as $failure) {
|
| 85 | 85 | $this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n");
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $this->logger->info("Произошла ошибка при сохранении пользователя");
|
| 89 | - } catch(\Exception $ex) {
|
|
| 89 | + } catch (\Exception $ex) {
|
|
| 90 | 90 | |
| 91 | 91 | $this->logger->error("system error:" . $ex->getMessage());
|
| 92 | 92 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | public function findById($id) |
| 29 | 29 | { |
| 30 | 30 | if (!$User = UserQuery::create()->findPk($id)) { |
| 31 | - throw new \InvalidArgumentException(sprintf('User with ID %d does not exist',$id)); |
|
| 31 | + throw new \InvalidArgumentException(sprintf('User with ID %d does not exist', $id)); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | return $User; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @return \Core\Models\User\User $User |
| 61 | 61 | */ |
| 62 | - public function build(){ |
|
| 62 | + public function build() { |
|
| 63 | 63 | return new User; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -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 | |
@@ -16,6 +16,6 @@ |
||
| 16 | 16 | class User extends BaseUser |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - use \Frameworkless\ValidatorTrait; |
|
| 19 | + use \Frameworkless\ValidatorTrait; |
|
| 20 | 20 | |
| 21 | 21 | } |
@@ -15,26 +15,26 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | trait ValidatorTrait |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Symfony\Component\Validator\Validator\RecursiveValidator |
|
| 20 | - * @var type |
|
| 21 | - */ |
|
| 22 | - protected $validator; |
|
| 18 | + /** |
|
| 19 | + * Symfony\Component\Validator\Validator\RecursiveValidator |
|
| 20 | + * @var type |
|
| 21 | + */ |
|
| 22 | + protected $validator; |
|
| 23 | 23 | |
| 24 | 24 | function __construct() |
| 25 | - { |
|
| 26 | - $this->validator = new RecursiveValidator( |
|
| 25 | + { |
|
| 26 | + $this->validator = new RecursiveValidator( |
|
| 27 | 27 | new ExecutionContextFactory(new IdentityTranslator()), |
| 28 | 28 | new LazyLoadingMetadataFactory(new StaticMethodLoader()), |
| 29 | 29 | new ConstraintValidatorFactory() |
| 30 | 30 | ); |
| 31 | - } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - public function preSave(\Propel\Runtime\Connection\ConnectionInterface $con = null) |
|
| 34 | - { |
|
| 33 | + public function preSave(\Propel\Runtime\Connection\ConnectionInterface $con = null) |
|
| 34 | + { |
|
| 35 | 35 | if (!$result = $this->validate($this->validator)) { |
| 36 | 36 | throw new ValidationException($this->getValidationFailures(),"Validation error"); |
| 37 | 37 | } |
| 38 | - return $result; |
|
| 39 | - } |
|
| 38 | + return $result; |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | public function preSave(\Propel\Runtime\Connection\ConnectionInterface $con = null) |
| 34 | 34 | { |
| 35 | 35 | if (!$result = $this->validate($this->validator)) { |
| 36 | - throw new ValidationException($this->getValidationFailures(),"Validation error"); |
|
| 36 | + throw new ValidationException($this->getValidationFailures(), "Validation error"); |
|
| 37 | 37 | } |
| 38 | 38 | return $result; |
| 39 | 39 | } |
@@ -25,36 +25,36 @@ discard block |
||
| 25 | 25 | * set Monolog |
| 26 | 26 | */ |
| 27 | 27 | $container->share(Monolog\Logger::class) |
| 28 | - ->withArgument('myLogger') |
|
| 29 | - ; |
|
| 28 | + ->withArgument('myLogger') |
|
| 29 | + ; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * set Propel2 Logger |
| 33 | 33 | */ |
| 34 | 34 | Propel\Runtime\Propel::getServiceContainer()->setLogger('defaultLogger', |
| 35 | - (new Monolog\Logger('defaultLogger')) |
|
| 36 | - ->pushHandler(new Monolog\Handler\StreamHandler('php://stderr')) |
|
| 37 | - ); |
|
| 35 | + (new Monolog\Logger('defaultLogger')) |
|
| 36 | + ->pushHandler(new Monolog\Handler\StreamHandler('php://stderr')) |
|
| 37 | + ); |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * set Debug bar |
| 41 | 41 | */ |
| 42 | 42 | $container->share(DebugBar\StandardDebugBar::class) |
| 43 | - ->withMethodCall("addCollector",[ |
|
| 44 | - new DebugBar\Bridge\Twig\TwigCollector( |
|
| 45 | - new DebugBar\Bridge\Twig\TraceableTwigEnvironment( |
|
| 46 | - $container->get(Twig_Environment::class), |
|
| 47 | - new DebugBar\DataCollector\TimeDataCollector |
|
| 48 | - ) |
|
| 49 | - ) |
|
| 50 | - ]) |
|
| 51 | - ->withMethodCall("addCollector",[ |
|
| 52 | - new DebugBar\Bridge\Propel2Collector(Propel\Runtime\Propel::getConnection()) |
|
| 53 | - ]) |
|
| 54 | - ->withMethodCall("addCollector",[ |
|
| 55 | - new \DebugBar\Bridge\MonologCollector($container->get(Monolog\Logger::class)) |
|
| 56 | - ]) |
|
| 57 | - ; |
|
| 43 | + ->withMethodCall("addCollector",[ |
|
| 44 | + new DebugBar\Bridge\Twig\TwigCollector( |
|
| 45 | + new DebugBar\Bridge\Twig\TraceableTwigEnvironment( |
|
| 46 | + $container->get(Twig_Environment::class), |
|
| 47 | + new DebugBar\DataCollector\TimeDataCollector |
|
| 48 | + ) |
|
| 49 | + ) |
|
| 50 | + ]) |
|
| 51 | + ->withMethodCall("addCollector",[ |
|
| 52 | + new DebugBar\Bridge\Propel2Collector(Propel\Runtime\Propel::getConnection()) |
|
| 53 | + ]) |
|
| 54 | + ->withMethodCall("addCollector",[ |
|
| 55 | + new \DebugBar\Bridge\MonologCollector($container->get(Monolog\Logger::class)) |
|
| 56 | + ]) |
|
| 57 | + ; |
|
| 58 | 58 | ; |
| 59 | 59 | |
| 60 | 60 | |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | |
| 65 | 65 | $container->inflector(Psr\Log\LoggerAwareInterface::class) |
| 66 | - ->invokeMethod('setLogger', [$container->get(Monolog\Logger::class)]); |
|
| 66 | + ->invokeMethod('setLogger', [$container->get(Monolog\Logger::class)]); |
|
| 67 | 67 | |
| 68 | 68 | $container->inflector(Frameworkless\Controllers\PageInterface::class) |
| 69 | - ->invokeMethod('setTwig', [$container->get(Twig_Environment::class)]) |
|
| 70 | - ->invokeMethod('setDebugbar', [$container->get(DebugBar\StandardDebugBar::class)]) |
|
| 71 | - ; |
|
| 69 | + ->invokeMethod('setTwig', [$container->get(Twig_Environment::class)]) |
|
| 70 | + ->invokeMethod('setDebugbar', [$container->get(DebugBar\StandardDebugBar::class)]) |
|
| 71 | + ; |
|
| 72 | 72 | |
| 73 | 73 | |
| 74 | 74 | App::getInstance()->import("DI", $container); |
| 75 | 75 | \ No newline at end of file |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** |
| 14 | 14 | * set Request |
| 15 | 15 | */ |
| 16 | -$container->add(Request::class,Request::createFromGlobals()); |
|
| 16 | +$container->add(Request::class, Request::createFromGlobals()); |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * set Twig |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * set Debug bar |
| 41 | 41 | */ |
| 42 | 42 | $container->share(DebugBar\StandardDebugBar::class) |
| 43 | - ->withMethodCall("addCollector",[ |
|
| 43 | + ->withMethodCall("addCollector", [ |
|
| 44 | 44 | new DebugBar\Bridge\Twig\TwigCollector( |
| 45 | 45 | new DebugBar\Bridge\Twig\TraceableTwigEnvironment( |
| 46 | 46 | $container->get(Twig_Environment::class), |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | ) |
| 49 | 49 | ) |
| 50 | 50 | ]) |
| 51 | - ->withMethodCall("addCollector",[ |
|
| 51 | + ->withMethodCall("addCollector", [ |
|
| 52 | 52 | new DebugBar\Bridge\Propel2Collector(Propel\Runtime\Propel::getConnection()) |
| 53 | 53 | ]) |
| 54 | - ->withMethodCall("addCollector",[ |
|
| 54 | + ->withMethodCall("addCollector", [ |
|
| 55 | 55 | new \DebugBar\Bridge\MonologCollector($container->get(Monolog\Logger::class)) |
| 56 | 56 | ]) |
| 57 | 57 | ; |
@@ -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 | } |
@@ -4,10 +4,7 @@ |
||
| 4 | 4 | use Symfony\Component\Console\Command\Command; |
| 5 | 5 | use Symfony\Component\Console\Input\InputInterface; |
| 6 | 6 | use Symfony\Component\Console\Output\OutputInterface; |
| 7 | -use Symfony\Component\Console\Input\StringInput; |
|
| 8 | 7 | use Symfony\Component\Console\Input\ArrayInput; |
| 9 | -use Symfony\Component\Process\Process; |
|
| 10 | -use Symfony\Component\Process\Exception\ProcessFailedException; |
|
| 11 | 8 | |
| 12 | 9 | /** |
| 13 | 10 | * Description of HelloWorldCommand |
@@ -25,21 +25,21 @@ |
||
| 25 | 25 | protected function execute(InputInterface $input, OutputInterface $output) |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - $command = $this->getApplication()->find('config:convert'); |
|
| 29 | - $returnCode = $command->run(new ArrayInput([ |
|
| 30 | - 'command' => 'config:convert' |
|
| 31 | - ]), $output); |
|
| 28 | + $command = $this->getApplication()->find('config:convert'); |
|
| 29 | + $returnCode = $command->run(new ArrayInput([ |
|
| 30 | + 'command' => 'config:convert' |
|
| 31 | + ]), $output); |
|
| 32 | 32 | |
| 33 | - $command = $this->getApplication()->find('packages:install'); |
|
| 34 | - $returnCode = $command->run(new ArrayInput([ |
|
| 35 | - 'command' => 'packages:install' |
|
| 36 | - ]), $output); |
|
| 33 | + $command = $this->getApplication()->find('packages:install'); |
|
| 34 | + $returnCode = $command->run(new ArrayInput([ |
|
| 35 | + 'command' => 'packages:install' |
|
| 36 | + ]), $output); |
|
| 37 | 37 | |
| 38 | - $command = $this->getApplication()->find('migration:migrate'); |
|
| 39 | - $returnCode = $command->run(new ArrayInput([ |
|
| 40 | - 'command' => 'migration:migrate' |
|
| 41 | - ]), $output); |
|
| 38 | + $command = $this->getApplication()->find('migration:migrate'); |
|
| 39 | + $returnCode = $command->run(new ArrayInput([ |
|
| 40 | + 'command' => 'migration:migrate' |
|
| 41 | + ]), $output); |
|
| 42 | 42 | |
| 43 | - $output->writeln("install completed!"); |
|
| 43 | + $output->writeln("install completed!"); |
|
| 44 | 44 | } |
| 45 | 45 | } |
@@ -25,18 +25,18 @@ |
||
| 25 | 25 | protected function execute(InputInterface $input, OutputInterface $output) |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - $command = $this->getApplication()->find('config:convert'); |
|
| 29 | - $returnCode = $command->run(new ArrayInput([ |
|
| 28 | + $command = $this->getApplication()->find('config:convert'); |
|
| 29 | + $returnCode = $command->run(new ArrayInput([ |
|
| 30 | 30 | 'command' => 'config:convert' |
| 31 | 31 | ]), $output); |
| 32 | 32 | |
| 33 | - $command = $this->getApplication()->find('packages:install'); |
|
| 34 | - $returnCode = $command->run(new ArrayInput([ |
|
| 33 | + $command = $this->getApplication()->find('packages:install'); |
|
| 34 | + $returnCode = $command->run(new ArrayInput([ |
|
| 35 | 35 | 'command' => 'packages:install' |
| 36 | 36 | ]), $output); |
| 37 | 37 | |
| 38 | - $command = $this->getApplication()->find('migration:migrate'); |
|
| 39 | - $returnCode = $command->run(new ArrayInput([ |
|
| 38 | + $command = $this->getApplication()->find('migration:migrate'); |
|
| 39 | + $returnCode = $command->run(new ArrayInput([ |
|
| 40 | 40 | 'command' => 'migration:migrate' |
| 41 | 41 | ]), $output); |
| 42 | 42 | |