/**
  * @return bool
  */
 public function download()
 {
     if ($this->isDownloaded()) {
         return true;
     }
     $httpClient = new Client();
     $request = new Request('GET', $this->getUrl());
     $response = $httpClient->send($request, [RequestOptions::PROGRESS => function ($total, $current) {
         if ($total <= 0 || !$this->output) {
             return;
         }
         if (!$this->progressBar) {
             $this->progressBar = new ProgressBar($this->output, $total);
             $this->progressBar->setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return $this->formatSize($bar->getMaxSteps());
             });
             $this->progressBar->setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
             });
         }
         $this->progressBar->setProgress($current);
     }]);
     $this->filesystem->dumpFile($this->getDestinationFile(), $response->getBody()->getContents());
     $this->downloaded = true;
     return true;
 }
 /**
  * @Route("/new", name="wiki_create")
  * @Method("POST")
  */
 public function createAction(Request $request)
 {
     $name = $request->request->get('name');
     $user = $this->getUser();
     $slug = $request->request->get('slug');
     if (empty($slug)) {
         $slug = $this->get('slug')->slugify($name);
     }
     $repositoryService = $this->get('app.repository');
     $repository = $repositoryService->createRepository($slug);
     $adminRepository = $repositoryService->getRepository($this->getParameter('app.admin_repository'));
     $path = $repository->getWorkingDir();
     $fs = new Filesystem();
     $fs->dumpFile($path . '/index.md', '# ' . $name);
     $repository->setDescription($name);
     $repository->run('add', array('-A'));
     $repository->run('commit', array('-m Initial commit', '--author="' . $user->getName() . ' <' . $user->getEmail() . '>"'));
     $username = $user->getUsername();
     $adminPath = $adminRepository->getWorkingDir();
     $yamlDumper = new Dumper();
     $yamlString = $yamlDumper->dump(array('groups' => null, 'owners' => array($username), 'users' => array($username => 'RW+')), 3);
     $fs->dumpFile($adminPath . '/wikis/' . $slug . '.yml', $yamlString);
     $adminMessage = sprintf('Added wiki %s', $slug);
     $adminRepository->run('add', array('-A'));
     $adminRepository->run('commit', array('-m ' . $adminMessage, '--author="' . $user->getName() . ' <' . $user->getEmail() . '>"'));
     return $this->redirectToRoute('page_show', array('slug' => $slug));
 }
 public function create(FileResource $fileResource)
 {
     $fileName = $fileResource->getFileName();
     $content = $this->codeGenerator->getOutput($fileResource->getClassSource());
     $this->filesystem->dumpFile($fileName, $content);
     return true;
 }
Beispiel #4
0
 public function testMergeAbort()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     // branch:master
     $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
     $git->add('test.txt');
     $git->commit('master');
     // branch:develop
     $git->checkout->create('develop');
     $filesystem->dumpFile($this->directory . '/test.txt', 'bar');
     $git->add('test.txt');
     $git->commit('develop');
     // branch:master
     $git->checkout('master');
     $filesystem->dumpFile($this->directory . '/test.txt', 'baz');
     $git->add('test.txt');
     $git->commit('master');
     try {
         $git->merge('develop');
         $this->fail('$git->merge("develop") should fail');
     } catch (Exception $e) {
     }
     $git->merge->abort();
     $this->assertEquals('baz', file_get_contents($this->directory . '/test.txt'));
 }
Beispiel #5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $fs = new Filesystem();
     $directory = $input->getArgument('directory');
     $routes = $this->router->getRouteCollection()->all();
     $arrayRoutes = [];
     $arrayRoutesDev = [];
     foreach ($routes as $routeName => $routeObject) {
         $routeCompile = $routeObject->compile();
         if (strpos($routeName, "app_form_") === 0) {
             $emptyVars = [];
             $variables = $routeCompile->getVariables();
             foreach ($variables as $v) {
                 $emptyVars[$v] = '*' . $v . '*';
             }
             $url = $this->router->generate($routeName, $emptyVars, UrlGeneratorInterface::ABSOLUTE_PATH);
             //$urlProd = str_replace('', '', $url);
             $arrayRoute = ["url" => $url, "params" => $variables, "method" => $routeObject->getMethods()[0]];
             $arrayRoutes[$routeName] = $arrayRoute;
             $output->writeln($routeName . ' => ' . json_encode($arrayRoute));
             $arrayRoute['url'] = '/app_dev.php/' . $arrayRoute['url'];
             $arrayRoutesDev[$routeName] = $arrayRoute;
         }
     }
     $jsFile = "\n      var Router = (function () {\n          var Router = {};\n          Router.routes = %ROUTES%;\n          Router.generate = function (routeName, routeParams) {\n              if(typeof routeParams == 'undefined') routeParams = {};\n              var route = this.routes[routeName];\n              if (typeof route === 'undefined')\n                  return false;\n              var routeUrl = route.url;\n              var params = [];\n              for (var param in routeParams) {\n                  routeUrl = routeUrl.replace('*' + param + '*', routeParams[param]);\n              }\n              return {\n                  url: routeUrl,\n                  method: route.method\n              };\n          };\n          return Router;\n      })();";
     $fs->dumpFile($directory . '/router_prod.js', str_replace('%ROUTES%', json_encode($arrayRoutes), $jsFile));
     $fs->dumpFile($directory . '/router_dev.js', str_replace('%ROUTES%', json_encode($arrayRoutesDev), $jsFile));
 }
 /**
  * @param string $contents
  * @return string
  */
 public function add($contents)
 {
     $path = $this->path();
     $this->filesystem->dumpFile($path, $contents);
     $this->files[] = $path;
     return $path;
 }
