/** * @covers ::glob() */ public function testGlobStar() { $globDir = rtrim(realpath(__DIR__ . '/../TestFixtures/glob/'), '/') . '/'; $this->assertEquals(array($globDir . 'company/bilbo.txt', $globDir . 'company/dwarves/bifur.txt', $globDir . 'company/dwarves/bombur.txt', $globDir . 'company/dwarves/oin.txt', $globDir . 'company/dwarves/thorin.txt', $globDir . 'company/wizards/gandalf.txt', $globDir . 'company/wizards/radagast.txt', $globDir . 'lipsum/dolor/amet/adipiscit.txt', $globDir . 'lipsum/dolor/amet/elit.txt', $globDir . 'lipsum/dolor/amet/lorem.txt', $globDir . 'lipsum/dolor/dolor.txt', $globDir . 'lipsum/dolor/valuptatos.js', $globDir . 'lipsum/root.js', $globDir . 'newdir/dummy/dummy.js', $globDir . 'newdir/dummy/leaf.txt', $globDir . 'newdir/file.txt'), FilesystemUtils::glob($globDir . '**/*.*'), 'Failed to assert using a simple double star wildcard.'); $this->assertEquals(array($globDir . 'company/bilbo.txt', $globDir . 'company/dwarves/bifur.txt', $globDir . 'company/dwarves/bombur.txt', $globDir . 'company/dwarves/oin.txt', $globDir . 'company/dwarves/thorin.txt', $globDir . 'company/wizards/gandalf.txt', $globDir . 'company/wizards/radagast.txt', $globDir . 'lipsum/dolor/amet/adipiscit.txt', $globDir . 'lipsum/dolor/amet/elit.txt', $globDir . 'lipsum/dolor/amet/lorem.txt', $globDir . 'lipsum/dolor/dolor.txt', $globDir . 'lipsum/dolor/valuptatos.js', $globDir . 'lipsum/root.js', $globDir . 'newdir/dummy/dummy.js', $globDir . 'newdir/dummy/leaf.txt', $globDir . 'newdir/file.txt'), FilesystemUtils::glob($globDir . '**/*.*', GLOB_BRACE), 'Failed to assert using a simple double star wildcard with GLOB_BRACE flag.'); $this->assertEquals(array($globDir . 'app.js', $globDir . 'app.min.js', $globDir . 'company/bilbo.txt', $globDir . 'company/dwarves/bifur.txt', $globDir . 'company/dwarves/bombur.txt', $globDir . 'company/dwarves/oin.txt', $globDir . 'company/dwarves/thorin.txt', $globDir . 'company/wizards/gandalf.txt', $globDir . 'company/wizards/radagast.txt', $globDir . 'config.ini', $globDir . 'config.php', $globDir . 'config.xml', $globDir . 'config.yml', $globDir . 'dolor.txt', $globDir . 'global.js', $globDir . 'global.min.js', $globDir . 'ipsum.txt', $globDir . 'lipsum/dolor/amet/adipiscit.txt', $globDir . 'lipsum/dolor/amet/elit.txt', $globDir . 'lipsum/dolor/amet/lorem.txt', $globDir . 'lipsum/dolor/dolor.txt', $globDir . 'lipsum/dolor/valuptatos.js', $globDir . 'lipsum/root.js', $globDir . 'lorem.txt', $globDir . 'newdir/dummy/dummy.js', $globDir . 'newdir/dummy/leaf.txt', $globDir . 'newdir/file.txt'), FilesystemUtils::glob($globDir . '{,**}/*.*', GLOB_BRACE), 'Failed to assert using double star wildcard inside braces.'); $this->assertEquals(array($globDir . 'app.js', $globDir . 'app.min.js', $globDir . 'company/bilbo.txt', $globDir . 'company/dwarves/bifur.txt', $globDir . 'company/dwarves/bombur.txt', $globDir . 'company/dwarves/oin.txt', $globDir . 'company/dwarves/thorin.txt', $globDir . 'company/wizards/gandalf.txt', $globDir . 'company/wizards/radagast.txt', $globDir . 'config.ini', $globDir . 'config.php', $globDir . 'config.xml', $globDir . 'config.yml', $globDir . 'dolor.txt', $globDir . 'global.js', $globDir . 'global.min.js', $globDir . 'ipsum.txt', $globDir . 'lipsum/dolor/amet/adipiscit.txt', $globDir . 'lipsum/dolor/amet/elit.txt', $globDir . 'lipsum/dolor/amet/lorem.txt', $globDir . 'lipsum/dolor/dolor.txt', $globDir . 'lipsum/dolor/valuptatos.js', $globDir . 'lipsum/root.js', $globDir . 'lorem.txt', $globDir . 'newdir/dummy/dummy.js', $globDir . 'newdir/dummy/leaf.txt', $globDir . 'newdir/file.txt'), FilesystemUtils::glob($globDir . '{,**/}*.*', GLOB_BRACE), 'Failed to assert using double star wildcard inside braces, different style.'); $this->assertEquals(array($globDir . 'app.js', $globDir . 'app.min.js', $globDir . 'config.ini', $globDir . 'config.php', $globDir . 'config.xml', $globDir . 'config.yml', $globDir . 'dolor.txt', $globDir . 'global.js', $globDir . 'global.min.js', $globDir . 'ipsum.txt', $globDir . 'lorem.txt', $globDir . 'company/bilbo.txt', $globDir . 'company/dwarves/bifur.txt', $globDir . 'company/dwarves/bombur.txt', $globDir . 'company/dwarves/oin.txt', $globDir . 'company/dwarves/thorin.txt', $globDir . 'company/wizards/gandalf.txt', $globDir . 'company/wizards/radagast.txt', $globDir . 'lipsum/root.js', $globDir . 'lipsum/dolor/dolor.txt', $globDir . 'lipsum/dolor/valuptatos.js', $globDir . 'lipsum/dolor/amet/adipiscit.txt', $globDir . 'lipsum/dolor/amet/elit.txt', $globDir . 'lipsum/dolor/amet/lorem.txt', $globDir . 'newdir/file.txt', $globDir . 'newdir/dummy/dummy.js', $globDir . 'newdir/dummy/leaf.txt'), FilesystemUtils::glob($globDir . '{,**/}*.*', FilesystemUtils::GLOB_ROOTFIRST | GLOB_BRACE), 'Failed to sort with root first.'); $this->assertEquals(array($globDir . 'company/dwarves/bifur.txt', $globDir . 'company/dwarves/bombur.txt', $globDir . 'company/dwarves/oin.txt', $globDir . 'company/dwarves/thorin.txt', $globDir . 'company/wizards/gandalf.txt', $globDir . 'company/wizards/radagast.txt', $globDir . 'company/bilbo.txt', $globDir . 'lipsum/dolor/amet/adipiscit.txt', $globDir . 'lipsum/dolor/amet/elit.txt', $globDir . 'lipsum/dolor/amet/lorem.txt', $globDir . 'lipsum/dolor/dolor.txt', $globDir . 'lipsum/dolor/valuptatos.js', $globDir . 'lipsum/root.js', $globDir . 'newdir/dummy/dummy.js', $globDir . 'newdir/dummy/leaf.txt', $globDir . 'newdir/file.txt', $globDir . 'app.js', $globDir . 'app.min.js', $globDir . 'config.ini', $globDir . 'config.php', $globDir . 'config.xml', $globDir . 'config.yml', $globDir . 'dolor.txt', $globDir . 'global.js', $globDir . 'global.min.js', $globDir . 'ipsum.txt', $globDir . 'lorem.txt'), FilesystemUtils::glob($globDir . '{,**/}*.*', FilesystemUtils::GLOB_CHILDFIRST | GLOB_BRACE), 'Failed to sort with child first.'); }
/** * Reads config files from the given directory, but only the ones called `config.(php|yml|yaml)`. * * Optionally, if `$env` is defined, then it will also try to load `config.$env.(php|yml|yaml)` files. * * PHP config files are loaded before the YML files. * * @param string $dir Directory which should be searched for config files. * @param string $env [optional] Environment for which to load additional files. Default: `null`. * @return Config */ public static function readFromDir($dir, $env = null) { $dir = rtrim($dir, DS) . DS; $config = new static(); $files = FilesystemUtils::glob($dir . 'config.{yml,yaml,php}', GLOB_BRACE); if ($env) { $files = array_merge($files, FilesystemUtils::glob($dir . 'config.' . $env . '.{yml,yaml,php}', GLOB_BRACE)); } foreach ($files as $file) { $config->loadFromFile($file); } return $config; }
/** * Reads routes for the given module and registers them automatically. * * @param AbstractModule $module Module object. */ public function readModuleRoutes(AbstractModule $module) { $moduleName = $module->getName(); $routesDir = rtrim($module->getModuleDir(), '/') . '/Controllers'; if (!is_dir($routesDir)) { return; } $moduleNamespace = $module->getNamespace() . NS . 'Controllers' . NS; $routesDirLength = strlen($routesDir . '/'); $files = FilesystemUtils::glob($routesDir . '/{,**/}*.php', GLOB_BRACE); foreach ($files as $file) { // remove full path to the routes dir, so we're left only with relative path $file = substr($file, $routesDirLength); // also remove extension $file = substr($file, 0, -4); // build full class name $subNamespace = str_replace('/', NS, $file); $class = $moduleNamespace . $subNamespace; // class_exists autoloads the file if (!class_exists($class)) { continue; } // check if this class can be instantiated, if not, skip it $reflection = new ReflectionClass($class); if (!$reflection->isInstantiable()) { continue; } $this->addRoute($moduleName . ':' . $subNamespace, $class, $moduleName, $module->getUrlPrefix() . $class::_getUrl()); } }
/** * Returns files to watch. * * @return array */ public function filesToWatch() { $files = FilesystemUtils::glob($this->templatesDir . '{,**/}*.html.twig', GLOB_BRACE); return $files; }
/** * Generates all pages. * * @return boolean */ public function generateAll() { // force clearing cache before every generation $this->templating->clearCache(); $this->eventManager->trigger(new WillGenerate()); $templates = FilesystemUtils::glob($this->templatesDir . '{,**/}*.html.twig', GLOB_BRACE); foreach ($templates as $template) { // exclude if a partial template, ie. ends with ".inc.html.twig" if (preg_match('/\\.inc\\.html\\.twig$/i', $template)) { continue; } $this->addToQueue($template); } $this->processQueue(); $this->eventManager->trigger(new DidGenerate()); return true; }
/** * Expands GLOB resource patterns. * * @param string $resource Resource name. * @param string $type Type of the resource. * @return array */ public function expand($resource, $type) { list($moduleName, $subDir, $filePattern) = $this->parseResourceName($resource); $resourceLocation = $moduleName . ':' . $subDir . ':'; // read from application dir $appDir = rtrim($this->_application->getApplicationDir(), DS) . DS . 'Resources' . DS; // if a module name was specified then point to a subfolder with the module name if (!empty($moduleName)) { // check for module existence in the first place if (!$this->_application->hasModule($moduleName)) { throw new ResourceNotFoundException('There is no module "' . $moduleName . '" registered, so cannot find its resource.'); } $appDir = $appDir . $moduleName . DS; } $appDir = $this->buildResourcePath($appDir, $type, $subDir, ''); $appFiles = FilesystemUtils::glob($appDir . $filePattern, FilesystemUtils::GLOB_ROOTFIRST | GLOB_BRACE); $resources = array(); foreach ($appFiles as $file) { $resources[] = $resourceLocation . substr($file, mb_strlen($appDir)); } // now take care of the module dir if ($moduleName) { $module = $this->_application->getModule($moduleName); $moduleDir = rtrim($module->getModuleDir(), DS) . DS . 'Resources' . DS; $moduleDir = $this->buildResourcePath($moduleDir, $type, $subDir, ''); $moduleFiles = FilesystemUtils::glob($moduleDir . $filePattern, GLOB_BRACE); foreach ($moduleFiles as $file) { $resources[] = $resourceLocation . substr($file, mb_strlen($moduleDir)); } } $resources = array_unique($resources); return ArrayUtils::sortPaths($resources, true); }
/** * Returns a list of files to watch. * * @return array */ public function filesToWatch() { $files = FilesystemUtils::glob($this->articlesDir . '*.md'); $files[] = $this->dataFile; return $files; }
/** * Configures a module in context of the given application. * * @param AbstractModule $module Module to be configured. * @param AbstractApplication $application Application for which this module should be configured. * @param string $env [optional] Environment in which the application is running. Default: `dev`. * @param boolean $debug [optional] Debug mode status for the application. Default: `true`. */ public function configureModule(AbstractModule $module, AbstractApplication $application, $env = 'dev', $debug = true) { $container = $application->getContainer(); $config = $application->getConfig(); // define config for the module $container->register('config.' . $module->getName(), array('extends' => 'config_module.abstract')); // add method calls to load appropriate config files to the definition $configDefinition = $container->getDefinition('config.' . $module->getName()); $configDir = rtrim($module->getConfigDir(), DS); $configFiles = array_merge(FilesystemUtils::glob($configDir . '/config.{yml,yaml,php}', GLOB_BRACE), FilesystemUtils::glob($configDir . '/config.' . $env . '.{yml,yaml,php}', GLOB_BRACE)); foreach ($configFiles as $file) { $configDefinition->addMethodCall('loadFromFile', array($file)); } // add method call to apply the config from the application config $configDefinition->addMethodCall('apply', array($config->getNamespace($module->getName()))); // let it configure itself $module->configure(); }