/** * extractFirstCall to a Placeholder method from a Document. * * @param \nochso\WriteMe\Document $document * @param int $priority * @param int $offset * * @return Call|null */ public static function extractFirstCall(Document $document, $priority = \nochso\WriteMe\Interfaces\Placeholder::PRIORITY_FIRST, $offset = 0) { $call = null; $content = $document->getContent(); if ($offset > 0) { $content = mb_substr($content, $offset); } if (preg_match(self::REGEX, $content, $matches, PREG_OFFSET_CAPTURE) === 1) { $call = new self(); $call->document = $document; $call->priority = $priority; $call->identifier = $matches[3][0]; $call->rawCall = $matches[0][0]; // Position of the match including additional offset from before $call->rawCallFirstPosition = $matches[0][1] + $offset; if (isset($matches[5]) && $matches[5][0] !== '') { $call->method = $matches[5][0]; } if (isset($matches[7])) { $call->extractParameters($matches[7][0]); } } return $call; }