/**
  * @param Collection $collection
  * @return Collection
  */
 protected function findTokens(Collection $collection)
 {
     $query = new Query();
     $query->valueLike('!\\n[ ]+\\n!');
     $query->typeIs(T_WHITESPACE);
     return $collection->find($query);
 }
Beispiel #2
0
 /**
  * @param string $start
  * @param string $end
  * @return $this
  */
 public function setDelimiters($start, $end)
 {
     $startQuery = new Query();
     $startQuery->valueIs($start);
     $this->setStartQuery($startQuery);
     $endQuery = new Query();
     $endQuery->valueIs($end);
     $this->setEndQuery($endQuery);
     return $this;
 }
Beispiel #3
0
 /**
  * @param Query $query
  * @return Collection
  */
 public function find(Query $query)
 {
     $result = new Collection();
     foreach ($this->collection as $token) {
         if ($query->isValid($token)) {
             $result[] = $token;
         }
     }
     return $result;
 }
 /**
  * Updates the value of the constant named $key to $value
  *
  * @param mixed $key
  * @param mixed $value
  * @return string
  */
 public function modify($key, $value)
 {
     $tokens = Collection::createFromString($this->source);
     $query = new Query();
     $query->typeIs(T_CONST);
     $constants = $tokens->find($query);
     foreach ($constants as $constant) {
         $this->handleConstant($tokens, $constant, $key, $value);
     }
     return $tokens->assemble();
 }
Beispiel #5
0
 /**
  * @return Query
  */
 protected function getFindQuery()
 {
     if ($this->query !== null) {
         return $this->query;
     }
     $this->query = new Query();
     $this->query->custom(function (Token $token) {
         return (bool) preg_match(LineEndingAbstract::REGEX, $token->getValue());
     });
     return $this->query;
 }
Beispiel #6
0
 /**
  * @param \Funivan\PhpTokenizer\Collection $collection
  * @return \Funivan\PhpTokenizer\Collection
  */
 protected function findTags(Collection $collection)
 {
     $query = new Query();
     $query->typeIs(T_OPEN_TAG);
     if ($this->useShortTags()) {
         $query->valueLike('!^<\\?php\\s+!');
         // long php tag contains also spaces
     } else {
         $query->valueIs('<?');
     }
     return $collection->find($query);
 }