private function runAllInFolder($folder) { Explorer::find()->files("*.php")->in($folder)->map(function ($key, $fileInfo) { /** @var \SplFileInfo $fileInfo */ if ($fileName = $fileInfo->getFilename()) { $className = str_replace('.php', '', $fileName); $this->runClass($className); } }); }
public function testFileSearchWithDate() { $explorer = Explorer::find()->in(__DIR__)->date('1470157800', '<'); $this->assertInstanceOf('Core\\FileSystem\\Explorer', $explorer); //$this->assertCount(1, $explorer); foreach ($explorer as $file) { /** @var \SplFileInfo $file */ $this->assertTrue($file->getMTime() < 1470157800); } }
private function readFromFile($path) { $items = []; Explorer::find()->files("*.php")->in($path)->map(function ($key, $fileInfo) use(&$items) { /** @var \SplFileInfo $fileInfo */ if ($path = $fileInfo->getPathname()) { $key = str_replace('.php', '', $key); $items[$key] = (require $path); } }); return $items; }
private function prepare() { $defaultMigrationFolder = $this->application()->appPath() . DIRECTORY_SEPARATOR . 'Migrations' . DIRECTORY_SEPARATOR; $migrationFolder = $this->options('folder', $defaultMigrationFolder); Explorer::find()->files('*.php')->in($migrationFolder)->map(function ($key, $fileInfo) use($migrationFolder, $defaultMigrationFolder) { /** @var \SplFileInfo $fileInfo */ if ($path = $fileInfo->getPath()) { if ($migrationFolder !== $defaultMigrationFolder) { require_once $path; $tokenizer = new Tokenizer($path); $class = $tokenizer->getFullyQualifiedClass(); } else { $class = str_replace('.php', '', $fileInfo->getFilename()); } $migrationModel = Migration::findOne(['migration' => $class]); if (!$migrationModel) { $migrationModel = new Migration(['migration' => $class, 'batch' => 0]); $migrationModel->save(); } } }); }