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;
 }
 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();
 }
 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;
 }
 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;
 }
Example #5
0
 /**
  * @expectedException \DomainException
  */
 public function testSettingInvalidTypeThrowsSplException()
 {
     Reference::factory()->setType(0xff);
 }
Example #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");
 }
Example #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;
 }
Example #8
0
 /**
  * @expectedException \DomainException
  */
 public function testSetNegativeLengthThrowsSplException()
 {
     Reference::factory()->setLength(-1);
 }
Example #9
0
 /**
  * @expectedException \LogicException
  */
 public function testAccessingUninitializedIsLastThrowsSplException()
 {
     Reference::factory()->isLast();
 }