@@ -10,26 +10,26 @@ |
||
| 10 | 10 | class User implements \Frameworkless\SeedInterface |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * |
|
| 15 | - * @param type $id |
|
| 16 | - * @return type |
|
| 17 | - */ |
|
| 18 | - static public function build($id = 1) |
|
| 19 | - { |
|
| 20 | - $generator = \Faker\Factory::create(); |
|
| 21 | - $populator = new \Faker\ORM\Propel2\Populator($generator); |
|
| 22 | - $populator->addEntity(\Core\Models\User\User::class, $id); |
|
| 23 | - return $populator->execute(); |
|
| 24 | - } |
|
| 13 | + /** |
|
| 14 | + * |
|
| 15 | + * @param type $id |
|
| 16 | + * @return type |
|
| 17 | + */ |
|
| 18 | + static public function build($id = 1) |
|
| 19 | + { |
|
| 20 | + $generator = \Faker\Factory::create(); |
|
| 21 | + $populator = new \Faker\ORM\Propel2\Populator($generator); |
|
| 22 | + $populator->addEntity(\Core\Models\User\User::class, $id); |
|
| 23 | + return $populator->execute(); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * |
|
| 28 | - * @return type |
|
| 29 | - */ |
|
| 30 | - public static function reset() |
|
| 31 | - { |
|
| 32 | - return \Core\Models\User\UserQuery::create()->deleteAll(); |
|
| 33 | - } |
|
| 26 | + /** |
|
| 27 | + * |
|
| 28 | + * @return type |
|
| 29 | + */ |
|
| 30 | + public static function reset() |
|
| 31 | + { |
|
| 32 | + return \Core\Models\User\UserQuery::create()->deleteAll(); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | } |
@@ -18,39 +18,39 @@ |
||
| 18 | 18 | class SeedCommand extends Command |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - protected function configure() |
|
| 22 | - { |
|
| 23 | - $this->setName('seed:build') |
|
| 24 | - ->setDescription('Create seeds data') |
|
| 25 | - ->setDefinition( |
|
| 26 | - new InputDefinition(array( |
|
| 27 | - new InputOption('class', 'c', InputOption::VALUE_REQUIRED), |
|
| 28 | - new InputOption('amount', 'a', InputOption::VALUE_OPTIONAL) |
|
| 29 | - )) |
|
| 30 | - ); |
|
| 31 | - $this->setName('seed:reset') |
|
| 32 | - ->setDescription('Reset seeds data') |
|
| 33 | - ->setDefinition( |
|
| 34 | - new InputDefinition(array( |
|
| 35 | - new InputOption('class', 'c', InputOption::VALUE_REQUIRED) |
|
| 36 | - )) |
|
| 37 | - ); |
|
| 38 | - } |
|
| 21 | + protected function configure() |
|
| 22 | + { |
|
| 23 | + $this->setName('seed:build') |
|
| 24 | + ->setDescription('Create seeds data') |
|
| 25 | + ->setDefinition( |
|
| 26 | + new InputDefinition(array( |
|
| 27 | + new InputOption('class', 'c', InputOption::VALUE_REQUIRED), |
|
| 28 | + new InputOption('amount', 'a', InputOption::VALUE_OPTIONAL) |
|
| 29 | + )) |
|
| 30 | + ); |
|
| 31 | + $this->setName('seed:reset') |
|
| 32 | + ->setDescription('Reset seeds data') |
|
| 33 | + ->setDefinition( |
|
| 34 | + new InputDefinition(array( |
|
| 35 | + new InputOption('class', 'c', InputOption::VALUE_REQUIRED) |
|
| 36 | + )) |
|
| 37 | + ); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
| 41 | - { |
|
| 40 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
| 41 | + { |
|
| 42 | 42 | |
| 43 | - if (!$class = $input->getOption('class')) { |
|
| 44 | - $output->writeln("Model not set"); |
|
| 45 | - return; |
|
| 46 | - } |
|
| 43 | + if (!$class = $input->getOption('class')) { |
|
| 44 | + $output->writeln("Model not set"); |
|
| 45 | + return; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - if ($input->getArgument('command') == "seed:reset" && $class::reset()) { |
|
| 49 | - $output->writeln(sprintf("Seed %s reset success!", $class)); |
|
| 50 | - } else { |
|
| 51 | - $number = $input->getOption('amount'); |
|
| 52 | - $class::build($number > 1 ? $number : 1); |
|
| 53 | - $output->writeln(sprintf("Seed %s amount %s create success!", $class, $number)); |
|
| 54 | - } |
|
| 55 | - } |
|
| 48 | + if ($input->getArgument('command') == "seed:reset" && $class::reset()) { |
|
| 49 | + $output->writeln(sprintf("Seed %s reset success!", $class)); |
|
| 50 | + } else { |
|
| 51 | + $number = $input->getOption('amount'); |
|
| 52 | + $class::build($number > 1 ? $number : 1); |
|
| 53 | + $output->writeln(sprintf("Seed %s amount %s create success!", $class, $number)); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -21,23 +21,23 @@ |
||
| 21 | 21 | |
| 22 | 22 | protected function execute(InputInterface $input, OutputInterface $output) |
| 23 | 23 | { |
| 24 | - $finder = \Symfony\Component\Finder\Finder::create(); |
|
| 24 | + $finder = \Symfony\Component\Finder\Finder::create(); |
|
| 25 | 25 | |
| 26 | - $root_path = __DIR__ . "../../../.."; |
|
| 26 | + $root_path = __DIR__ . "../../../.."; |
|
| 27 | 27 | |
| 28 | - $iterator = $finder |
|
| 29 | - ->files() |
|
| 30 | - ->in($root_path . "/vendor/*/*/db"); |
|
| 28 | + $iterator = $finder |
|
| 29 | + ->files() |
|
| 30 | + ->in($root_path . "/vendor/*/*/db"); |
|
| 31 | 31 | |
| 32 | - foreach ($iterator as $file) { |
|
| 32 | + foreach ($iterator as $file) { |
|
| 33 | 33 | |
| 34 | - if (!copy($file->getRealpath(), $root_path . '/db/' . $file->getRelativePathname())) { |
|
| 35 | - $output->writeln( sprintf("error copy migration %s...", $file->getRelativePathname()) ); |
|
| 36 | - } |
|
| 37 | - else{ |
|
| 38 | - $output->writeln( sprintf("copy migration %s", $file->getRelativePathname()) ); |
|
| 39 | - } |
|
| 40 | - } |
|
| 34 | + if (!copy($file->getRealpath(), $root_path . '/db/' . $file->getRelativePathname())) { |
|
| 35 | + $output->writeln( sprintf("error copy migration %s...", $file->getRelativePathname()) ); |
|
| 36 | + } |
|
| 37 | + else{ |
|
| 38 | + $output->writeln( sprintf("copy migration %s", $file->getRelativePathname()) ); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | $output->writeln("completed!"); |
| 43 | 43 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | // exit('f'); |
| 29 | 29 | // } |
| 30 | 30 | |
| 31 | - /** |
|
| 31 | + /** |
|
| 32 | 32 | * Gets the default commands that should always be available. |
| 33 | 33 | * |
| 34 | 34 | * @return array An array of default Command instances |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | $defaultCommands[] = new \Symfony\Component\Console\Command\HelpCommand(); |
| 43 | 43 | |
| 44 | - $defaultCommands[] = new \Frameworkless\Console\Commands\TestCommand(); |
|
| 44 | + $defaultCommands[] = new \Frameworkless\Console\Commands\TestCommand(); |
|
| 45 | 45 | |
| 46 | 46 | return $defaultCommands; |
| 47 | 47 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | |
| 67 | - function __o(){ |
|
| 67 | + function __o(){ |
|
| 68 | 68 | |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | } |
| 71 | 71 | \ No newline at end of file |
@@ -12,84 +12,84 @@ |
||
| 12 | 12 | class IndexController |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var Twig_Environment |
|
| 17 | - */ |
|
| 18 | - private $twig; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * |
|
| 22 | - * @var \Models\User\UserRepository $UserRepository |
|
| 23 | - */ |
|
| 24 | - protected $UserRepository; |
|
| 25 | - |
|
| 26 | - protected $debugbar; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * IndexController, constructed by container |
|
| 30 | - * |
|
| 31 | - * @param Twig_Environment $twig |
|
| 32 | - */ |
|
| 33 | - public function __construct( |
|
| 34 | - Twig_Environment $twig, UserRepository $UserRepository, StandardDebugBar $debugbar, Logger $logger |
|
| 35 | - ) |
|
| 36 | - { |
|
| 37 | - $this->twig = $twig; |
|
| 38 | - $this->UserRepository = $UserRepository; |
|
| 39 | - $this->debugbar = $debugbar; |
|
| 40 | - |
|
| 41 | - $logger->addDebug('start work', [1, 2, 'test']); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Return index page (/) |
|
| 46 | - * |
|
| 47 | - * @param array $args |
|
| 48 | - * @return Response |
|
| 49 | - */ |
|
| 50 | - public function get($args) |
|
| 51 | - { |
|
| 52 | - $debugbarRenderer = $this->debugbar->getJavascriptRenderer("/assets/debug_bar"); |
|
| 53 | - |
|
| 54 | - $Users = $this->UserRepository->findMany(); |
|
| 55 | - |
|
| 56 | - $table = \Donquixote\Cellbrush\Table\Table::create(); |
|
| 57 | - $table->addColNames([0, 1, 2]); |
|
| 58 | - $table->addClass('table table-striped'); |
|
| 59 | - $table->thead() |
|
| 60 | - ->addRowName('head row') |
|
| 61 | - ->th('head row', 0, 'Id') |
|
| 62 | - ->th('head row', 1, 'Имя') |
|
| 63 | - ->th('head row', 2, 'Email'); |
|
| 64 | - $i = 0; |
|
| 65 | - foreach ($Users as $User) { |
|
| 66 | - $table->addRow($i)->tdMultiple([ |
|
| 67 | - $User->getId(), |
|
| 68 | - $User->getName(), |
|
| 69 | - $User->getEmail()]); |
|
| 70 | - $i++; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return new Response($this->twig->render('pages/index.html.twig', [ |
|
| 74 | - "table" => $table->render(), |
|
| 75 | - "debugbar_Head" => $debugbarRenderer->renderHead(), |
|
| 76 | - "debugbar_Body" => $debugbarRenderer->render() |
|
| 77 | - ])); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - public function add($args) |
|
| 81 | - { |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - try { |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - return new Response("success create!"); |
|
| 15 | + /** |
|
| 16 | + * @var Twig_Environment |
|
| 17 | + */ |
|
| 18 | + private $twig; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * |
|
| 22 | + * @var \Models\User\UserRepository $UserRepository |
|
| 23 | + */ |
|
| 24 | + protected $UserRepository; |
|
| 25 | + |
|
| 26 | + protected $debugbar; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * IndexController, constructed by container |
|
| 30 | + * |
|
| 31 | + * @param Twig_Environment $twig |
|
| 32 | + */ |
|
| 33 | + public function __construct( |
|
| 34 | + Twig_Environment $twig, UserRepository $UserRepository, StandardDebugBar $debugbar, Logger $logger |
|
| 35 | + ) |
|
| 36 | + { |
|
| 37 | + $this->twig = $twig; |
|
| 38 | + $this->UserRepository = $UserRepository; |
|
| 39 | + $this->debugbar = $debugbar; |
|
| 40 | + |
|
| 41 | + $logger->addDebug('start work', [1, 2, 'test']); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Return index page (/) |
|
| 46 | + * |
|
| 47 | + * @param array $args |
|
| 48 | + * @return Response |
|
| 49 | + */ |
|
| 50 | + public function get($args) |
|
| 51 | + { |
|
| 52 | + $debugbarRenderer = $this->debugbar->getJavascriptRenderer("/assets/debug_bar"); |
|
| 53 | + |
|
| 54 | + $Users = $this->UserRepository->findMany(); |
|
| 55 | + |
|
| 56 | + $table = \Donquixote\Cellbrush\Table\Table::create(); |
|
| 57 | + $table->addColNames([0, 1, 2]); |
|
| 58 | + $table->addClass('table table-striped'); |
|
| 59 | + $table->thead() |
|
| 60 | + ->addRowName('head row') |
|
| 61 | + ->th('head row', 0, 'Id') |
|
| 62 | + ->th('head row', 1, 'Имя') |
|
| 63 | + ->th('head row', 2, 'Email'); |
|
| 64 | + $i = 0; |
|
| 65 | + foreach ($Users as $User) { |
|
| 66 | + $table->addRow($i)->tdMultiple([ |
|
| 67 | + $User->getId(), |
|
| 68 | + $User->getName(), |
|
| 69 | + $User->getEmail()]); |
|
| 70 | + $i++; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return new Response($this->twig->render('pages/index.html.twig', [ |
|
| 74 | + "table" => $table->render(), |
|
| 75 | + "debugbar_Head" => $debugbarRenderer->renderHead(), |
|
| 76 | + "debugbar_Body" => $debugbarRenderer->render() |
|
| 77 | + ])); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + public function add($args) |
|
| 81 | + { |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + try { |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + return new Response("success create!"); |
|
| 90 | 90 | |
| 91 | - } catch(\Exception $ex) { |
|
| 92 | - return new Response("system error:" . $ex->getMessage()); |
|
| 93 | - } |
|
| 94 | - } |
|
| 91 | + } catch(\Exception $ex) { |
|
| 92 | + return new Response("system error:" . $ex->getMessage()); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | 95 | } |
@@ -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 | } |