/** * Instantiates the repository for the underlying file system * * A file system iterator has to be injected. * * The default file extension that will be included in the scan is "mig". * * @param \FilesystemIterator $directory The iterator to use * @param string $extension The file extension to look for * * @throws \Bytepark\Component\Migration\Exception\UnitIsAlreadyPresentException * @throws \InvalidArgumentException */ public function __construct(\FilesystemIterator $directory, $extension = 'mig') { $this->basePath = $directory->getPath(); $this->extension = $extension; $this->buildMigrations($directory); }
/** * _initTemp * * @param string $baseDir base dir * @param string $bundle bundle * * @throws Exception * @return void */ private function _initTemp($baseDir, $bundle = null) { $baseDir = realpath($baseDir); if (!is_dir($baseDir)) { throw new Exception('无效的模板目录', 500); } $this->_baseTempDir = new FilesystemIterator($baseDir, FilesystemIterator::KEY_AS_FILENAME); $currentRepo = $this->_baseTempDir; if (!empty($bundle)) { $path = trim($bundle, '/'); $dir = explode('/', $path); while ($cDir = current($dir)) { $exist = false; foreach ($currentRepo as $key => $child) { if ($child->isDir() && $key == $cDir) { $currentRepo = new FilesystemIterator($child->getPathname(), FilesystemIterator::KEY_AS_FILENAME); $exist = true; break; } } if ($exist == false) { $pathname = realpath($currentRepo->getPath()) . '/' . $cDir; if (mkdir($pathname)) { $currentRepo = new FilesystemIterator($pathname, FilesystemIterator::KEY_AS_FILENAME); } else { throw new Exception('权限不够,创建目录失败'); } } next($dir); } } $this->_currentTempDir = $currentRepo; }