当前位置: 首页>>代码示例>>PHP>>正文


PHP Filesystem::exists方法代码示例

本文整理汇总了PHP中Symfony\Component\Filesystem\Filesystem::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::exists方法的具体用法?PHP Filesystem::exists怎么用?PHP Filesystem::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Filesystem\Filesystem的用法示例。


在下文中一共展示了Filesystem::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: rand

 public function test exists asserts every file exists()
 {
     $dummySuccess = rand(0, 1) === 1;
     $this->mockFilesystem->exists([$this->dummyStoragePath . '/public.pem', $this->dummyStoragePath . '/private.pem'])->willReturn($dummySuccess);
     $result = $this->service->exists();
     $this->assertSame($dummySuccess, $result);
 }
开发者ID:acmephp,项目名称:symfony-bundle,代码行数:7,代码来源:KeyPairStorageTest.php

示例2: createRequiredFiles

 public static function createRequiredFiles(Event $event)
 {
     $fs = new Filesystem();
     $root = static::getDrupalRoot(getcwd());
     $dirs = ['modules', 'profiles', 'themes'];
     // Required for unit testing
     foreach ($dirs as $dir) {
         if (!$fs->exists($root . '/' . $dir)) {
             $fs->mkdir($root . '/' . $dir);
             $fs->touch($root . '/' . $dir . '/.gitkeep');
         }
     }
     // Prepare the settings file for installation
     if (!$fs->exists($root . '/sites/default/settings.php')) {
         $fs->copy($root . '/sites/default/default.settings.php', $root . '/sites/default/settings.php');
         $fs->chmod($root . '/sites/default/settings.php', 0666);
         $event->getIO()->write("Create a sites/default/settings.php file with chmod 0666");
     }
     // Prepare the services file for installation
     if (!$fs->exists($root . '/sites/default/services.yml')) {
         $fs->copy($root . '/sites/default/default.services.yml', $root . '/sites/default/services.yml');
         $fs->chmod($root . '/sites/default/services.yml', 0666);
         $event->getIO()->write("Create a sites/default/services.yml file with chmod 0666");
     }
     // Create the files directory with chmod 0777
     if (!$fs->exists($root . '/sites/default/files')) {
         $oldmask = umask(0);
         $fs->mkdir($root . '/sites/default/files', 0777);
         umask($oldmask);
         $event->getIO()->write("Create a sites/default/files directory with chmod 0777");
     }
 }
开发者ID:openrestaurant,项目名称:openrestaurant-project,代码行数:32,代码来源:ScriptHandler.php

示例3: testDirectoryEmpty

 public function testDirectoryEmpty()
 {
     $this->assertFalse($this->fs->exists($this->directory));
     $result = $this->runCommand('oro:cron:import-tracking', ['--directory' => $this->directory]);
     $this->assertTrue($this->fs->exists($this->directory));
     $this->assertContains('Logs not found', $result);
 }
开发者ID:northdakota,项目名称:platform,代码行数:7,代码来源:ImportLogsCommandTest.php

示例4: launch

 /**
  * {@inheritdoc}
  */
 public function launch(Payload $payload, Iteration $iteration, Config $config)
 {
     $name = XDebugUtil::filenameFromIteration($iteration);
     $dir = $config['output_dir'];
     $phpConfig = ['xdebug.trace_output_name' => $name, 'xdebug.trace_output_dir' => $dir, 'xdebug.trace_format' => '1', 'xdebug.auto_trace' => '1', 'xdebug.coverage_enable' => '0', 'xdebug.collect_params' => '3'];
     $payload->setPhpConfig($phpConfig);
     $path = $dir . DIRECTORY_SEPARATOR . $name . '.xt';
     // if the file exists, remove it. XDebug might not be installed
     // on the PHP binary and the file may not be generated. We should
     // fail in such a case and not use the file from a previous run.
     if ($this->filesystem->exists($path)) {
         $this->filesystem->remove($path);
     }
     $result = $payload->launch();
     if (false === $this->filesystem->exists($path)) {
         throw new \RuntimeException(sprintf('Trace file at "%s" was not generated.', $path));
     }
     $dom = $this->converter->convert($path);
     $subject = $iteration->getVariant()->getSubject();
     $class = $subject->getBenchmark()->getClass();
     // remove leading slash from class name for matching
     // the class in the trace.
     if (substr($class, 0, 1) == '\\') {
         $class = substr($class, 1);
     }
     // extract only the timings for the benchmark class, ignore the bootstrapping
     $selector = '//entry[@function="' . $class . '->' . $subject->getName() . '"]';
     // calculate stats from the trace
     $time = (int) ($dom->evaluate(sprintf('number(%s/@end-time) - number(%s/@start-time)', $selector, $selector)) * 1000000.0);
     $memory = (int) $dom->evaluate(sprintf('number(%s/@end-memory) - number(%s/@start-memory)', $selector, $selector));
     $funcCalls = (int) $dom->evaluate('count(' . $selector . '//*)');
     $iteration->setResult(new TimeResult($result['time']));
     $iteration->setResult(MemoryResult::fromArray($result['mem']));
     $iteration->setResult(new XDebugTraceResult($time, $memory, $funcCalls, $dom));
 }
