public function testThrowExceptionOnError() { $this->setExpectedException('Zend\\Stdlib\\Exception\\RuntimeException'); // run into a max path lengh error $path = '/' . str_repeat('a', 10000); Glob::glob($path); }
private function glob($pattern) { if (class_exists(Glob::class)) { return Glob::glob($pattern, Glob::GLOB_BRACE); } return glob($pattern, GLOB_BRACE); }
public function __invoke($file, $minify = null) { if (!is_file($this->getOptions()->getPublicDir() . $file)) { throw new \InvalidArgumentException('File "' . $this->getOptions()->getPublicDir() . $file . '" not found.'); } $less = new \lessc(); $info = pathinfo($file); $newFile = $this->getOptions()->getDestinationDir() . $info['filename'] . '.' . filemtime($this->getOptions()->getPublicDir() . $file) . '.css'; $_file = $this->getOptions()->getPublicDir() . $newFile; if (!is_file($_file)) { $globPattern = $this->getOptions()->getPublicDir() . $this->getOptions()->getDestinationDir() . $info['filename'] . '.*.css'; foreach (Glob::glob($globPattern, Glob::GLOB_BRACE) as $match) { if (preg_match("/^" . $info['filename'] . "\\.[0-9]{10}\\.css\$/", basename($match))) { unlink($match); } } $compiledFile = new \SplFileObject($_file, 'w'); $result = $less->compileFile($this->getOptions()->getPublicDir() . $file); if (is_null($minify) && $this->getOptions()->getMinify() || $minify === true) { $result = \CssMin::minify($result); } $compiledFile->fwrite($result); } return $newFile; }
public function testFallback() { if (!defined('GLOB_BRACE')) { $this->markTestSkipped('GLOB_BRACE not available'); } $this->assertEquals(glob(__DIR__ . '/_files/{alph,bet}a', GLOB_BRACE), Glob::glob(__DIR__ . '/_files/{alph,bet}a', Glob::GLOB_BRACE, true)); }
/** * Configurations loader. * * @param string $pathRole Glob role. * * @return array */ public static function load($pathRole = './config/{{*}}{{,*.local}}.php') { $config = []; foreach (Glob::glob($pathRole, Glob::GLOB_BRACE) as $file) { $config = ArrayUtils::merge($config, include $file); } return $config; }
public function getConfig() { $config = array_merge_recursive(require __DIR__ . '/core/config/module.config.php', require __DIR__ . '/core/config/navigation.config.php', require __DIR__ . '/core/config/router.config.php'); foreach (Glob::glob(__DIR__ . '/config/*.config.php') as $file) { $config = array_merge_recursive($config, require $file); } return $config; }
public function addDirectory($glob) { $this->list[] = array('type' => 'directory', 'value' => $glob); foreach (Glob::glob($glob, Glob::GLOB_BRACE) as $i) { $this->files[] = $i; } return $this; }
/** * @inheritdoc */ public function findAll() { $posts = []; foreach (Glob::glob('data/posts/*.md', Glob::GLOB_BRACE) as $file) { $posts[] = $this->parse(file_get_contents($file)); } return $posts; }
/** * Find pathnames matching a pattern. * * @param string $pattern * @param int $flags * @param bool $forceFallback * @return array */ public static function glob($pattern, $flags = 0, $forceFallback = false) { try { $result = ZendGlob::glob($pattern, $flags, $forceFallback); } catch (ZendRuntimeException $e) { $result = []; } return $result; }
/** * Clear datas with $uid key * @param mixed $uid * @return void */ public function clear($uid = null) { if ($uid) { if (!$this->has($uid)) { return false; } return @unlink($this->dir . '/' . $uid); } array_map('unlink', Glob::glob($this->dir . '/*', 0)); return true; }
/** * Get the versions of a module * * @param string $module * @param string $path * @return array|boolean */ public function getModuleVersions($module, $path = false) { $module = $this->normalizeModule($module); if (!$path) { $path = $this->getModuleSourcePath($module); } $versions = array(); foreach (Glob::glob($path . DIRECTORY_SEPARATOR . 'V*') as $dir) { if (preg_match('/\\V(?P<version>\\d+)$/', $dir, $matches)) { $versions[] = (int) $matches['version']; } } return $versions; }
public static function load($directory) { $directory = rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $env = getenv('APPLICATION_ENV') ?: 'production'; $pattern = sprintf('%s{,*.}{config,%s}.php', $directory, $env); $config = array(); foreach (Glob::glob($pattern, Glob::GLOB_BRACE) as $file) { if (!is_readable($file)) { continue; } $cfg = (include $file); $config = ArrayUtils::merge($config, $cfg); } return $config; }
/** * @inheritDoc */ public function collect($handle, $area = null) { $globPaths = $this->getGlobPaths($handle, $area); $tempStructure = new Config([], true); foreach ($globPaths as $globPath) { try { $configFiles = Glob::glob($globPath, Glob::GLOB_BRACE); } catch (RuntimeException $e) { // @codeCoverageIgnoreStart continue; // @codeCoverageIgnoreEnd } foreach ($configFiles as $configFile) { $config = ConfigFactory::fromFile($configFile, true); $tempStructure->merge($config); } } return $tempStructure; }
/** * * @param string $handle */ protected function fetchHandle($handle) { $globPaths = $this->getGlobPaths($handle); foreach ($globPaths as $globPath) { try { $configFiles = Glob::glob($globPath, Glob::GLOB_BRACE); } catch (RuntimeException $e) { continue; } foreach ($configFiles as $configFile) { $config = ConfigFactory::fromFile($configFile, true); if ($includeHandles = $config->get(LayoutUpdaterInterface::INSTRUCTION_INCLUDE)) { foreach ($includeHandles as $includeHandle) { $this->fetchHandle($includeHandle); } } $this->layoutStructure->merge($config); } } }
/** * Get Resource Code by Module Name * * @param string $moduleName * @return string */ public function getResourceCode($moduleName) { $sqlResources = []; $dataResources = []; $modulePath = str_replace('_', '/', $moduleName); // Collect files by /app/code/{modulePath}/sql/*/ pattern $pattern = $this->directoryList->getPath(DirectoryList::MODULES) . '/' . $modulePath . '/sql/*'; $resourceDirs = Glob::glob($pattern, Glob::GLOB_ONLYDIR); if (!empty($resourceDirs)) { foreach ($resourceDirs as $resourceDir) { $sqlResources[] = basename($resourceDir); } } // Collect files by /app/code/{modulePath}/data/*/ pattern $pattern = $this->directoryList->getPath(DirectoryList::MODULES) . '/' . $modulePath . '/data/*'; $resourceDirs = Glob::glob($pattern, Glob::GLOB_ONLYDIR); if (!empty($resourceDirs)) { foreach ($resourceDirs as $resourceDir) { $dataResources[] = basename($resourceDir); } } $resources = array_unique(array_merge($sqlResources, $dataResources)); return array_shift($resources); }
/** * Given a path (glob or static), fetch the config and add it to the array * of configs to merge. * * @param string $path * @param string $type * @return ConfigListener */ protected function addConfigByPath($path, $type) { switch ($type) { case self::STATIC_PATH: $this->addConfig($path, ConfigFactory::fromFile($path)); break; case self::GLOB_PATH: // We want to keep track of where each value came from so we don't // use ConfigFactory::fromFiles() since it does merging internally. foreach (Glob::glob($path, Glob::GLOB_BRACE) as $file) { $this->addConfig($file, ConfigFactory::fromFile($file)); } break; } return $this; }
/** * Merge all config files matching a glob * * @param mixed $path * @return ConfigListener */ protected function mergePath($path) { switch ($path['type']) { case self::STATIC_PATH: $config = ConfigFactory::fromFile($path['path']); break; case self::GLOB_PATH: $config = ConfigFactory::fromFiles(Glob::glob($path['path'], Glob::GLOB_BRACE)); break; } $this->mergeTraversableConfig($config); if ($this->getOptions()->getConfigCacheEnabled()) { $this->updateCache(); } return $this; }
<?php use Zend\Stdlib\ArrayUtils; use Zend\Stdlib\Glob; /** * Configuration files are loaded in a specific order. First ``global.php``, then ``*.global.php``. * then ``local.php`` and finally ``*.local.php``. This way local settings overwrite global settings. * * The configuration can be cached. This can be done by setting ``config_cache_enabled`` to ``true``. * * Obviously, if you use closures in your config you can't cache it. */ $cachedConfigFile = 'data/cache/app_config.php'; $config = []; if (is_file($cachedConfigFile)) { // Try to load the cached config $config = (include $cachedConfigFile); } else { // Load configuration from autoload path foreach (Glob::glob('config/autoload/{{,*.}global,{,*.}local}.php', Glob::GLOB_BRACE) as $file) { $config = ArrayUtils::merge($config, include $file); } // Cache config if enabled if (isset($config['config_cache_enabled']) && $config['config_cache_enabled'] === true) { file_put_contents($cachedConfigFile, '<?php return ' . var_export($config, true) . ';'); } } // Return an ArrayObject so we can inject the config as a service in Aura.Di // and still use array checks like ``is_array``. return new ArrayObject($config, ArrayObject::ARRAY_AS_PROPS);
public function __invoke() { return Factory::fromFiles(Glob::glob(__DIR__ . '/../config/{,*.}config.php', Glob::GLOB_BRACE)); }
/** * @inheritdoc */ public function getFiles() { $files = ZendGlob::glob($this->pattern, $this->flags); return $files; }
/** * Retrieve versions by module * * Checks each REST and RPC service name for a * version subnamespace; if found, that version * is added to the list. * * @param string $moduleName * @param ApigilityProviderInterface|ApigilityModuleInterface $module * @throws Exception\InvalidArgumentException * @return array */ protected function getVersionsByModule($moduleName, $module) { if (!$module instanceof ApigilityProviderInterface && !$module instanceof ApigilityModuleInterface) { throw new Exception\InvalidArgumentException('Expected ApigilityProviderInterface or ApigilityModuleInterface'); } $path = $this->detectSourcePathFromModule($moduleName, $module); $versions = []; foreach (Glob::glob($path . DIRECTORY_SEPARATOR . 'V*') as $dir) { if (preg_match('/\\V(?P<version>\\d+)$/', $dir, $matches)) { $versions[] = (int) $matches['version']; } } if (!$versions) { return [1]; } sort($versions); return $versions; }
* The configuration can be cached. This can be done by setting ``config_cache_enabled`` to ``true``. * * Obviously, if you use closures in your config you can't cache it. */ $cachedConfigFile = 'data/cache/app_config.php'; $config = []; if (is_file($cachedConfigFile)) { // Try to load the cached config $config = (include $cachedConfigFile); } else { // Load configuration from autoload path foreach (Glob::glob('config/autoload/{{,*.}global,{,*.}local}.php', Glob::GLOB_BRACE) as $file) { $config = ArrayUtils::merge($config, include $file); } // Load configuration from apps $dir = array_diff(scandir('src/'), ['..', '.']); foreach ($dir as $app) { if (is_dir('src/' . $app . '/Config')) { foreach (Glob::glob('src/' . $app . '/Config/{{,*.}global,{,*.}local}.php', Glob::GLOB_BRACE) as $file) { $config = ArrayUtils::merge($config, include $file); } } } // Cache config if enabled if (isset($config['config_cache_enabled']) && $config['config_cache_enabled'] === true) { file_put_contents($cachedConfigFile, '<?php return ' . var_export($config, true) . ';'); } } // Return an ArrayObject so we can inject the config as a service in Aura.Di // and still use array checks like ``is_array``. return new ArrayObject($config, ArrayObject::ARRAY_AS_PROPS);
<?php require __DIR__ . '/../vendor/autoload.php'; use Zend\Console\Console; use Pan\Core\Application; use DI\ContainerBuilder; use Pan\Core\Dispatcher; use Zend\Stdlib\Glob; use Zend\Stdlib\ArrayUtils; use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\Config; $config = []; foreach (Glob::glob('config/{{*}}{{,*.local}}.php', Glob::GLOB_BRACE) as $file) { $config = ArrayUtils::merge($config, include $file); } $builder = new ContainerBuilder(); $builder->addDefinitions($config); $container = $builder->build(); $configServiceManager = new Config($config['service_manager']); $container->set("service_manager", new ServiceManager($configServiceManager)); $application = new Application($config['app'], $config['version'], $config['routes'], Console::getInstance(), new Dispatcher($container)); $exit = $application->run(); exit($exit);
/** * @param string $path * @return array|false */ protected function getFiles($path) { return Glob::glob($this->config->getMagentoBasePath() . $path); }
/** * Given a path (glob or static), fetch the config and add it to the array * of configs to merge. * * @param string $path * @param string $type * @return array */ protected function getConfigsByPath($path, $type) { $getConfig = function ($config) { if ($config instanceof Traversable) { $config = ArrayUtils::iteratorToArray($config); } if (!is_array($config)) { throw new Exception\InvalidArgumentException(sprintf('Config being merged must be an array, ' . 'implement the Traversable interface, or be an ' . 'instance of Zend\\Config\\Config. %s given.', gettype($config))); } return $config; }; $configs = array(); switch ($type) { case ConfigListener::STATIC_PATH: $configs[$path] = $getConfig(ConfigFactory::fromFile($path)); break; case ConfigListener::GLOB_PATH: // We want to keep track of where each value came from so we don't // use ConfigFactory::fromFiles() since it does merging internally. foreach (Glob::glob($path, Glob::GLOB_BRACE) as $file) { $configs[$file] = $getConfig(ConfigFactory::fromFile($file)); } break; } return $configs; }
<?php use Zend\Stdlib\ArrayUtils; use Zend\Stdlib\Glob; /** * Configuration files are loaded in a specific order. First ``global.php``, * then ``*.global.php``. then ``local.php`` and finally ``*.local.php``. This * way local settings overwrite global settings. The configuration can be * cached. This can be done by setting ``config_cache_enabled`` to ``true``. * Obviously, if you use closures in your config you can't cache it. */ $cachedConfigFile = Configure::read('zendservicemanager.cache-file') ?: CACHE . 'zend-service-manager-cache.php'; $config = []; if (is_file($cachedConfigFile)) { // Try to load the cached config $config = (include $cachedConfigFile); } else { $configDir = Configure::read('zendservicemanager.autoload-dir') ?: APP . 'Config' . DS . 'Autoload' . DS; // Load configuration from autoload path foreach (Glob::glob($configDir . '{{,*.}global,{,*.}local}.php', Glob::GLOB_BRACE) as $file) { $config = ArrayUtils::merge($config, include $file); } // Cache config if enabled if (isset($config['config_cache_enabled']) && $config['config_cache_enabled'] === true) { file_put_contents($cachedConfigFile, '<?php return ' . var_export($config, true) . ';'); } } // Return an ArrayObject so we can inject the config as a service // and still use array checks like ``is_array``. return new ArrayObject($config, ArrayObject::ARRAY_AS_PROPS);
* local settings overwrite global settings. * * The configuration can be cached. This can be done by setting ``config_cache_enabled`` to ``true``. * * The configuration is stored in json so it is not depended on 3rd party libraries. Feel free to use something else * like Zend\Config\Writer to write PHP arrays. * * Obviously, if you use closures in your config you can't cache it. */ $cachedConfigFile = 'data/cache/app_config.php'; $config = []; if (is_file($cachedConfigFile)) { // Try to load the cached config $config = json_decode(file_get_contents($cachedConfigFile), true); } else { // Load configuration from autoload path foreach (Glob::glob('config/autoload/{{,*.}global,{,*.}local}.php', Glob::GLOB_BRACE) as $file) { $config = ArrayUtils::merge($config, include $file); } // Load configuration from autoload path foreach (Glob::glob('library/config/{{,*.}global,{,*.}local}.php', Glob::GLOB_BRACE) as $file) { $config = ArrayUtils::merge($config, include $file); } // Cache config if enabled if (isset($config['config_cache_enabled']) && $config['config_cache_enabled'] === true) { file_put_contents($cachedConfigFile, json_encode($config)); } } // Return an ArrayObject so we can inject the config as a service in Aura.Di // and still use array checks like ``is_array``. return new \ArrayObject($config, \ArrayObject::ARRAY_AS_PROPS);
/** * Retrieve versions by module * * Checks each REST and RPC service name for a * version subnamespace; if found, that version * is added to the list. * * @param string $moduleName * @param $module * @throws \ZF\Apigility\Admin\Exception\InvalidArgumentException * @internal param array $services * @return array */ protected function getVersionsByModule($moduleName, $module) { if (!$module instanceof ApigilityProviderInterface && !$module instanceof ApigilityModuleInterface) { throw new Exception\InvalidArgumentException('Expected ApigilityProviderInterface or ApigilityModuleInterface'); } $r = new ReflectionObject($module); $path = dirname($r->getFileName()); $dirSep = sprintf('(?:%s|%s)', preg_quote('/'), preg_quote('\\')); $pattern = sprintf('#%ssrc%s%s#', $dirSep, $dirSep, str_replace('\\', $dirSep, $moduleName)); if (!preg_match($pattern, $path)) { $path = sprintf('%s/src/%s', $path, str_replace('\\', '/', $moduleName)); } if (!file_exists($path)) { return array(1); } $versions = array(); foreach (Glob::glob($path . DIRECTORY_SEPARATOR . 'V*') as $dir) { if (preg_match('/\\V(?P<version>\\d+)$/', $dir, $matches)) { $versions[] = (int) $matches['version']; } } if (empty($versions)) { return array(1); } sort($versions); return $versions; }
public function testNonMatchingGlobReturnsArray() { $result = Glob::glob('/some/path/{,*.}{this,orthis}.php', Glob::GLOB_BRACE); $this->assertInternalType('array', $result); }
public function testConfigLoaderMergesConfigFromFiles() { $loader = new ConfigManager(Glob::glob('test/Resources/config/{{,*.}global,{,*.}local}.php', Glob::GLOB_BRACE), []); $config = $loader->getMergedConfig(); $this->assertEquals(['fruit' => 'banana', 'vegetable' => 'potato'], (array) $config); }