Example #1
0
 private function fileToArray($filename)
 {
     $file = new File($filename);
     if (!$file->exists()) {
         throw new FileNotFoundException(sprintf('File not found at: %s', $filename));
     }
     return Json::decode($file->read());
 }
Example #2
0
 /**
  *
  * @param string $filename
  * @throws FileNotFoundException
  * @throws JsonException
  * @return static
  */
 public static function fromFile($filename)
 {
     $file = new File($filename);
     if (!$file->exists()) {
         throw new FileNotFoundException(sprintf('File not found at: %s', $filename));
     }
     $json = Json::decode($file->read());
     return new static($json);
 }
Example #3
0
 /**
  * @throws FileNotFoundException
  * @return AbstractPhpStruct
  */
 public function parse()
 {
     $file = new File($this->filename);
     if (!$file->exists()) {
         throw new FileNotFoundException(sprintf('File (%s) does not exist.', $this->filename));
     }
     $parser = $this->getParser();
     $traverser = new NodeTraverser();
     $traverser->addVisitor($this);
     $traverser->traverse($parser->parse($file->read()));
 }
Example #4
0
 public function testCopy()
 {
     $file = new File($this->root->url() . '/dir/composer.json');
     $file->write('{}');
     $file->copy($this->root->url() . '/composer.json');
     $this->assertTrue(file_exists($this->root->url() . '/composer.json'));
     $this->assertTrue(file_exists($this->root->url() . '/dir/composer.json'));
     $a = new File($this->root->url() . '/dir/composer.json');
     $b = new File($this->root->url() . '/composer.json');
     $this->assertEquals($a->read(), $b->read());
 }
 /**
  * 
  * @param AbstractPhpStructVisitor $visitor
  * @param string $filename
  * @throws FileNotFoundException
  * @return AbstractPhpStruct
  */
 public function parse(AbstractPhpStructVisitor $visitor, $filename)
 {
     $file = new File($filename);
     if (!$file->exists()) {
         throw new FileNotFoundException(sprintf('File (%s) does not exist.', $filename));
     }
     $parser = new Parser(new Emulative());
     $traverser = new NodeTraverser();
     $traverser->addVisitor($visitor);
     $traverser->traverse($parser->parse($file->read()));
     return $visitor->getStruct();
 }