开发者ID:dantleech,项目名称:phpbench,代码行数:38,代码来源:TraceExecutor.php

示例5: dumpMocksTo

 /**
  * Copy all existing mocks onto a target directory.
  *
  * @param string $targetDir
  */
 public function dumpMocksTo($targetDir)
 {
     if (!$this->filesystem->exists($this->mocksDir)) {
         return;
     }
     $this->filesystem->mirror($this->mocksDir, $targetDir, null, ['override' => true, 'delete' => true]);
 }
开发者ID:mRoca,项目名称:MrocaRequestLogBundle,代码行数:12,代码来源:ResponseLogger.php

示例6: createTerra

 /**
  * Creates a Terra instance.
  *
  * @return Terra
  *               A configured Flo instance.
  */
 private function createTerra()
 {
     $terra = new Terra();
     // Get config from env variables or files.
     if ($config_env = getenv('TERRA')) {
         $config_env = Yaml::parse($config_env);
         $config = new Config($config_env);
     } else {
         $fs = new Filesystem();
         $user_config = array();
         $user_config_file = getenv('HOME') . '/.terra/terra';
         if ($fs->exists($user_config_file)) {
             $user_config = Yaml::parse($user_config_file);
         }
         $project_config = array();
         $process = new Process('git rev-parse --show-toplevel');
         $process->run();
         if ($process->isSuccessful()) {
             $project_config_file = trim($process->getOutput()) . '/terra.yml';
             if ($fs->exists($project_config_file)) {
                 $project_config = Yaml::parse($project_config_file);
             }
         }
         $config = new Config($user_config, $project_config);
     }
     $terra->setConfig($config);
     return $terra;
 }
开发者ID:nateswart,项目名称:terra-cli,代码行数:34,代码来源:Factory.php

示例7: generateBehatTests

 /**
  * @param Bundle          $bundle
  * @param OutputInterface $output
  * @param array           $parameters
  */
 public function generateBehatTests(Bundle $bundle, OutputInterface $output, array $parameters)
 {
     $dirPath = sprintf("%s/Features", $bundle->getPath());
     $skeletonDir = sprintf("%s/Features", $this->fullSkeletonDir);
     // First copy all the content
     $this->filesystem->mirror($this->fullSkeletonDir, $bundle->getPath());
     // Now render the Context files to replace the namespace etc.
     if ($handle = opendir($skeletonDir . "/Context")) {
         while (false !== ($entry = readdir($handle))) {
             // Check to make sure we skip hidden folders
             // And we render the files ending in .php
             if (substr($entry, 0, 1) != '.' && substr($entry, -strlen(".php")) === ".php") {
                 $this->renderFile("/Features/Context/" . $entry, $dirPath . "/Context/" . $entry, $parameters);
             }
         }
         closedir($handle);
     }
     $featureContext = $dirPath . "/Context/FeatureContext.php";
     if ($this->filesystem->exists($featureContext)) {
         $contents = file_get_contents($featureContext);
         $contents = str_replace('-adminpwd-', $this->container->getParameter('kunstmaan_admin.admin_password'), $contents);
         file_put_contents($featureContext, $contents);
     }
     $output->writeln('Generating Behat Tests : <info>OK</info>');
 }
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:30,代码来源:AdminTestsGenerator.php

