ReplaceTokens::replaceTokenCallback PHP Method

replaceTokenCallback() private method

Performs lookup on key and returns appropriate replacement string.
private replaceTokenCallback ( array $matches ) : string
$matches array Array of 1 el containing key to search for.
return string Text with which to replace key or value of key if none is found.
    private function replaceTokenCallback($matches)
    {
        $key = $matches[1];
        /* Get tokens from tokensource and merge them with the
         * tokens given directly via build file. This should be 
         * done a bit more elegantly
         */
        if ($this->_alltokens === null) {
            $this->_alltokens = array();
            $count = count($this->_tokensources);
            for ($i = 0; $i < $count; $i++) {
                $source = $this->_tokensources[$i];
                $this->_alltokens = array_merge($this->_alltokens, $source->getTokens());
            }
            $this->_alltokens = array_merge($this->_tokens, $this->_alltokens);
        }
        $tokens = $this->_alltokens;
        $replaceWith = null;
        $count = count($tokens);
        for ($i = 0; $i < $count; $i++) {
            if ($tokens[$i]->getKey() === $key) {
                $replaceWith = $tokens[$i]->getValue();
            }
        }
        if ($replaceWith === null) {
            $replaceWith = $this->_beginToken . $key . $this->_endToken;
            $this->log("No token defined for key \"" . $this->_beginToken . $key . $this->_endToken . "\"");
        } else {
            $this->log("Replaced \"" . $this->_beginToken . $key . $this->_endToken . "\" with \"" . $replaceWith . "\"");
        }
        return $replaceWith;
    }