public function testCanCreateSmallSitemap()
    {
        $expected = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>http://foo.com/1</loc>
  </url>
  <url>
    <loc>http://foo.com/2</loc>
  </url>
  <url>
    <loc>http://foo.com/3</loc>
  </url>
</urlset>

XML;
        $urls = [];
        for ($i = 1; $i <= 3; $i++) {
            $urls[] = ['url' => 'http://foo.com/' . $i];
        }
        $path = $this->factory->createSitemap(new ArrayIterator($urls));
        $actual = $this->filesystem->read($path);
        $this->filesystem->delete($path);
        $this->assertEquals($expected, $actual);
    }
예제 #2
0
 /**
  * Return admin assets
  * @param Response $response
  * @param $asset
  * @return Response|static
  * @throws FileNotFoundException
  */
 public function assets(Response $response, $asset)
 {
     $filesystem = new Filesystem(new Adapter(FS2ADMIN));
     $expires = 8640000;
     try {
         // generate cache data
         $timestamp_string = gmdate('D, d M Y H:i:s ', $filesystem->getTimestamp($asset)) . 'GMT';
         $etag = md5($filesystem->read($asset));
         $mime_type = $filesystem->getMimetype($asset);
         if (0 !== strpos($mime_type, 'image')) {
             $mime_type = 'text/css';
         }
         $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
         $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : false;
         if (($if_none_match && $if_none_match == "\"{$etag}\"" || !$if_none_match) && ($if_modified_since && $if_modified_since == $timestamp_string)) {
             return $response->withStatus('304');
         } else {
             $response = $response->withHeader('Last-Modified', $timestamp_string)->withHeader('ETag', "\"{$etag}\"");
         }
         // send out content type, expire time and the file
         $response->getBody()->write($filesystem->read($asset));
         return $response->withHeader('Expires', gmdate('D, d M Y H:i:s ', time() + $expires) . 'GMT')->withHeader('Content-Type', $mime_type)->withHeader('Pragma', 'cache')->withHeader('Cache-Control', 'cache');
     } catch (FileNotFoundException $e) {
         throw $e;
     }
 }
예제 #3
0
 /**
  * Populates the "data" key with the file's JSON data
  *
  * @param array $file
  */
 private function addData(array &$file)
 {
     $data = json_decode($this->fs->read($file['path']), true);
     if ($data === null) {
         throw new \DomainException(sprintf('%s is not a valid JSON file.', $file['path']));
     }
     $file['data'] = $data;
 }
 private function getFile($path)
 {
     try {
         return $this->filesystem->read($path);
     } catch (FileNotFoundException $e) {
         return null;
     }
 }
예제 #5
0
 /**
  * Returns the value for a key.
  *
  * @param string $key A unique key
  *
  * @return string|false The file contents or false on failure.
  */
 public function get($key)
 {
     try {
         return $this->filesystem->read($key);
     } catch (FileNotFoundException $exception) {
         return false;
     }
 }