示例8: generate

 /**
  * @param $path
  * @throws \Exception
  */
 public function generate($path)
 {
     if ($this->filesystem->exists($path)) {
         throw new \Exception("Error module already exists");
     }
     $this->filesystem->mkdir($path, 0700);
 }
开发者ID:sergeycherepanov,项目名称:m2gen,代码行数:11,代码来源:Module.php

示例9: normalize

 /**
  * Normalize a source (string or SplInfo) into an instance of SplInfo.
  *
  * @param mixed $source
  * @return SplFileInfo
  * @throws Exception
  */
 public function normalize($source)
 {
     $fileSystem = new Filesystem();
     // if the source is a file info, it must exists and be readable
     if ($source instanceof SplFileInfo) {
         if (!$fileSystem->exists($source->getRealPath())) {
             throw new Exception('Unable to find ' . $source . ' during normalization process');
         }
         // the source is already normalized
         return $source;
     }
     // if the source is not an instance of SplInfo, it should be a string
     if (!is_string($source)) {
         throw new Exception('The source should be a string if it is not an instance of SplInfo (instead of ' . gettype($source) . ')');
     }
     $path = $source;
     // if the file does not exists, try to add the application path before
     if (!$fileSystem->exists($source)) {
         if (!$fileSystem->exists($this->applicationPath . '/' . $source)) {
             throw new Exception('File ' . $source . ' not found, searched in ' . implode(', ', [$source, $this->applicationPath . '/' . $source]));
         }
         $path = $this->applicationPath . '/' . $source;
     }
     // normalize source using SplInfo
     $source = new SplFileInfo($path);
     return $source;
 }
开发者ID:johnkrovitch,项目名称:sam,代码行数:34,代码来源:Normalizer.php

示例10: execute

 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $gitHooksPath = $this->paths()->getGitHooksDir();
     $resourceHooksPath = $this->paths()->getGitHookTemplatesDir() . $this->grumPHP->getHooksPreset();
     $resourceHooksPath = $this->paths()->getPathWithTrailingSlash($resourceHooksPath);
     $customHooksPath = $this->paths()->getPathWithTrailingSlash($this->grumPHP->getHooksDir());
     // Some git clients to not automatically create a git hooks folder.
     if (!$this->filesystem->exists($gitHooksPath)) {
         $this->filesystem->mkdir($gitHooksPath);
         $output->writeln(sprintf('<fg=yellow>Created git hooks folder at: %s</fg=yellow>', $gitHooksPath));
     }
     foreach (self::$hooks as $hook) {
         $gitHook = $gitHooksPath . $hook;
         $hookTemplate = $resourceHooksPath . $hook;
         if ($customHooksPath && $this->filesystem->exists($customHooksPath . $hook)) {
             $hookTemplate = $customHooksPath . $hook;
         }
         if (!$this->filesystem->exists($hookTemplate)) {
             throw new \RuntimeException(sprintf('Could not find hook template for %s at %s.', $hook, $hookTemplate));
         }
         $content = $this->parseHookBody($hook, $hookTemplate);
         file_put_contents($gitHook, $content);
         $this->filesystem->chmod($gitHook, 0775);
     }
     $output->writeln('<fg=yellow>Watch out! GrumPHP is sniffing your commits!<fg=yellow>');
 }
开发者ID:Big-Shark,项目名称:grumphp,代码行数:33,代码来源:InitCommand.php

示例11: getIdentifier

 /**
  * @return string The string which identifies a given segment of the execution environment
  */
 public function getIdentifier()
 {
     if (!$this->filesystem->exists($this->containerIdPath)) {
         return '';
     }
     return file_get_contents($this->containerIdPath);
 }
开发者ID:notxt,项目名称:php-execution-environment-metadata,代码行数:10,代码来源:DockerContainer.php

示例12: testPersistenceAndRemoval

 /**
  * Test if entity persistence and removal is handled correctly.
  * Tests also that associated physical file exists/is removed.
  */
 public function testPersistenceAndRemoval()
 {
     $container = static::$kernel->getContainer();
     $filesystem = new Filesystem();
     $repoFile = $this->em->getRepository('ReskumeFileBundle:File');
     $fileFactory = new FileFactory();
     $file = $fileFactory->create();
     // test only one entry in database table
     $this->em->persist($file);
     $this->em->flush();
     $result = $repoFile->findAll();
     $this->assertCount(1, $result);
     // @important clear em and refetch entity to suppress foreign key mapping errors
     $this->em->clear();
     $result = $repoFile->findAll();
     $result = $result[0];
     // check that associated file exists
     $fileStorageConfig = $container->get('reskume_file.configuration.file_storage_configuration');
     $filePath = sprintf('%s%s', $fileStorageConfig->getFileDir(), $result->getKey());
     $this->assertTrue($filesystem->exists($filePath));
     // test correct removal
     $this->em->remove($result);
     $this->em->flush();
     $result = $repoFile->findAll();
     $this->assertEmpty($result);
     // test that associated file is deleted from filesystem
     $this->assertFalse($filesystem->exists($filePath));
 }
