php Symfony-Component-Filesystem-Filesystem类(方法)实例源码

下面列出了php Symfony-Component-Filesystem-Filesystem 类(方法)源码代码实例,从而了解它的用法。

作者:ls    项目:OneupUploaderBundl   
public function cleanup($path)
 {
     // cleanup
     $filesystem = new Filesystem();
     $filesystem->remove($path);
     return true;
 }

作者:ilosad    项目:chamilo-lms-icpn   
/**
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param array $files
  * @param $permission
  * @return int
  */
 public function createFolders(\Symfony\Component\Console\Output\OutputInterface $output, $files, $permission)
 {
     $dryRun = $this->getConfigurationHelper()->getDryRun();
     if (empty($files)) {
         $output->writeln('<comment>No files found.</comment>');
         return 0;
     }
     $fs = new Filesystem();
     try {
         if ($dryRun) {
             $output->writeln("<comment>Folders to be created with permission " . decoct($permission) . ":</comment>");
             foreach ($files as $file) {
                 $output->writeln($file);
             }
         } else {
             $output->writeln("<comment>Creating folders with permission " . decoct($permission) . ":</comment>");
             foreach ($files as $file) {
                 $output->writeln($file);
             }
             $fs->mkdir($files, $permission);
         }
     } catch (IOException $e) {
         echo "\n An error occurred while removing the directory: " . $e->getMessage() . "\n ";
     }
 }

作者:umpirsk    项目:pim-community-de   
/**
  * Remove the extracted directory
  */
 public function __destruct()
 {
     if ($this->extractedPath) {
         $fileSystem = new Filesystem();
         $fileSystem->remove($this->extractedPath);
     }
 }

作者:jumbojet    项目:php-formatte   
/**
  * Execute command
  *
  * @param InputInterface  $input  Input
  * @param OutputInterface $output Output
  *
  * @return int|null|void
  *
  * @throws Exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path = $input->getArgument('path');
     /**
      * We load the options to work with
      */
     $options = $this->getUsableConfig($input);
     /**
      * Building the real directory or file to work in
      */
     $filesystem = new Filesystem();
     if (!$filesystem->isAbsolutePath($path)) {
         $path = getcwd() . DIRECTORY_SEPARATOR . $path;
     }
     if (!is_file($path) && !is_dir($path)) {
         throw new Exception('Directory or file "' . $path . '" does not exist');
     }
     /**
      * Print dry-run message if needed
      */
     $this->printDryRunMessage($input, $output, $path);
     /**
      * Print all configuration block if verbose level allows it
      */
     $this->printConfigUsed($output, $options);
     $fileFinder = new FileFinder();
     $files = $fileFinder->findPHPFilesByPath($path);
     /**
      * Parse and fix all found files
      */
     $this->parseAndFixFiles($input, $output, $files, $options);
 }

作者:hyperlato    项目:Sism   
public function tearDown()
 {
     parent::tearDown();
     $this->app['storage']->close();
     $fs = new Filesystem();
     $fs->remove($this->baseDir);
 }

作者:adrianoaguia    项目:symfony-container-generato   
function it_uses_container_dump_to_create_the_cache(Filesystem $filesystem, ContainerDumperFactory $dumperFactory, ContainerBuilder $containerBuilder, PhpDumper $dumper)
 {
     $dumper->dump()->willReturn('file contents');
     $dumperFactory->create($containerBuilder)->willReturn($dumper);
     $this->dump($containerBuilder);
     $filesystem->dumpFile($this->path, 'file contents')->shouldHaveBeenCalled();
 }

作者:csanque    项目:fakery-generato   
protected function setUp()
 {
     $fs = new Filesystem();
     if ($fs->exists(self::$cacheDir)) {
         $fs->remove(self::$cacheDir);
     }
 }

作者:kachkae    项目:php-backu   
/**
  * @param Profile $profile
  * @param bool    $clear
  *
  * @return Backup[]
  *
  * @throws \Exception
  */
 public function backup(Profile $profile, $clear = false)
 {
     $scratchDir = $profile->getScratchDir();
     $processor = $profile->getProcessor();
     $filesystem = new Filesystem();
     if ($clear) {
         $this->logger->info('Clearing scratch directory...');
         $filesystem->remove($scratchDir);
     }
     if (!is_dir($scratchDir)) {
         $filesystem->mkdir($scratchDir);
     }
     $this->logger->info('Beginning backup...');
     foreach ($profile->getSources() as $source) {
         $source->fetch($scratchDir, $this->logger);
     }
     $filename = $processor->process($scratchDir, $profile->getNamer(), $this->logger);
     try {
         $backups = $this->sendToDestinations($profile, $filename);
     } catch (\Exception $e) {
         $processor->cleanup($filename, $this->logger);
         throw $e;
     }
     $processor->cleanup($filename, $this->logger);
     $this->logger->info('Done.');
     return $backups;
 }

