本文整理汇总了PHP中Symfony\Component\Finder\Finder::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::create方法的具体用法?PHP Finder::create怎么用?PHP Finder::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\Finder
的用法示例。
在下文中一共展示了Finder::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scan
/**
* Scan themes directory.
*/
public function scan()
{
$files = $this->finder->create()->in($this->getBasePath())->name('theme.json');
foreach ($files as $file) {
$this->register($file);
}
}
示例2: compile
/**
* Compiles psysh into a single phar file.
*
* @param string $pharFile The full path to the file to create
*/
public function compile($pharFile = 'psysh.phar')
{
if (file_exists($pharFile)) {
unlink($pharFile);
}
$this->version = Shell::VERSION;
$phar = new \Phar($pharFile, 0, 'psysh.phar');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
$finder = Finder::create()->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->notName('Autoloader.php')->in(__DIR__ . '/..');
foreach ($finder as $file) {
$this->addFile($phar, $file);
}
$finder = Finder::create()->files()->ignoreVCS(true)->name('*.php')->exclude('Tests')->in(__DIR__ . '/../../vendor/dnoegel/php-xdg-base-dir/src')->in(__DIR__ . '/../../vendor/jakub-onderka/php-console-color')->in(__DIR__ . '/../../vendor/jakub-onderka/php-console-highlighter')->in(__DIR__ . '/../../vendor/nikic/php-parser/lib')->in(__DIR__ . '/../../vendor/symfony/console')->in(__DIR__ . '/../../vendor/symfony/var-dumper')->in(__DIR__ . '/../../vendor/symfony/yaml');
foreach ($finder as $file) {
$this->addFile($phar, $file);
}
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/autoload.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/include_paths.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_files.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_psr4.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_real.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_namespaces.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_classmap.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/ClassLoader.php'));
// Stubs
$phar->setStub($this->getStub());
$phar->stopBuffering();
// $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../LICENSE'), false);
unset($phar);
}
示例3: gc
/**
* {@inheritDoc}
*/
public function gc($lifetime)
{
$files = Finder::create()->in($this->path)->files()->ignoreDotFiles(true)->date('<= now - ' . $lifetime . ' seconds');
foreach ($files as $file) {
$this->files->delete($file->getRealPath());
}
}
示例4: sync
/**
* Sync the media. Oh sync the media.
*
* @param string|null $path
* @param SyncMedia $syncCommand The SyncMedia command object, to log to console if executed by artisan.
*/
public function sync($path = null, SyncMedia $syncCommand = null)
{
set_time_limit(env('APP_MAX_SCAN_TIME', 600));
$path = $path ?: Setting::get('media_path');
$results = ['good' => [], 'bad' => [], 'ugly' => []];
// For now we only care about mp3 and ogg files.
// Support for other formats (AAC?) may be added in the future.
$files = Finder::create()->files()->name('/\\.(mp3|ogg)$/')->in($path);
foreach ($files as $file) {
$song = $this->syncFile($file);
if ($song === true) {
$results['ugly'][] = $file;
} elseif ($song === false) {
$results['bad'][] = $file;
} else {
$results['good'][] = $file;
}
if ($syncCommand) {
$syncCommand->logToConsole($file->getPathname(), $song);
}
}
// Delete non-existing songs.
$hashes = array_map(function ($f) {
return $this->getHash($f->getPathname());
}, array_merge($results['ugly'], $results['good']));
Song::whereNotIn('id', $hashes)->delete();
// Empty albums and artists should be gone as well.
$inUseAlbums = Song::select('album_id')->groupBy('album_id')->get()->lists('album_id');
$inUseAlbums[] = Album::UNKNOWN_ID;
Album::whereNotIn('id', $inUseAlbums)->delete();
$inUseArtists = Album::select('artist_id')->groupBy('artist_id')->get()->lists('artist_id');
$inUseArtists[] = Artist::UNKNOWN_ID;
Artist::whereNotIn('id', $inUseArtists)->delete();
}
示例5: handle
public function handle()
{
$dirs = iterator_to_array(Finder::create()->in($this->repo->releasePath())->depth(0)->sortByChangedTime());
foreach (array_slice(array_reverse($dirs), 3) as $dir) {
$this->fs()->deleteDirectory($dir);
}
}
示例6: execute
/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException When the target directory does not exist or symlink cannot be used
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$targetArg = rtrim($input->getArgument('target'), '/');
if (!is_dir($targetArg)) {
throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
}
if (!function_exists('symlink') && $input->getOption('symlink')) {
throw new \InvalidArgumentException('The symlink() function is not available on your system. You need to install the assets without the --symlink option.');
}
$filesystem = $this->getContainer()->get('filesystem');
// Create the bundles directory otherwise symlink will fail.
$bundlesDir = $targetArg . '/bundles/';
$filesystem->mkdir($bundlesDir, 0777);
$output->writeln(sprintf('Installing assets using the <comment>%s</comment> option', $input->getOption('symlink') ? 'symlink' : 'hard copy'));
foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) {
if (is_dir($originDir = $bundle->getPath() . '/Resources/public')) {
$targetDir = $bundlesDir . preg_replace('/bundle$/', '', strtolower($bundle->getName()));
$output->writeln(sprintf('Installing assets for <comment>%s</comment> into <comment>%s</comment>', $bundle->getNamespace(), $targetDir));
$filesystem->remove($targetDir);
if ($input->getOption('symlink')) {
if ($input->getOption('relative')) {
$relativeOriginDir = $filesystem->makePathRelative($originDir, realpath($bundlesDir));
} else {
$relativeOriginDir = $originDir;
}
$filesystem->symlink($relativeOriginDir, $targetDir);
} else {
$filesystem->mkdir($targetDir, 0777);
// We use a custom iterator to ignore VCS files
$filesystem->mirror($originDir, $targetDir, Finder::create()->ignoreDotFiles(false)->in($originDir));
}
}
}
}
示例7: testCopyDir
public function testCopyDir()
{
$source = static::$cwd . '/tests/fixtures/filesystem';
Filesystem::create()->mkdir($target = getcwd());
Filesystem::create()->copyDir($source, $target, Finder::create());
$this->assertFileExists($target . '/foo/test.txt');
}
示例8: execute
/**
* @return void
*/
public function execute()
{
try {
$installationFolder = $this->config->getString('installationFolder');
$varFolder = $installationFolder . '/var';
if (!is_dir($varFolder)) {
@mkdir($varFolder);
}
@chmod($varFolder, 0777);
$varCacheFolder = $installationFolder . '/var/cache';
if (!is_dir($varCacheFolder)) {
@mkdir($varCacheFolder);
}
@chmod($varCacheFolder, 0777);
$mediaFolder = $installationFolder . '/pub/media';
if (!is_dir($mediaFolder)) {
@mkdir($mediaFolder);
}
@chmod($mediaFolder, 0777);
$finder = Finder::create();
$finder->directories()->ignoreUnreadableDirs(true)->in(array($varFolder, $mediaFolder));
foreach ($finder as $dir) {
@chmod($dir->getRealpath(), 0777);
}
} catch (\Exception $e) {
$this->output->writeln('<error>' . $e->getMessage() . '</error>');
}
}
示例9: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$info = $this->container->info()->get();
$path = $this->container->path();
$vers = $info['version'];
$filter = '/' . implode('|', $this->excludes) . '/i';
$this->line(sprintf('Starting: webpack'));
exec('webpack -p');
$finder = Finder::create()->files()->in($path)->ignoreVCS(true)->filter(function ($file) use($filter) {
return !preg_match($filter, $file->getRelativePathname());
});
$zip = new \ZipArchive();
if (!$zip->open($zipFile = "{$path}/pagekit-" . $vers . ".zip", \ZipArchive::OVERWRITE)) {
$this->abort("Can't open ZIP extension in '{$zipFile}'");
}
foreach ($finder as $file) {
$zip->addFile($file->getPathname(), $file->getRelativePathname());
}
$zip->addFile("{$path}/.bowerrc", '.bowerrc');
$zip->addFile("{$path}/.htaccess", '.htaccess');
$zip->addEmptyDir('tmp/');
$zip->addEmptyDir('tmp/cache');
$zip->addEmptyDir('tmp/temp');
$zip->addEmptyDir('tmp/logs');
$zip->addEmptyDir('tmp/sessions');
$zip->addEmptyDir('tmp/packages');
$zip->addEmptyDir('app/database');
$zip->close();
$name = basename($zipFile);
$size = filesize($zipFile) / 1024 / 1024;
$this->line(sprintf('Building: %s (%.2f MB)', $name, $size));
}
示例10: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$twig = $this->getContainer()->get('twig');
$template = null;
$filename = $input->getArgument('filename');
if (!$filename) {
if (0 !== ftell(STDIN)) {
throw new \RuntimeException("Please provide a filename or pipe template content to stdin.");
}
while (!feof(STDIN)) {
$template .= fread(STDIN, 1024);
}
return $twig->parse($twig->tokenize($template));
}
if (0 !== strpos($filename, '@') && !is_readable($filename)) {
throw new \RuntimeException("File or directory '%s' is not readable");
}
$files = array();
if (is_file($filename)) {
$files = array($filename);
} elseif (is_dir($filename)) {
$files = Finder::create()->files()->in($filename)->name('*.twig');
} else {
$dir = $this->getApplication()->getKernel()->locateResource($filename);
$files = Finder::create()->files()->in($dir)->name('*.twig');
}
foreach ($files as $file) {
$twig->parse($twig->tokenize(file_get_contents($file), (string) $file));
}
$output->writeln('<info>No syntax error detected.</info>');
}
示例11: load
public function load(ObjectManager $manager)
{
$gallery = $this->getGalleryManager()->create();
$manager = $this->getMediaManager();
$faker = $this->getFaker();
$files = Finder::create()->name('*.jpeg')->in(__DIR__ . '/../data/files');
$i = 0;
foreach ($files as $pos => $file) {
$media = $manager->create();
$media->setBinaryContent($file);
$media->setEnabled(true);
$media->setDescription($faker->sentence(15));
$this->addReference('sonata-media-' . $i++, $media);
$manager->save($media, 'default', 'sonata.media.provider.image');
$this->addMedia($gallery, $media);
}
$videos = array('ythUVU31Y18' => 'sonata.media.provider.youtube');
foreach ($videos as $video => $provider) {
$media = $manager->create();
$media->setBinaryContent($video);
$media->setEnabled(true);
$manager->save($media, 'default', $provider);
$this->addMedia($gallery, $media);
}
$gallery->setEnabled(true);
$gallery->setName($faker->sentence(4));
$gallery->setDefaultFormat('small');
$gallery->setContext('default');
$this->getGalleryManager()->update($gallery);
$this->addReference('media-gallery', $gallery);
}
示例12: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$foundLinkTarget = '';
$targetFolder = $input->getArgument('target-folder');
if (!is_dir($targetFolder)) {
throw new \LogicException('Folder ' . $targetFolder . ' does not exist.');
}
$finder = Finder::create()->directories()->name('PhpStorm')->depth(0)->in($targetFolder);
foreach ($finder as $dir) {
/* @var $dir \Symfony\Component\Finder\SplFileInfo */
$foundLinkTarget = $dir->getLinkTarget();
$output->writeln('<info>Found Symlink to current version </info><comment>' . $foundLinkTarget . '</comment>');
break;
}
if (empty($foundLinkTarget)) {
$output->writeln('<info>Please run download before any clean operation</info>');
return 1;
}
$finder = Finder::create()->directories()->name('PhpStorm-*')->notName($foundLinkTarget)->in($targetFolder)->depth(0);
$filesystem = new Filesystem();
foreach ($finder as $dir) {
$output->writeln('<info>Remove directory</info> <comment>' . $dir->getRelativePathname() . '</comment>');
$filesystem->remove(array($dir));
}
}
示例13: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$dirs = $this->findTranslationsDirs($container);
if (empty($dirs)) {
return;
}
$translator = $container->findDefinition('translator.default');
// Register translation resources
foreach ($dirs as $dir) {
$container->addResource(new DirectoryResource($dir));
}
$files = [];
$finder = Finder::create()->files()->filter(function (SplFileInfo $file) {
return 2 === substr_count($file->getBasename(), '.') && preg_match('/\\.\\w+$/', $file->getBasename());
})->in($dirs);
/** @var SplFileInfo $file */
foreach ($finder as $file) {
$locale = explode('.', $file->getBasename(), 3)[1];
if (!isset($files[$locale])) {
$files[$locale] = [];
}
$files[$locale][] = (string) $file;
}
$options = array_merge_recursive($translator->getArgument(3), ['resource_files' => $files]);
$translator->replaceArgument(3, $options);
}
示例14: setAppDirectoryNamespace
/**
* Set the namespace on the files in the app directory.
*
* @return void
*/
protected function setAppDirectoryNamespace()
{
$files = Finder::create()->in($this->laravel['path'])->name('*.php');
foreach ($files as $file) {
$this->replaceNamespace($file->getRealPath());
}
}
示例15: registerBuiltInConfigs
public function registerBuiltInConfigs()
{
foreach (Finder::create()->files()->in(__DIR__ . '/Config') as $file) {
$class = 'Symfony\\CS\\Config\\' . basename($file, '.php');
$this->addConfig(new $class());
}
}