Beispiel #7
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof StorageEntity && $this->fs->exists($entity->getPath()) && !$this->fs->exists($entity->getPath() . self::ID_FILE)) {
         $this->fs->dumpFile($entity->getPath() . self::ID_FILE, $entity->getId(), 0666);
     }
 }
Beispiel #8
0
 /**
  * {@inheritDoc}
  */
 public function store(BinaryInterface $binary, $path, $filter)
 {
     $this->filesystem->dumpFile(
         $this->getFilePath($path, $filter),
         $binary->getContent()
     );
 }
 /**
  *
  */
 public function testFileExists()
 {
     $this->dumpEntity->setCarefully(true);
     $this->filesystem->dumpFile($this->filePath, 'test');
     $this->setExpectedException('Evheniy\\SitemapXmlBundle\\Exception\\DumpException', 'File "' . $this->filePath . '" already exists!');
     $this->dumpEntity->saveFile($this->filePath, 'test');
 }
Beispiel #10
0
    private function prepareWorkingDirectory()
    {
        $this->currentDirectory = getcwd();
        // create a tmp directory
        $tmpFile = tempnam(sys_get_temp_dir(), '');
        $fs = new Filesystem();
        if ($fs->exists($tmpFile)) {
            $fs->remove($tmpFile);
        }
        $fs->mkdir($tmpFile);
        chdir($tmpFile);
        $this->tmpDirectory = $tmpFile;
        $fs->mkdir('dir');
        $fs->dumpFile('file', 'This is a test file');
        $fs->dumpFile('dir/file', 'This is a test file in a directory');
        $commandLine = <<<'EOF'
git init;
git config user.email "*****@*****.**"
git config user.name "Your Name"
git add file;
git commit -m "adds file";
git tag 0.1.0 -m "Adds file";
git checkout -b branch1 master;
git add dir/file;
git commit -m "adds dir/file";
git tag 0.2.0 -m "Adds file";
git branch branch2
EOF;
        (new Process($commandLine))->mustRun();
    }
Beispiel #11
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $handle = new Filesystem();
     $path = './' . $name;
     try {
         if ($handle->exists($path)) {
             // 抛出目录已存在错误
             throw new IOException('Directory exists!');
         }
         // 创建目录
         $handle->mkdir(array($path . '/posts', $path . '/themes/default/css'));
         // 创建文件
         $handle->touch(array($path . '/config.json', $path . '/posts/hello.md', $path . '/themes/default/index.tpl', $path . '/themes/default/post.tpl'));
         // 填充文件
         $handle->dumpFile($path . '/config.json', 'hello world');
         $handle->dumpFile($path . '/posts/hello.md', 'hello world');
         $handle->dumpFile($path . '/themes/default/index.tpl', 'index-tpl');
         $handle->dumpFile($path . '/themes/default/post.tpl', 'post-tpl');
     } catch (IOException $exception) {
         // 创建项目失败处理异常
         $output->writeln('failed!');
         exit;
     }
     // 输出成功
     $output->writeln('created!');
 }
Beispiel #12
0
 /**
  * Dumps an array into the parameters.yml file.
  *
  * @param array $config
  */
 public function dump(array $config, $mode = 0777)
 {
     $values = ['parameters' => array_merge($this->getConfigValues(), $config)];
     $yaml = Yaml::dump($values);
     $this->fileSystem->dumpFile($this->configFile, $yaml, $mode);
     $this->fileSystem->remove(sprintf('%s/%s.php', $this->kernel->getCacheDir(), $this->kernel->getContainerCacheClass()));
 }