作者:kohkimakimot    项目:alta   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getApplication()->getContainer();
     $commandFile = realpath($_SERVER['SCRIPT_FILENAME']);
     $currentVersion = "v" . $container->getVersion();
     $updateVersion = trim(@file_get_contents('https://raw.githubusercontent.com/kohkimakimoto/altax/master/version'));
     if (!$container->isPhar()) {
         $output->writeln('<error>You can not update altax. Because altax only supports self-update command on PHAR file version.</error>');
         return 1;
     }
     if (!preg_match('/^v[0-9].[0-9]+.[0-9]+$/', $updateVersion)) {
         $output->writeln('<error>You can not update altax. Because the latest version of altax are not available for download.</error>');
         return 1;
     }
     if ($currentVersion === $updateVersion) {
         $output->writeln('<info>You are already using altax version <comment>' . $updateVersion . '</comment>.</info>');
         return 0;
     }
     $output->writeln(sprintf("Updating to version <info>%s</info>.", $updateVersion));
     $tmpDir = "/tmp/" . uniqid("altax.update.");
     $process = new Process("mkdir {$tmpDir} && cd {$tmpDir} && curl -L https://raw.githubusercontent.com/kohkimakimoto/altax/master/installer.sh | bash -s local {$updateVersion}");
     $process->setTimeout(null);
     if ($process->run() !== 0) {
         $output->writeln('<error>You can not update altax.');
         return 1;
     }
     $fs = new Filesystem();
     $fs->copy($tmpDir . "/altax.phar", $commandFile, true);
     $fs->remove($tmpDir);
     $output->writeln("Done.");
 }

作者:ivob    项目:superleansilexplat   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $finder = Finder::create()->in($this->cachePath)->notName('.gitkeep');
     $filesystem = new Filesystem();
     $filesystem->remove($finder);
     $output->writeln(sprintf("%s <info>success</info>", 'cache:clear'));
 }

作者:kebool    项目:input-mappin   
public function tearDown()
 {
     // Delete local files
     $finder = new Finder();
     $fs = new Filesystem();
     $fs->remove($finder->files()->in($this->tmpDir . "/download"));
     $fs->remove($finder->files()->in($this->tmpDir));
     $fs->remove($this->tmpDir . "/download");
     $fs->remove($this->tmpDir);
     // Delete file uploads
     $options = new ListFilesOptions();
     $options->setTags(["docker-bundle-test"]);
     $files = $this->client->listFiles($options);
     foreach ($files as $file) {
         $this->client->deleteFile($file["id"]);
     }
     if ($this->client->bucketExists("in.c-docker-test")) {
         // Delete tables
         foreach ($this->client->listTables("in.c-docker-test") as $table) {
             $this->client->dropTable($table["id"]);
         }
         // Delete bucket
         $this->client->dropBucket("in.c-docker-test");
     }
     if ($this->client->bucketExists("in.c-docker-test-redshift")) {
         // Delete tables
         foreach ($this->client->listTables("in.c-docker-test-redshift") as $table) {
             $this->client->dropTable($table["id"]);
         }
         // Delete bucket
         $this->client->dropBucket("in.c-docker-test-redshift");
     }
 }

作者:campaignchai    项目:updat   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->io = new SymfonyStyle($input, $output);
     $locator = $this->getContainer()->get('campaignchain.core.module.locator');
     $bundles = $locator->getAvailableBundles();
     $selectedBundle = $this->selectBundle($bundles);
     $generateOutput = new BufferedOutput();
     $application = new Application($this->getContainer()->get('kernel'));
     $application->setAutoExit(false);
     $application->run(new ArrayInput(['command' => $this->getDoctrineMigrationsCommand(), '--no-interaction' => true]), $generateOutput);
     preg_match('/Generated new migration class to "(.*)"/', $generateOutput->fetch(), $matches);
     if (count($matches) < 2) {
         //error
         return;
     }
     $pathForMigrationFile = $matches[1];
     preg_match('/Version.*.php/', $pathForMigrationFile, $fileNames);
     if (!count($fileNames)) {
         return;
     }
     $schemaFile = $this->getContainer()->getParameter('kernel.root_dir') . DIRECTORY_SEPARATOR . '..';
     $schemaFile .= DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $selectedBundle->getName();
     $schemaFile .= str_replace('/', DIRECTORY_SEPARATOR, $this->getContainer()->getParameter('campaignchain_update.bundle.schema_dir'));
     $schemaFile .= DIRECTORY_SEPARATOR . $fileNames[0];
     $fs = new Filesystem();
     $fs->copy($pathForMigrationFile, $schemaFile);
     $fs->remove($pathForMigrationFile);
     $this->io->success('Generation finished. You can find the file here:');
     $this->io->text($schemaFile);
 }

