/** * 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); }
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); }
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]; }
/** * 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; }
protected function createResponseForFile(File $file) { return new Response($file->read(), Response::HTTP_OK, array('Content-Type' => $file->getMimetype())); }