开发者ID:reskume,项目名称:file-bundle,代码行数:32,代码来源:FilePersistenceTest.php

示例13: extract

 /**
  * @param string $source
  * @param string $locale
  *
  * @return MessageCatalogueInterface | null
  */
 public function extract($source, $locale)
 {
     if (!$this->isSourceAvailable($source)) {
         return;
     }
     $fs = new Filesystem();
     /* @var Bundle $foundBundle */
     $foundBundle = $this->kernel->getBundle($this->bundle);
     // load any messages from templates
     $extractedCatalogue = new MessageCatalogue($locale);
     $resourcesDir = $this->resolveResourcesDirectory($foundBundle);
     if ($fs->exists($resourcesDir)) {
         $this->extractor->extract($resourcesDir, $extractedCatalogue);
     }
     // load any existing messages from the translation files
     $translationsDir = $foundBundle->getPath() . '/Resources/translations';
     if ($fs->exists($translationsDir)) {
         $currentCatalogue = new MessageCatalogue($locale);
         $this->loader->loadMessages($translationsDir, $currentCatalogue);
         foreach ($extractedCatalogue->getDomains() as $domain) {
             $messages = $currentCatalogue->all($domain);
             if (count($messages)) {
                 $extractedCatalogue->add($messages, $domain);
             }
         }
     }
     return $extractedCatalogue;
 }
开发者ID:modera,项目名称:foundation,代码行数:34,代码来源:TemplateTranslationHandler.php

示例14: guardFileExists

 /**
  * @param FileInterface $file
  */
 protected function guardFileExists(FileInterface $file)
 {
     $location = $file->getPath();
     if (!$this->filesystem->exists($location)) {
         throw new \RuntimeException('File does not exist: ' . $location);
     }
 }
开发者ID:phpro,项目名称:zf-filesystem,代码行数:10,代码来源:AbstractMetadata.php

示例15: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $pathToIlios2 = $input->getArgument('pathToIlios2');
     if (!$this->symfonyFileSystem->exists($pathToIlios2)) {
         throw new \Exception("'{$pathToIlios2}' does not exist.");
     }
     $learningMaterials = $this->learningMaterialManager->findFileLearningMaterials();
     $helper = $this->getHelper('question');
     $output->writeln('');
     $question = new ConfirmationQuestion('<question>Ready to copy ' . count($learningMaterials) . ' learning materials. Shall we continue? </question>' . "\n", true);
     if ($helper->ask($input, $output, $question)) {
         $migrated = 0;
         foreach ($learningMaterials as $lm) {
             $fullPath = $pathToIlios2 . $lm->getRelativePath();
             if (!$this->symfonyFileSystem->exists($fullPath)) {
                 throw new \Exception('Unable to migrated learning material #' . $lm->getId() . ".  No file found at '{$fullPath}'.");
             }
             $file = $this->iliosFileSystem->getSymfonyFileForPath($fullPath);
             $newPath = $this->iliosFileSystem->storeLearningMaterialFile($file);
             $lm->setRelativePath($newPath);
             $this->learningMaterialManager->updateLearningMaterial($lm, false);
             $migrated++;
             if ($migrated % 500) {
                 $this->learningMaterialManager->flushAndClear();
             }
         }
         $this->learningMaterialManager->flushAndClear();
         $output->writeln("<info>Migrated {$migrated} learning materials successfully!</info>");
     } else {
         $output->writeln('<comment>Migration canceled.</comment>');
     }
 }
开发者ID:Okami-,项目名称:ilios,代码行数:35,代码来源:MigrateIlios2LearningMaterialsCommand.php


注:本文中的Symfony\Component\Filesystem\Filesystem::exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。