Пример #1
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;
 }
Пример #2
0
 /**
  * Checks if text at current cursor position starts from token of given type.
  *
  * @param int $type
  * @return string|null Token text or NULL.
  * @todo Split method in two.
  */
 protected function matchTokenTextAtCursor(int $type)
 {
     $result = preg_match($this->getTokenPattern($type), $this->getTextAtCursor(), $matches);
     PregHelper::assertMatchResult($result, RegExpException::class, "Failed to match token text due to regular expression error");
     if (1 === $result) {
         $text = $matches[0];
         if (strlen($text) == 0) {
             throw new LengthException("Matched token text is empty");
         }
     } else {
         $text = null;
     }
     return $text;
 }