作者:amira2    项目:DrupalConsol   
/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configName = $input->getArgument('config-name');
     $editor = $input->getArgument('editor');
     $config = $this->getConfigFactory()->getEditable($configName);
     $configSystem = $this->getConfigFactory()->get('system.file');
     $temporalyDirectory = $configSystem->get('path.temporary') ?: '/tmp';
     $configFile = $temporalyDirectory . '/config-edit/' . $configName . '.yml';
     $ymlFile = new Parser();
     $fileSystem = new Filesystem();
     try {
         $fileSystem->mkdir($temporalyDirectory);
         $fileSystem->dumpFile($configFile, $this->getYamlConfig($configName));
     } catch (IOExceptionInterface $e) {
         throw new \Exception($this->trans('commands.config.edit.messages.no-directory') . ' ' . $e->getPath());
     }
     if (!$editor) {
         $editor = $this->getEditor();
     }
     $processBuilder = new ProcessBuilder(array($editor, $configFile));
     $process = $processBuilder->getProcess();
     $process->setTty('true');
     $process->run();
     if ($process->isSuccessful()) {
         $value = $ymlFile->parse(file_get_contents($configFile));
         $config->setData($value);
         $config->save();
         $fileSystem->remove($configFile);
     }
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
 }

作者:GerDne    项目:luck-docke   
/**
  * @param $offset
  *
  * @return FinishResult|ValidResult
  * @throws \RuntimeException
  * @throws \Exception
  */
 public function run($offset)
 {
     $fs = new Filesystem();
     $requestTime = time();
     try {
         $source = new Zip($this->source);
         $count = $source->count();
         $source->seek($offset);
     } catch (\Exception $e) {
         @unlink($this->source);
         throw new \Exception('Could not open update package:<br>' . $e->getMessage(), 0, $e);
     }
     /** @var ZipEntry $entry */
     while (list($position, $entry) = $source->each()) {
         $name = $entry->getName();
         $targetName = $this->destinationDir . $name;
         if (!$entry->isDir()) {
             $fs->dumpFile($targetName, $entry->getContents());
         }
         if (time() - $requestTime >= 20 || ($position + 1) % 1000 == 0) {
             $source->close();
             return new ValidResult($position + 1, $count);
         }
     }
     $source->close();
     return new FinishResult($count, $count);
 }

作者:badr    项目:terra-ap   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Ask for an app and environment.
     $this->getApp($input, $output);
     $this->getEnvironment($input, $output);
     $environment_name = $this->environment->name;
     $app_name = $this->app->name;
     // Confirm removal of the app.
     $helper = $this->getHelper('question');
     $question = new ConfirmationQuestion("Are you sure you would like to remove the environment <question>{$app_name}:{$environment_name}</question>?  All files at {$this->environment->path} will be deleted, and all containers will be killed. [y/N] ", false);
     if (!$helper->ask($input, $output, $question)) {
         $output->writeln('<error>Cancelled</error>');
         return;
     } else {
         // Remove the environment from config registry.
         // @TODO: Move this to EnvironmentFactory class
         // Remove files
         $fs = new Filesystem();
         try {
             $fs->remove(array($this->environment->path));
             $output->writeln("<info>Files for environment {$app_name}:{$environment_name} has been deleted.</info>");
         } catch (IOExceptionInterface $e) {
             $output->writeln('<error>Unable to remove ' . $e->getPath() . '</error>');
         }
         // Destroy the environment
         $environmentFactory = new EnvironmentFactory($this->environment, $this->app);
         $environmentFactory->destroy();
         unset($this->app->environments[$environment_name]);
         $this->getApplication()->getTerra()->getConfig()->add('apps', $app_name, (array) $this->app);
         $this->getApplication()->getTerra()->getConfig()->save();
         $output->writeln("<info>Environment {$app_name}:{$environment_name} has been removed.</info>");
     }
 }

