Base::build PHP Method

build() public method

Replace tokenized URL with available token values
public build ( $url, $args = [] ) : string
$url array|string
$args array
return string
    function build($url, $args = [])
    {
        $args += $this->hive['PARAMS'];
        if (is_array($url)) {
            foreach ($url as &$var) {
                $var = $this->build($var, $args);
                unset($var);
            }
        } else {
            $i = 0;
            $url = preg_replace_callback('/@(\\w+)|(\\*)/', function ($match) use(&$i, $args) {
                if (isset($match[1]) && array_key_exists($match[1], $args)) {
                    return $args[$match[1]];
                }
                if (isset($match[2]) && array_key_exists($match[2], $args)) {
                    if (!is_array($args[$match[2]])) {
                        return $args[$match[2]];
                    }
                    $i++;
                    return $args[$match[2]][$i - 1];
                }
                return $match[0];
            }, $url);
        }
        return $url;
    }

Usage Example

Esempio n. 1
0
 /**
  * @return null
  */
 public function testBuild()
 {
     $expected = '<base href="' . $this->href . '" target="' . $this->target . '">';
     $this->assertEquals($expected, $this->base->build());
     $base = new BaseTag($this->href);
     $expected = '<base href="' . $this->href . '">';
     $this->assertEquals($expected, $base->build());
     $base = new BaseTag(null, $this->target);
     $expected = '<base target="' . $this->target . '">';
     $this->assertEquals($expected, $base->build());
 }
All Usage Examples Of Base::build