コード例 #1
0
ファイル: YamlUpdater.php プロジェクト: Twiebie/bolt
 /**
  * Updates a single value with replacement for given key in yml file.
  *
  * @param string $key
  * @param string $value
  *
  * @return boolean
  */
 public function change($key, $value, $makebackup = true)
 {
     $pattern = str_replace("/", ":.*", $key);
     preg_match_all('/^' . $pattern . '(:\\s*)/mis', $this->file->read(), $matches, PREG_OFFSET_CAPTURE);
     if (count($matches[0]) > 0 && count($matches[1])) {
         $index = $matches[1][0][1] + strlen($matches[1][0][0]);
     } else {
         return false;
     }
     $line = substr_count($this->file->read(), "\n", 0, $index);
     $this->yaml[$line] = preg_replace('/^(.*):(.*)/', "\$1: " . $this->prepareValue($value), $this->yaml[$line]);
     return $this->save($makebackup);
 }
コード例 #2
0
 public function testFileRead()
 {
     $prophecy = $this->prophesize('League\\Flysystem\\FilesystemInterface');
     $prophecy->read('path.txt')->willReturn('contents');
     $filesystem = $prophecy->reveal();
     $file = new File(null, 'path.txt');
     $file->setFilesystem($filesystem);
     $output = $file->read();
     $this->assertEquals('contents', $output);
 }
コード例 #3
0
ファイル: Indexer.php プロジェクト: sekjun9878/elphp
 public static function index(File $file)
 {
     $lexer = new Lexer(array('usedAttributes' => array('comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos')));
     $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP5, $lexer);
     $traverser = new NodeTraverser();
     $traverser->addVisitor(new ScopeResolver());
     $stmts = $parser->parse($file->read());
     $stmts = new ScopeResolvedNodes($traverser->traverse($stmts));
     $functions = (new BasicFunctionIndexer($file, $stmts))->index();
     $variables = (new BasicVariableIndexer($file, $stmts))->index();
     return ["functions" => $functions, "variables" => $variables];
 }
コード例 #4
0
 /**
  * Reads versions from the storage file.
  *
  * @return VersionInterface[]
  *
  * @throws StorageException
  */
 protected function doFetchAll()
 {
     $contents = $this->file->read();
     $lines = explode("\n", $contents);
     $collection = new Migrated();
     foreach ($lines as $line) {
         $line = trim($line);
         if (!empty($line)) {
             // skip empty lines
             $version = new Version($line);
             $version->setMigrated(true);
             // if its in storage its because it has been migrated
             $collection->add($version);
         }
     }
     return $collection;
 }
コード例 #5
0
ファイル: FileReader.php プロジェクト: h4cc/stack-flysystem
 protected function createResponseForFile(File $file)
 {
     return new Response($file->read(), Response::HTTP_OK, array('Content-Type' => $file->getMimetype()));
 }