protected function execute(InputInterface $input, OutputInterface $output) { $arr = array(); $names = array(); $collections = false; if (is_dir(DIR_REPOSITORY)) { $it = new \FilesystemIterator(DIR_REPOSITORY, \FilesystemIterator::SKIP_DOTS); while ($it->valid()) { if (!$it->isDot() && !$it->isDir()) { $nm = $it->getBasename('.php'); $cl = '\\Repository\\' . $nm; if (class_exists($cl)) { $names[] = $nm; $arr[] = " /** @return {$cl} */\n" . " public function " . StaticStringy::camelize($nm) . "()\n" . " {\n" . " return \$this->getRepository('{$nm}');\n" . " }"; $collections .= " \$this->setRepositoryClass('{$nm}', '{$cl}');\n"; } } $it->next(); } } $code = "<?php\n\nnamespace Base;\n\n" . "/** Этот файл сгенерирован автоматически командой db:manager */\n" . "class Manager extends \\SQRT\\DB\\Manager\n{\n" . " function __construct()\n" . " {\n" . " \$this->addConnection(DB_HOST, DB_USER, DB_PASS, DB_NAME);\n" . " \$this->setPrefix(PREFIX);\n" . ($collections ? "\n" . $collections : '') . " }\n\n" . join("\n\n", $arr) . "\n" . "}"; $file = DIR_APP . '/Base/Manager.php'; file_put_contents($file, $code); if (!empty($names)) { $output->writeln(sprintf('<info>Менеджер БД обновлен, список коллекций: %s</info>', join(', ', $names))); } else { $output->writeln('<info>Первичная инициализация менеджера БД</info>'); } }
protected function getSubDirectoriesInfos($rootDir, $infoFilename) { if ($rootDir[0] == '~') { if (DIRECTORY_SEPARATOR == '\\') { $rootDir = $_SERVER['USERPROFILE'] . substr($rootDir, 1); } else { $rootDir = $_SERVER['HOME'] . substr($rootDir, 1); } } $infos = array(); $it = new \FilesystemIterator($rootDir); foreach ($it as $subDir) { if ($it->isDot() || !$it->isDir()) { continue; } $defaultInfo = array('name' => $subDir->getFilename(), 'description' => '', 'dir' => $subDir->getPathname(), 'source' => $subDir->getPathname()); $infoPath = $subDir->getPathname() . DIRECTORY_SEPARATOR . $infoFilename; if (is_file($infoPath)) { $infos[] = array_merge($defaultInfo, Yaml::parse($infoPath)); } else { $infos[] = $defaultInfo; } } return $infos; }
protected function execute(InputInterface $input, OutputInterface $output) { $db = new \Base\Manager(); $limit = 10; $arr = array(); if (is_dir(DIR_SCHEMA)) { $it = new \FilesystemIterator(DIR_SCHEMA, \FilesystemIterator::SKIP_DOTS); while ($it->valid()) { if (!$it->isDot() && !$it->isDir()) { $nm = $it->getBasename('.php'); $cl = 'Schema\\' . $nm; if (class_exists($cl)) { $arr[$nm] = new $cl($db); } } $it->next(); } } $db->query('DROP TABLE IF EXISTS ' . $db->getPrefix() . 'phinxlog'); while ($limit--) { /** @var $schema Schema */ foreach ($arr as $nm => $schema) { try { $db->query('DROP TABLE IF EXISTS ' . $db->getPrefix() . $schema->getTable()); $output->writeln(sprintf('<info>Таблица %s сброшена</info>', $nm)); unset($arr[$nm]); } catch (\Exception $e) { } } if (empty($arr)) { $output->writeln(sprintf('<info>Все таблицы сброшены.</info>')); break; } } }