Beispiel #13
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /**
      * @var $schema Schema
      */
     $schema = $this->application->getStorage()->getSchema();
     $debug = $input->getArgument('debug') == true;
     $fs = new Filesystem();
     $fs->dumpFile($this->application->getProject()->getPath('build php Storage Master.php'), $this->fenom->render("master", array('schema' => $schema)));
     if ($debug) {
         echo '- master' . PHP_EOL;
     }
     foreach ($schema->getModels() as $model) {
         $modelGenerator = $this->application->getManager()->create('Cti\\Storage\\Generator\\Model', array('model' => $model));
         $modelSource = $modelGenerator->getCode();
         $path = $this->application->getProject()->getPath('build php Storage Model ' . $model->getClassName() . 'Base.php');
         $fs->dumpFile($path, $modelSource);
         $repositoryGenerator = $this->application->getManager()->create('Cti\\Storage\\Generator\\Repository', array('model' => $model));
         $repositorySource = $repositoryGenerator->getCode();
         $path = $this->application->getProject()->getPath('build php Storage Repository ' . $model->getClassName() . 'Repository.php');
         $fs->dumpFile($path, $repositorySource);
         if ($debug) {
             echo '- generate ' . $model->getClassName() . PHP_EOL;
         }
         //            if($model->hasOwnQuery()) {
         //                $fs->dumpFile(
         //                    $this->application->getPath('build php Storage Query ' . $model->class_name . 'Select.php'),
         //                    $this->application->getManager()->create('Cti\Storage\Generator\Select', array(
         //                        'model' => $model
         //                    ))
         //                );
         //            }
     }
 }
Beispiel #14
0
 /**
  * @return array
  */
 public function getArgs()
 {
     $path = $this->getTemporaryPath();
     $paragraphs = $this->faker->paragraphs(rand(5, 50), true);
     $this->filesystem->dumpFile($path, $paragraphs);
     return [$path];
 }
Beispiel #15
0
 /**
  * Load remote WSDL to local cache.
  *
  * @param string $url
  * @return string
  */
 public function loadWsdl($url)
 {
     $response = $this->guzzleClient->get($url)->send();
     $cacheFilePath = $this->getCachedWsdlPath($url);
     $this->fs->dumpFile($cacheFilePath, $response->getBody(true));
     return $cacheFilePath;
 }
Beispiel #16
0
 /**
  * @param string $binaryImage
  * @param string $filename
  *
  * @return string URL to the image
  */
 public function upload($binaryImage, $filename)
 {
     $targetFile = $this->getTargetPath($filename);
     $this->ensureDirectoryExists(dirname($targetFile));
     $this->filesystem->dumpFile($targetFile, $binaryImage);
     return $targetFile;
 }
 public function test save dumps the content into the certificate file()
 {
     $dummyCertificateFile = uniqid();
     $dummyContent = uniqid();
     $this->mockFilesystem->dumpFile($this->dummyStoragePath . '/' . $dummyCertificateFile, $dummyContent)->shouldBeCalled();
     $this->service->saveCertificateFile($dummyCertificateFile, $dummyContent);
 }
Beispiel #18
0
 /**
  * Load remote WSDL to local cache.
  *
  * @param string $url
  * @return string
  */
 public function loadWsdl($url)
 {
     $clientOptions = ['verify' => empty($this->bundleConfig['sync_settings']['skip_ssl_verification'])];
     $response = $this->guzzleClient->get($url, null, $clientOptions)->send();
     $cacheFilePath = $this->getCachedWsdlPath($url);
     $this->fs->dumpFile($cacheFilePath, $response->getBody(true));
     return $cacheFilePath;
 }
 /**
  * @param string $request
  * @param string $url
  * @param string $response
  */
 public function set($request, $url, $response)
 {
     if ($expires = $this->getRequestExpires($request)) {
         $filename = $this->getFilename($url);
         $this->fs->dumpFile($filename, $response);
         $this->fs->touch($filename, $expires);
     }
 }
Beispiel #20
0
 /**
  * Write to retrofit cache
  *
  * @param GeneratedClassMetaDataProvider $generatedClassMetaDataProvider
  * @param string $contents
  */
 public function write(GeneratedClassMetaDataProvider $generatedClassMetaDataProvider, $contents)
 {
     $contents = "<?php\n" . $contents;
     $path = $this->cacheDir . $generatedClassMetaDataProvider->getFilePath();
     $filename = $path . DIRECTORY_SEPARATOR . $generatedClassMetaDataProvider->getFilenameShort();
     $this->filesystem->mkdir($path);
     $this->filesystem->dumpFile($filename, $contents);
 }
Beispiel #21
0
 public function createExampleFile($path)
 {
     $dir = dirname($path);
     if ($dir) {
         $this->fs->mkdir($dir);
     }
     $this->fs->dumpFile($path, "hello from {$path}");
 }