作者:Big-Shar    项目:grumph   
function it_should_locate_config_file_on_empty_composer_configuration(Filesystem $filesystem, PackageInterface $package)
 {
     $package->getExtra()->willReturn(array());
     $filesystem->exists($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);
     $filesystem->isAbsolutePath($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);
     $this->locate('/composer', $package)->shouldMatch($this->pathRegex('/composer/grumphp.yml'));
 }

作者:cyberspectru    项目:pharpile   
/**
  * {@inheritdoc}
  */
 public function tearDown()
 {
     if (isset($this->workDir)) {
         $filesystem = new Filesystem();
         $filesystem->remove($this->workDir);
     }
 }

作者:chaj    项目:RPiAS_serve   
/**
  * setData constructor.
  *
  * @param \Aura\Web\Request $request
  * @param \Aura\Web\Response $response
  * @param \Aura\View\View $view
  */
 public function __construct($request, $response, $view)
 {
     $status = 'success';
     $message = 'Image saved successfully.';
     $image = $request->files->get('file', ['error' => 1]);
     $secureToken = (new Config())->getConfig()['secure_token'];
     $retrievedSecureToken = $request->query->get('key', '');
     if ($secureToken !== $retrievedSecureToken) {
         $status = 'error';
         $message = 'Incorrect secure token';
     } else {
         if ($image['error'] === 0) {
             $fileSystem = new Filesystem();
             $tmpName = $image['tmp_name'];
             $path = '../storage/';
             try {
                 $fileSystem->copy($tmpName, $path . $image['name']);
             } catch (\Exception $e) {
                 Log::addError('Image upload error: ' . $e->getMessage());
                 $status = 'error';
                 $message = 'Move image exception: ' . $e->getMessage();
             }
         } else {
             Log::addError('Image upload error: ' . serialize($image));
             $status = 'error';
             $message = 'Image upload error';
         }
     }
     $view->setData(['status' => $status, 'message' => $message]);
     $response->content->set($view->__invoke());
 }

作者:cyrille    项目:extract-php-view.and.data.ap   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $identifier = $input->getArgument('identifier');
     if (!$identifier) {
         $identifier = '1799-Auobj';
     }
     $path = utils::normalize(__DIR__ . "/../data/{$identifier}.json");
     $content = file_get_contents($path);
     $data = json_decode($content);
     $localFile = utils::normalize(__DIR__ . "/../tmp/{$data->name}");
     $file = fopen($localFile, 'wb');
     $http = new \ADN\Extract\HttpRequest($data->uri, [], null, null);
     $response = $http->get(function ($code, $chunk) use($file, $data, $path) {
         if ($code != 'data') {
             return false;
         }
         fwrite($file, $chunk);
         $data->bytesRead += strlen($chunk);
         file_put_contents($path, json_encode($data));
         return true;
     });
     fclose($file);
     if (!$response || $response->code != Response::HTTP_OK) {
         $output->writeln('oops');
         $fs = new Filesystem();
         $fs->remove($path);
         $fs->remove($localFile);
         return;
     }
     $data->size = utils::findKey($response->headers, 'Content-Length');
     $data->bytesRead = $data->size;
     file_put_contents($path, json_encode($data));
     utils::log('ok');
 }

作者:mgdigita    项目:bootstrap-bundl   
/**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $destDir = $this->getDestDir();
     $finder = new Finder();
     $fs = new Filesystem();
     try {
         $fs->mkdir($destDir);
     } catch (IOException $e) {
         $output->writeln(sprintf('<error>Could not create directory %s.</error>', $destDir));
         return;
     }
     $srcDir = $this->getSrcDir();
     if (false === file_exists($srcDir)) {
         $output->writeln(sprintf('<error>Fonts directory "%s" does not exist. Did you install twbs/bootstrap? ' . 'If you used something other than Composer you need to manually change the path in ' . '"braincrafted_bootstrap.assets_dir". If you want to use Font Awesome you need to install the font and change the option "braincrafted_bootstrap.fontawesome_dir".</error>', $srcDir));
         return;
     }
     $finder->files()->in($srcDir);
     foreach ($finder as $file) {
         $dest = sprintf('%s/%s', $destDir, $file->getBaseName());
         try {
             $fs->copy($file, $dest);
         } catch (IOException $e) {
             $output->writeln(sprintf('<error>Could not copy %s</error>', $file->getBaseName()));
             return;
         }
     }
     $output->writeln(sprintf('Copied icon fonts to <comment>%s</comment>.', $destDir));
 }


问题


面经


文章

微信
公众号

扫码关注公众号