/** * Returns an array of YAML files in the directory. * * @param string $basedir The base directory * * @return array * * @throws \BackBee\Config\Exception\InvalidBaseDirException Occurs if the base directory cannont be read */ private function getYmlFiles($basedir) { $ymlFiles = File::getFilesByExtension($basedir, self::EXTENSION); $defaultFile = $basedir . DIRECTORY_SEPARATOR . self::CONFIG_FILE . '.' . self::EXTENSION; if (is_file($defaultFile) && 1 < count($ymlFiles)) { // Ensure that config.yml is the first one $ymlFiles = array_diff($ymlFiles, array($defaultFile)); array_unshift($ymlFiles, $defaultFile); } foreach ($ymlFiles as &$file) { $name = basename($file); if (in_array(substr($name, 0, strrpos($name, '.')), $this->yml_names_to_ignore)) { $file = null; } } return array_filter($ymlFiles); }
public function testGetFilesByExtension() { $this->assertEquals([$this->folderPath . DIRECTORY_SEPARATOR . 'bar.txt', $this->folderPath . DIRECTORY_SEPARATOR . 'foo.txt'], File::getFilesByExtension($this->folderPath, 'txt')); $this->assertEquals([$this->folderPath . DIRECTORY_SEPARATOR . 'baz.php'], File::getFilesByExtension($this->folderPath, 'php')); $this->assertEquals([$this->folderPath . DIRECTORY_SEPARATOR . 'backbee.yml'], File::getFilesByExtension($this->folderPath, 'yml')); $this->assertEquals([$this->folderPath . DIRECTORY_SEPARATOR . 'noextension'], File::getFilesByExtension($this->folderPath, '')); $this->assertEquals([], File::getFilesByExtension($this->folderPath, 'aaa')); }