Beispiel #22
0
 /**
  * {@inheritdoc}
  */
 public function set($key, $value, $ttl = CacheElement::HOUR)
 {
     $createAt = new \DateTime();
     $content = sprintf("<?php\n\nreturn array('createdAt' => %s, 'ttl' => %s, 'data' => '%s');\n", $createAt->format('U'), $ttl, serialize($value));
     $element = new CacheElement($key, $value, $ttl, $createAt);
     $this->filesystem->dumpFile($this->getCacheKey($key), $content);
     return $element;
 }
 public function test persistChallenge dumps a serialized challenge()
 {
     $dummyToken = uniqid();
     $mockChallenge = $this->prophesize(Challenge::class);
     $mockChallenge->getToken()->willReturn($dummyToken);
     $this->mockFilesystem->dumpFile($this->dummyStoragePath . '/' . $dummyToken, serialize($mockChallenge));
     $this->service->persistChallenge($mockChallenge->reveal());
 }
 /**
  * @Given the following acme_php configuration:
  */
 public function theFollowingAcmePhpConfiguration(PyStringNode $rawConfig)
 {
     $yaml = new Yaml();
     $config = ['acme_php' => array_merge($this->getDefaultConfig(), $yaml->parse($rawConfig->getRaw()))];
     $this->filesystem->dumpFile($this->acmeConfigPath, $yaml->dump($config, 4));
     $this->kernel->shutdown();
     $this->filesystem->remove($this->kernel->getCacheDir());
     $this->kernel->boot();
 }
Beispiel #25
0
 /**
  * 方法继承
  * @param string $sessionId
  * @param string $sessionData
  * @return bool|void
  */
 function write($sessionId, $sessionData)
 {
     try {
         $result = $this->filesystem->dumpFile($this->getSessionFile($sessionId), $sessionData);
     } catch (IOException $e) {
         $result = false;
     }
     return $result;
 }
 /**
  * Creates a json log file containing the request and the response contents.
  *
  * @param Request  $request
  * @param Response $response
  *
  * @return string The new mock file path
  */
 public function logReponse(Request $request, Response $response)
 {
     $filename = $this->getFilePathByRequest($request);
     $requestJsonContent = json_decode($request->getContent(), true);
     $responseJsonContent = json_decode($response->getContent(), true);
     $dumpFileContent = ['request' => ['uri' => $request->getRequestUri(), 'method' => $request->getMethod(), 'parameters' => $request->request->all(), 'content' => $requestJsonContent ?: $request->getContent()], 'response' => ['statusCode' => $response->getStatusCode(), 'contentType' => $response->headers->get('Content-Type'), 'content' => $responseJsonContent ?: $response->getContent()]];
     $this->filesystem->dumpFile($this->mocksDir . $filename, self::jsonEncode($dumpFileContent, true));
     return $this->mocksDir . $filename;
 }
 /**
  * {@inheritdoc}
  */
 public function dump($files, $cacheFile, array $options = [])
 {
     $type = isset($options['type']) ? $options['type'] : null;
     $buffer = $this->header;
     foreach ((array) $files as $file) {
         $buffer .= $this->loader->load($file, $type);
     }
     $this->filesystem->dumpFile($this->cacheDir . '/' . $cacheFile, $buffer);
 }
 public function testCurrentFileNotProcessed()
 {
     $date = new \DateTime('now', new \DateTimeZone('UTC'));
     $file = $date->format('Ymd-H') . '-60-1.log';
     $this->fs->dumpFile($this->directory . DIRECTORY_SEPARATOR . $file, json_encode(['prop' => 'value']));
     $result = $this->runCommand('oro:cron:import-tracking', ['--directory' => $this->directory]);
     $this->assertFileExists($this->directory . DIRECTORY_SEPARATOR . $file);
     $this->assertNotContains(sprintf('Successful: "%s"', $file), $result);
 }
 /**
  * @param string $filename
  * @param string $contents
  *
  * @return Command
  *
  * @throws Exception
  */
 protected function writeFile($filename, $contents)
 {
     if (empty($contents)) {
         throw new FileEmptyException('The generated file was empty.');
     }
     $this->filesystem->dumpFile($filename, $contents);
     $this->io->success(sprintf('%s created', $filename));
     return $this;
 }
 public function warmUp($cacheDir)
 {
     $resources = $this->resources;
     foreach ($resources as $resource) {
         $this->processResource($resource);
     }
     $data = $this->compilerCache->serialize();
     $this->fileSystem->dumpFile($this->compilerCacheFilePath, '<?php return "' . base64_encode($data) . '";');
 }