Exemple #1
0
 /**
  * @param $data
  * @param $fileType
  * @return array
  * @throws InvalidTypeException
  * @throws UnsupportedFileTypeException
  */
 public function parse($data, $fileType)
 {
     if (!is_string($data)) {
         throw new InvalidTypeException('$data', 'string', gettype($data));
     }
     if (!is_string($fileType)) {
         throw new InvalidTypeException('$fileType', 'string', gettype($fileType));
     }
     /** @var CommentParser\FileType\AbstractFileType $canonicalFileType */
     $canonicalFileType = $this->guessFileType($fileType);
     if (!$canonicalFileType) {
         throw new UnsupportedFileTypeException($fileType);
     }
     $seeder = new Seeder($data);
     $flavours = $canonicalFileType->getFlavours();
     $result = [];
     while (!$seeder->eof()) {
         foreach ($flavours as $flavour) {
             call_user_func_array($flavour, [$seeder, &$result]);
         }
         if ($this->isScrapeUnknown() && !$seeder->eof()) {
             Flavour\Unknown::parse($seeder, $result);
         } else {
             $seeder->forward();
         }
     }
     return $result;
 }
Exemple #2
0
 public function testSeeder()
 {
     $seeder = new Seeder('abc123');
     $this->assertEquals(0, $seeder->getPosition());
     $this->assertEquals(6, $seeder->getLength());
     $this->assertTrue($seeder->sof());
     $this->assertFalse($seeder->eof());
     $this->assertEquals('abc123', $seeder->get(6));
     $this->assertEquals('abc123', $seeder->get(1000));
     $this->assertEquals('abc', $seeder->get(3));
     $this->assertEquals('a', $seeder->get());
     $seeder->forward();
     $this->assertEquals('b', $seeder->get());
     $seeder->forward();
     $this->assertEquals('c', $seeder->get());
     $seeder->forward(2);
     $this->assertEquals('2', $seeder->get());
     $seeder->backward(2);
     $this->assertEquals('c', $seeder->get());
     $seeder->backward();
     $this->assertEquals('b', $seeder->get());
     $seeder->forward(4);
     $this->assertFalse($seeder->eof());
     $seeder->forward(1);
     $this->assertTrue($seeder->eof());
 }
Exemple #3
0
 /**
  * @param Seeder $seeder
  * @throws CommentParser\UnexpectedEOFException
  */
 protected static function trackEOF(Seeder $seeder)
 {
     if ($seeder->eof()) {
         throw new CommentParser\UnexpectedEOFException();
     }
 }