Ejemplo n.º 1
0
 protected function applyReference(Reference $reference)
 {
     if (!$this->writer->hasData()) {
         throw new EvaluatorException("No data at '{$reference->getPath()}'");
     }
     if ($this->writer->isArray()) {
         if ($reference->getType() == $reference::TYPE_NEXT_INDEX) {
             $this->writer->selectNewElement();
         } elseif ($reference->getType() == $reference::TYPE_INDEX) {
             $index = (int) $reference->getKey();
             $elementCount = $this->writer->getElementCount();
             if ($index == $elementCount) {
                 $this->writer->selectNewElement();
             } elseif ($index < $elementCount && $index >= 0) {
                 $this->writer->selectElement($index);
             } else {
                 throw new EvaluatorException("Invalid index #{$index} at '{$reference->getPath()}'");
             }
         } else {
             throw new EvaluatorException("Invalid index '{$reference->getKey()}' at '{$reference->getPath()}'");
         }
     } elseif ($this->writer->isObject()) {
         $property = (string) $reference->getKey();
         $this->writer->selectProperty($property);
     } else {
         throw new EvaluatorException("Scalar data at '{$reference->getPath()}'");
     }
     return $this;
 }
Ejemplo n.º 2
0
 public function flush()
 {
     if (null !== $this->reference) {
         throw new LogicException("Reference already flushed in token buffer");
     }
     $this->reference = Reference::factory()->setLength($this->length)->setKey($this->value)->setText($this->text);
     return $this->resetBuffer();
 }
Ejemplo n.º 3
0
 protected function applyReference(Reference $reference)
 {
     if ($this->selector->isArray()) {
         if ($reference->getType() != $reference::TYPE_INDEX) {
             return $this->setResultFromBool(false);
         }
         $index = (int) $reference->getKey();
         $hasData = $this->selector->selectElement($index)->hasData();
         if (!$hasData) {
             return $this->setResultFromBool(false);
         }
     } elseif ($this->selector->isObject()) {
         $property = (string) $reference->getKey();
         $hasData = $this->selector->selectProperty($property)->hasData();
         if (!$hasData) {
             return $this->setResultFromBool(false);
         }
     } else {
         return $this->setResultFromBool(false);
     }
     return $this;
 }
Ejemplo n.º 4
0
 protected function applyReference(Reference $reference)
 {
     if ($this->selector->isArray()) {
         if ($reference->getType() != $reference::TYPE_INDEX) {
             throw new EvaluatorException("Invalid index '{$reference->getKey()}' at {$reference->getPath()}");
         }
         $index = (int) $reference->getKey();
         $this->selector->selectElement($index);
         if (!$this->selector->hasData()) {
             throw new EvaluatorException("No index #{$index} at {$reference->getPath()}");
         }
     } elseif ($this->selector->isObject()) {
         $property = (string) $reference->getKey();
         $this->selector->selectProperty($property);
         if (!$this->selector->hasData()) {
             throw new EvaluatorException("No property '{$property}' at {$reference->getPath()}");
         }
     } else {
         throw new EvaluatorException("Scalar data at {$reference->getPath()}");
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * @expectedException \DomainException
  */
 public function testSettingInvalidTypeThrowsSplException()
 {
     Reference::factory()->setType(0xff);
 }
Ejemplo n.º 6
0
 /**
  */
 public function testGotValueSameAsSet()
 {
     $value = 'abc';
     $reference = Reference::factory()->setKey($value);
     $this->assertEquals($value, $reference->getKey(), "Got value differs from the one that was set");
 }
Ejemplo n.º 7
0
 protected function setupReferenceType(Reference $reference)
 {
     $result = preg_match('#^(0|[1-9]\\d*)$#u', $reference->getKey());
     PregHelper::assertMatchResult($result, RegExpException::class, "Regular expression error on reference type detection");
     if (1 === $result) {
         $type = Reference::TYPE_INDEX;
     } elseif ('-' == $reference->getKey()) {
         $type = Reference::TYPE_NEXT_INDEX;
     } else {
         $type = Reference::TYPE_PROPERTY;
     }
     $reference->setType($type);
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * @expectedException \DomainException
  */
 public function testSetNegativeLengthThrowsSplException()
 {
     Reference::factory()->setLength(-1);
 }
Ejemplo n.º 9
0
 /**
  * @expectedException \LogicException
  */
 public function testAccessingUninitializedIsLastThrowsSplException()
 {
     Reference::factory()->isLast();
 }