예제 #6
0
 /**
  * @inheritdoc
  */
 public function read($path)
 {
     try {
         return $this->fileSystem->read($this->getInnerPath($path));
     } catch (FileNotFoundException $e) {
         throw $this->exceptionWrapper($e, $path);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function parse(Configuration $configuration = null)
 {
     if (!$this->filesystem->has($this->file)) {
         throw new ParsingFailed(sprintf('File "%s" not found', $this->file));
     }
     $fileContents = $this->filesystem->read($this->file);
     $parser = new Text($fileContents);
     return $parser->parse($configuration);
 }
예제 #8
0
 /**
  * @return false|string
  */
 private function loadFile()
 {
     if (!$this->filesystem->has($this->getFile())) {
         $this->filesystem->write($this->getFile(), '');
     }
     if (!$this->sites) {
         $this->sites = $this->filesystem->read($this->file);
     }
     return $this->sites;
 }
 /**
  * @inheritdoc
  */
 public function fetch($key)
 {
     if ($this->filesystem->has($key)) {
         // The file exist, read it!
         $data = @unserialize($this->filesystem->read($key));
         if ($data instanceof CacheEntry) {
             return $data;
         }
     }
     return;
 }
예제 #10
0
 /**
  * @param string $providerPrefix
  * @param string $uri
  * @param string $query
  *
  * @return bool|mixed
  */
 public function get($providerPrefix, $uri, $query)
 {
     $hash = $this->getHash($providerPrefix, $uri, $query);
     $ttlCutoff = time() - $this->ttl;
     if ($this->filesystem->has($hash) and $this->filesystem->getTimestamp($hash) > $ttlCutoff) {
         $data = $this->filesystem->read($hash);
         if (!empty($data)) {
             return $data;
         }
     }
     return false;
 }
예제 #11
0
 /**
  * Returns the historical price data as a csv string for $ticker
  * @param string $ticker
  * @param bool $fromCache
  * @param bool $saveToCache
  * @param bool $return
  * @return TickerCollection
  */
 public function getData($ticker, $fromCache = true, $saveToCache = true, $return = true)
 {
     if ($fromCache && $this->fileSystem->has($ticker)) {
         return $this->present($ticker, $this->fileSystem->read($ticker));
     }
     $data = (string) $this->guzzle->request('GET', '', ['query' => ['s' => $ticker, 'ignore' => '.csv']])->getBody();
     if ($saveToCache) {
         $this->fileSystem->put($ticker, $data);
     }
     if ($return) {
         return $this->present($ticker, $data);
     }
 }
 /**
  * Test setting prefixes for both output filename and URLs in vtt file
  */
 public function testPrefixes()
 {
     $ts = new ThumbnailSprite();
     $ts->setSource($this->testSrc);
     $ts->setOutputDirectory(dirname($this->testSrc));
     $ts->setPrefix('blubber');
     $ts->setUrlPrefix('http://example.org');
     $ts->generate();
     $this->assertTrue($this->outputFS->has('blubber.jpg'));
     $this->assertTrue($this->outputFS->has('blubber.vtt'));
     $vtt = $this->outputFS->read('blubber.vtt');
     $this->assertContains('http://example.org/blubber.jpg#xywh', $vtt);
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function load(Configuration $configuration = null)
 {
     if (!$this->filesystem->has($this->file)) {
         throw new LoaderException(sprintf('File "%s" not found', $this->file));
     }
     if (!($fileContents = $this->filesystem->read($this->file))) {
         throw new LoaderException(sprintf('Reading file "%s" failed', $this->file));
     }
     try {
         $ini = $this->getParser()->parse($fileContents);
     } catch (ParserException $e) {
         throw new LoaderException('Cannot parse INI', 0, $e);
     }
     return $this->parseSections($ini, $configuration);
 }
예제 #14
0
 /**
  * read all metadata from module file.
  * @param type $module_system_name
  * @return type
  */
 public function readModuleMetadata($module_system_name)
 {
     $adapter = new Local(MODULE_PATH);
     $filesystem = new Filesystem($adapter);
     unset($adapter);
     $output = [];
     if ($filesystem->has($module_system_name . DS . $module_system_name . '.php')) {
         $content = $filesystem->read($module_system_name . DS . $module_system_name . '.php');
         preg_match_all('|([a-zA-Z0-9-_ ]+):(.*)$|mi', $content, $matches, PREG_PATTERN_ORDER);
         unset($content);
         if (isset($matches) && is_array($matches) && array_key_exists(1, $matches) && array_key_exists(2, $matches) && is_array($matches[1]) && is_array($matches[2])) {
             foreach ($matches[1] as $key => $item) {
                 if (!is_array($item) && array_key_exists($key, $matches[2]) && !is_array($matches[2][$key])) {
                     $output[trim($item)] = trim($matches[2][$key]);
                 }
             }
         }
     }
     // validate available metadata
     foreach ($this->available_metadata as $meta_name) {
         if (!array_key_exists($meta_name, $output)) {
             $output[$meta_name] = '';
         }
     }
     unset($filesystem, $item, $key, $matches, $meta_name);
     return $output;
 }
예제 #15
0
 /**
  * read all metadata from theme file.
  * @param type $theme_system_name
  * @return type
  */
 public function readThemeMetadata($theme_system_name)
 {
     // get theme config
     $Config = new \System\Libraries\Config();
     $Config->load('theme');
     $theme_dir = $Config->get('theme_dir', 'theme');
     unset($Config);
     $adapter = new Local($theme_dir);
     $filesystem = new Filesystem($adapter);
     unset($adapter, $theme_dir);
     $output = [];
     if ($filesystem->has($theme_system_name . DS . $theme_system_name . '.php')) {
         $content = $filesystem->read($theme_system_name . DS . $theme_system_name . '.php');
         preg_match_all('|([a-zA-Z0-9-_ ]+):(.*)$|mi', $content, $matches, PREG_PATTERN_ORDER);
         unset($content);
         if (isset($matches) && is_array($matches) && array_key_exists(1, $matches) && array_key_exists(2, $matches) && is_array($matches[1]) && is_array($matches[2])) {
             foreach ($matches[1] as $key => $item) {
                 if (!is_array($item) && array_key_exists($key, $matches[2]) && !is_array($matches[2][$key])) {
                     $output[trim($item)] = trim($matches[2][$key]);
                 }
             }
         }
     }
     // validate available metadata
     foreach ($this->available_metadata as $meta_name) {
         if (!array_key_exists($meta_name, $output)) {
             $output[$meta_name] = '';
         }
     }
     unset($filesystem, $item, $key, $matches, $meta_name);
     return $output;
 }
예제 #16
0
 /**
  * Get cached string from store.
  *
  * @param  string $key
  *
  * @return null|string
  */
 public function get($key)
 {
     if (!is_string($key)) {
         return;
     }
     try {
         $file = $this->get_file_name($key);
         // Expire the file if the expires time is not zero.
         if ($this->args['expires'] > 0) {
             $time = $this->filesystem->getTimestamp($file);
             // If time is bigger than expires and file timestamp
             // the file should be deleted and null should be returned
             // since the cache has expired.
             if (time() > $this->args['expires'] * $time) {
                 $this->filesystem->delete($file);
                 return;
             }
         }
         // Try to read the file.
         $content = $this->filesystem->read($file);
         // Delete the file if empty.
         if (empty($content)) {
             $this->filesystem->delete($file);
         }
         return $content;
     } catch (FileNotFoundException $e) {
         return;
     }
 }
예제 #17
0
 /**
  * Process give source file with given options
  *
  * @param array $options
  * @param $sourceFile
  * @return string
  */
 public function process($options, $sourceFile)
 {
     //check restricted_domains is enabled
     if ($this->params['restricted_domains'] && is_array($this->params['whitelist_domains']) && !in_array(parse_url($sourceFile, PHP_URL_HOST), $this->params['whitelist_domains'])) {
         throw new \Exception('Restricted domains enabled, the domain your fetching from is not allowed: ' . parse_url($sourceFile, PHP_URL_HOST));
     }
     $options = $this->parseOptions($options);
     $newFileName = md5(implode('.', $options) . $sourceFile);
     if ($this->filesystem->has($newFileName) && $options['refresh']) {
         $this->filesystem->delete($newFileName);
     }
     if (!$this->filesystem->has($newFileName)) {
         $this->saveNewFile($sourceFile, $newFileName, $options);
     }
     return $this->filesystem->read($newFileName);
 }
예제 #18
0
 /**
  * Return an array of rules
  *
  * @return array
  */
 public function rules()
 {
     $rules = NULL;
     $json = NULL;
     $string = $this->filesystem->read($this->filename);
     if ($string) {
         $json = json_decode($string, true);
     }
     if ($json) {
         $rules = array();
         foreach ($json as $experiment => $rule) {
             $rules[$experiment] = $this->factory->create($experiment, $rule);
         }
     }
     return $rules;
 }
예제 #19
0
 /**
  * Read skip file
  *
  * @param $pathToSkipFile
  * @return array|mixed
  */
 private function getSkipedData($pathToSkipFile)
 {
     if ($this->system->has($pathToSkipFile)) {
         $content = $this->system->read($pathToSkipFile);
         return unserialize($content);
     }
     return [];
 }
예제 #20
0
 /**
  * Read a file.
  *
  * @param string $path The path to the file.
  *
  * @throws FileNotFoundException
  *
  * @return string|false The file contents or false on failure.
  */
 public function read($path)
 {
     try {
         return $this->filesystem->read($path);
     } catch (FlysystemFileNotFoundException $e) {
         FileNotFoundException::fileNotFound();
     }
 }
예제 #21
0
 /**  */
 public function read($id, array $options = [])
 {
     if (!isset($options['refresh']) && $id == $this->id && $this->config != null) {
         return $this->config;
     }
     try {
         $data = $this->filesystem->read($this->getPathFromId($id));
         $config = $this->validate($this->parse($data));
         $this->config = $config;
         $this->id = $id;
         $this->timestamp = $this->filesystem->getTimestamp($this->getPathFromId($id));
         return $config;
     } catch (\League\Flysystem\Exception $e) {
         throw $e;
         //FIXME better handling
     }
 }
예제 #22
0
 public function do()
 {
     $this->io->writeln('Getting Config!');
     $s3Client = new S3Client(['version' => 'latest', 'region' => 'us-east-1']);
     $adapter = new AwsS3Adapter($s3Client, $this->config->get('bucket'));
     $s3 = new Filesystem($adapter);
     $config = $s3->read($this->config->get('AppName') . '/Config/' . $this->config->get('config_file'));
     file_put_contents($this->config->get('build_path', getcwd() . '/build/' . $this->config->get('config_file')), $config);
 }
예제 #23
0
 /**
  * {@inheritdoc}
  */
 public function restore(Filesystem $source, Filesystem $destination, ReadonlyDatabase $database, array $parameter)
 {
     $this->output->writeln('  * <comment>import "export.xml" to "' . $parameter['path'] . '"</comment>');
     $tempfile = $this->temporaryFileSystem->createTemporaryFile('jackrabbit');
     $handle = fopen($tempfile, 'w+');
     file_put_contents($tempfile, $source->read('export.xml'));
     fclose($handle);
     $this->import($this->getSession($parameter), $parameter['path'], $tempfile);
 }
예제 #24
0
 /**
  * @return array
  */
 public function getSkipSeries()
 {
     $file = SERIES_FOLDER . '/.skip';
     if ($this->system->has($file)) {
         $content = $this->system->read($file);
         return unserialize($content);
     }
     return [];
 }
 public function testPostExample()
 {
     $filesystem = new Filesystem(new Adapter(__DIR__ . '.'));
     //dd($filesystem);
     $data = $filesystem->read('commit-message-with-key.json');
     $contents = json_decode($data, true);
     $response = $this->call('POST', 'gitlab/user/list');
     // i don't know why statusCode is 404.
     $this->assertEquals($response->getStatusCode(), 404);
 }
예제 #26
0
 public function testStoreDomainCertificate()
 {
     $cert = new Certificate(self::$certPem, new Certificate(self::$issuerCertPem));
     $this->repository->storeDomainKeyPair('example.com', new KeyPair(new PublicKey('public'), new PrivateKey('private')));
     $this->repository->storeDomainCertificate('example.com', $cert);
     $this->assertEquals(self::$certPem . "\n", $this->master->read('certs/example.com/cert.pem'));
     $this->assertEquals(self::$issuerCertPem . "\n", $this->master->read('certs/example.com/chain.pem'));
     $this->assertEquals(self::$certPem . "\n" . self::$issuerCertPem . "\n", $this->master->read('certs/example.com/fullchain.pem'));
     $this->assertEquals(self::$certPem . "\n" . self::$issuerCertPem . "\nprivate\n", $this->master->read('certs/example.com/combined.pem'));
 }
 public function testClassesInGivenNameSpaceRootAreAddedAsMethods()
 {
     $client = Mockery::mock(ClientInterface::class);
     $out = Mockery::mock(OutputInterface::class);
     $out->shouldReceive("write");
     $out->shouldReceive("writeln")->times(12);
     $inMock = Mockery::mock(InputInterface::class);
     $dialog = Mockery::mock(QuestionHelper::class);
     $dialog->shouldReceive("ask")->andReturn(true);
     $generator = new EndpointGenerator($inMock, $out, $dialog);
     $generator->generateForEndpoint("Episodes");
     $content = $this->filesystem->read("Episodes.php");
     $this->assertContains('public function comments', $content);
     $this->assertContains('public function ratings', $content);
     $this->assertContains('public function stats', $content);
     $this->assertContains('public function summary', $content);
     $this->assertContains('public function get', $content);
     $this->assertContains('public function watching', $content);
 }
예제 #28
0
 /**
  * {@inheritdoc}
  */
 public function restore(Filesystem $source, Filesystem $destination, ReadonlyDatabase $database, array $parameter)
 {
     $tempFile = $this->temporaryFileSystem->createTemporaryFile('mysql');
     file_put_contents($tempFile, $source->read('dump.sql'));
     $process = new Process($this->getImportCommand($parameter['username'], $parameter['password'], $parameter['database'], $tempFile));
     $process->run();
     while ($process->isRunning()) {
         // waiting for process to finish
     }
     $this->output->writeln(sprintf('  * <comment>%s</comment>', $this->getImportCommand($parameter['username'], $parameter['password'], $parameter['database'], 'dump.sql', true)));
 }
예제 #29
0
 /**
  * Read a file
  *
  * ```php
  * read('cache/file.tmp')
  * read('~/file.tmp$/')
  * ```
  *
  * @param  string $path path to file or regexp pattern
  * @return string|false          file contents or FALSE when fails
  *                               to read existing file
  */
 public function read($path)
 {
     if (StringHelper::isRegexp($path) && !($path = $this->searchByPattern($path))) {
         return false;
     }
     try {
         return parent::read($path);
     } catch (\Exception $e) {
         $this->errors[] = StringHelper::replace(FileException::UNKNOWN_FILE, ['path' => $path]);
     }
     return false;
 }
 public function testReplaceExistsCopy()
 {
     $resourceDOSource = $this->getResourceDOMock();
     $resourceDODest = $this->getResourceDOMock();
     $resourceDODest->setVersion($resourceDOSource->getVersion() + 1);
     $contentExpected = 'New content';
     $this->filesystem->put($resourceDOSource->getFilePath(), $contentExpected);
     $this->filesystem->put($resourceDODest->getFilePath(), 'Exist content');
     $command = $this->getCommand($resourceDOSource, $resourceDODest);
     $result = $command(true);
     $this->assertEquals($resourceDODest, $result);
     $this->assertEquals($contentExpected, $this->filesystem->read($resourceDODest->getFilePath()));
 }