public static function getRoutes($path) { $routes = new \Symfony\Component\Routing\RouteCollection(); $finder = new \Symfony\Component\Finder\Finder(); $finder->name('*.php'); $finder->files()->in($path); if (!$finder->count()) { throw new Exception('No routes found in ' . $path); } foreach ($finder as $entry) { $route_path = $entry->getRelativePath(); $basename = $entry->getBasename('.php'); $cleaned = str_replace('/', '_', str_replace('-', '_', $route_path . $basename)); $route = $route_path . ($basename === 'index' ? '' : '/' . $basename); /* if (strrchr($route, '-')) { $sluglen = strlen(strrchr($route, '-')); $route2 = substr($route, 0, strlen($route) - $sluglen + 1) . '{slug}'; $basename2 = substr($basename, 0, $basename - $sluglen + 1); } else { $route2 = $route; $basename2 = $basename; } */ $routes->add($cleaned, new \Symfony\Component\Routing\Route($route, ['_controller' => 'build', 'php_file' => $entry->getRealPath(), 'file_root' => $route_path . '/' . $basename, 'name' => '.+'])); $routes->add('slash' . $cleaned, new \Symfony\Component\Routing\Route($route . '/', ['_controller' => 'build', 'php_file' => $entry->getRealPath(), 'file_root' => $route_path . '/' . $basename, 'name' => '.+'])); } return $routes; }
function getFilesFromPathByEnv(\LaravelSeed\Contracts\ProviderInterface $provider) { $finder = new Symfony\Component\Finder\Finder(); $files = []; $finder->name("/\\_" . $provider->getEnv() . "\\.(\\w{1,4})\$/i"); foreach ($finder->in($provider->getConfig('path')) as $file) { $files[] = $file->getPath() . '/' . $file->getFilename(); } return $files; }
/** * @param $directory * @param array $exclude * @param array $pattern * * @return Translations */ public function fromDirectory($directory, $translations = null, $exclude = ['languages'], $pattern = ['*.php', '*.phtml']) { if (!$translations) { $translations = new Translations(); } // fetch strings $sourcesFinder = new \Symfony\Component\Finder\Finder(); $sourcesFinder->files()->in($directory)->exclude($exclude); foreach ($pattern as $filePattern) { $sourcesFinder->name($filePattern); } $sourcesList = iterator_to_array($sourcesFinder->getIterator()); $sourcesList = array_map('strval', $sourcesList); foreach ($sourcesList as $sourceFile) { $this->fromFile($sourceFile, $translations); } return $translations; }
protected function execute(InputInterface $input, OutputInterface $output) { $dir = __DIR__ . '/../../../../'; $projectHome = realpath($dir); $output->writeln($projectHome); $finder = new \Symfony\Component\Finder\Finder(); $finder->in($projectHome . '/Tekstove'); $finder->name('*.php'); $finder->path('/\\/Base\\//')->path('/\\/Map\\//'); $this->handleFinder($finder, $output, $projectHome); $finderNewFiles = new \Symfony\Component\Finder\Finder(); $finderNewFiles->in($projectHome . '/Tekstove'); $finderNewFiles->name('*.php'); $this->handleFinder($finderNewFiles, $output, $projectHome, false); $fs = new \Symfony\Component\Filesystem\Filesystem(); $fs->remove($projectHome . '/Tekstove'); $output->writeln('<info>Command result.</info>'); }
/** * @param array $directories * @param array $excludes * @param array $suffixes * @return array * @since Method available since Release 1.7.0 */ protected function findFiles(array $directories, array $excludes, array $suffixes) { $files = array(); $finder = new Symfony\Component\Finder\Finder(); $iterate = FALSE; try { foreach ($directories as $directory) { if (!is_file($directory)) { $finder->in($directory); $iterate = TRUE; } else { $files[] = realpath($directory); } } foreach ($excludes as $exclude) { $finder->exclude($exclude); } foreach ($suffixes as $suffix) { $finder->name('*' . $suffix); } } catch (Exception $e) { $this->showError($e->getMessage() . "\n"); exit(1); } if ($iterate) { foreach ($finder as $file) { $files[] = $file->getRealpath(); } } return $files; }
private function isCacheExpired($cache_path, $path) { if (!file_exists($cache_path)) { return __LINE__; } if (!file_exists($path)) { return __LINE__; } $cache_time = filemtime($path); $this->cache_expired_time = $cache_time; $dirs = (include $path); $cache_dir = $this->container->getParameter('kernel.root_dir') . '/Resources/SymforceAdminBundle/src/'; $root_dir = dirname($this->container->getParameter('kernel.root_dir')) . '/'; foreach ($dirs as $dir => $entities) { if ($dir) { foreach ($entities as $entity_path => $admin_path) { $_entity_path = $root_dir . $dir . $entity_path; if (!file_exists($_entity_path)) { return __LINE__; } if (filemtime($_entity_path) > $cache_time) { return __LINE__; } } } else { foreach ($entities as $resource_path => $_file_expire_time) { $resource_full_path = $root_dir . $resource_path; if (!file_exists($resource_full_path)) { return __LINE__; } if (filemtime($resource_full_path) > $cache_time) { return __LINE__; } } } } if ($this->container->getParameter('kernel.debug')) { foreach ($dirs as $dir => $_files) { if ($dir) { $finder = new \Symfony\Component\Finder\Finder(); $finder->name('*.php'); foreach ($finder->in($root_dir . '/' . $dir) as $file) { $_file = $file->getRelativePathname(); if (!isset($_files[$_file])) { return __LINE__; } } } } } return $this->container->getParameter('sf.admin.debug'); }
/** * Run AutoMOD test. * * @param \phpbb\titania\entity\package $package * @param string $phpbb_path Path to phpBB files we run the test on * @param string $details Will hold the details of the mod * @param string $results Will hold the results for output * @param string $bbcode_results Will hold the results for storage * @return bool true on success, false on failure */ public function run_automod_test($package, $phpbb_path, &$details, &$results, &$bbcode_results) { require $this->phpbb_root_path . 'includes/functions_transfer.' . $this->php_ext; require $this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext; require $this->ext_root_path . 'includes/library/automod/acp_mods.' . $this->php_ext; require $this->ext_root_path . 'includes/library/automod/editor.' . $this->php_ext; require $this->ext_root_path . 'includes/library/automod/mod_parser.' . $this->php_ext; require $this->ext_root_path . 'includes/library/automod/functions_mods.' . $this->php_ext; $this->user->add_lang_ext('phpbb/titania', 'automod'); // Find the main modx file $modx_root = $package->find_directory(array('files' => array('required' => 'install*.xml'))); if ($modx_root === null) { $this->user->add_lang_ext('phpbb/titania', 'contributions'); $this->errors[] = $this->user->lang['COULD_NOT_FIND_ROOT']; return false; } $modx_root = $package->get_temp_path() . '/' . $modx_root . '/'; $modx_file = false; if (file_exists($modx_root . 'install.xml')) { $modx_file = $modx_root . 'install.xml'; } else { $finder = new \Symfony\Component\Finder\Finder(); $finder->name('install*.xml')->depth(0)->in($modx_root); if ($finder->count()) { foreach ($finder as $file) { $modx_file = $file->getPathname(); break; } } } if (!$modx_file) { $this->user->add_lang_ext('phpbb/titania', 'contributions'); $this->errors[] = $this->user->lang['COULD_NOT_FIND_ROOT']; return false; } // HAX global $phpbb_root_path; $phpbb_root_path = $phpbb_path; // The real stuff $acp_mods = new \acp_mods(); $acp_mods->mods_dir = $this->ext_config->__get('contrib_temp_path'); $acp_mods->mod_root = $modx_root; $editor = new \editor_direct(); $details = $acp_mods->mod_details($modx_file, false); $actions = $acp_mods->mod_actions($modx_file); $installed = $acp_mods->process_edits($editor, $actions, $details, false, true, false); // Reverse HAX $phpbb_root_path = $this->phpbb_root_path; $this->template->set_filenames(array('automod' => 'contributions/automod.html', 'automod_bbcode' => 'contributions/automod_bbcode.html')); $this->template->assign_var('S_AUTOMOD_SUCCESS', $installed); $results = $this->template->assign_display('automod'); $bbcode_results = $this->template->assign_display('automod_bbcode'); return $installed; }
public function getPicture() { if (!isset($this->picture)) { $finder = new \Symfony\Component\Finder\Finder(); $finder->name($this->getId() . '.*')->in(realpath(WEB_DIRECTORY . '/uploads/'))->files()->depth('== 0'); if (count($finder) > 0) { foreach ($finder as $file) { $this->picture = $file; } } } return $this->picture; }
private function generateExpireCheckCache($expire_check_path) { $root_dir = dirname($this->container->getParameter('kernel.root_dir')); $fs = new \Symfony\Component\Filesystem\Filesystem(); $bundles = array(); foreach ($this->admin_generators as $key => $admin) { if (isset($bundles[$admin->bundle_name])) { continue; } $file = $admin->getFilename(); $file = trim($fs->makePathRelative($file, $root_dir), '/'); $bundles[$admin->bundle_name] = dirname($file) . '/'; continue; if (!isset($dirs[$_dir])) { $dirs[$_dir] = array(); } $_entity_file = basename($file); $dirs[$_dir][$_entity_file] = filemtime($admin->getFilename()); } $dirs = array(); foreach ($bundles as $entity_dir) { $finder = new \Symfony\Component\Finder\Finder(); $finder->name('*.php'); foreach ($finder->in($root_dir . '/' . $entity_dir) as $file) { $dirs[$entity_dir][$file->getRelativePathname()] = filemtime($file->getRealpath()); } } $default_resources = array('app/config/symforce/admin.yml'); foreach ($default_resources as $file) { $dirs[0][$file] = filemtime($root_dir . '/' . $file); } foreach ($this->expire_check_resources as $file) { $_file = trim($fs->makePathRelative($file, $root_dir), '/'); if (!in_array($_file, $dirs[0])) { $dirs[0][$_file] = filemtime($file); } } /** * @todo add yml configure check */ \Dev::write_file($expire_check_path, '<' . '?php return ' . var_export($dirs, 1) . ';'); }
function fileList($patterns) { $patterns = (array) $patterns; $finder = new \Symfony\Component\Finder\Finder(); $finder->files(); foreach ($patterns as $p) { $finder->name($p); } return $finder; }