compile() public static method

Compiles a template with variables.
public static compile ( string $template, array $variables, callable $filter = null ) : string
$template string Template.
$variables array Variables.
$filter callable Filter function.
return string Compiled template.
 /**
  *
  */
 public function testCompile()
 {
     $template = Template::compile(':foo {:bar}', ['foo' => 'foo', 'bar' => 'bar']);
     $this->assertEquals('foo bar', $template);
     $template = Template::compile(':html', ['html' => '<html>'], 'htmlspecialchars');
     $this->assertEquals('&lt;html&gt;', $template);
 }
 /**
  *	{@inheritDoc}
  */
 public function prepare($url)
 {
     if (preg_match($this->_pattern, $url, $matches)) {
         $url = Template::compile($this->_template, ['id' => $matches['id']]);
     }
     return $url;
 }
Esempio n. 3
0
 /**
  *	{@inheritDoc}
  */
 public function present(Media $Media)
 {
     $switch = $Media->get($this->_switch);
     if ($switch && !$Media->has($this->_property)) {
         foreach ($this->_templates as $pattern => $template) {
             if (preg_match($pattern, $switch)) {
                 $Media->set($this->_property, Template::compile($template, $Media->properties(), 'htmlspecialchars'));
                 break;
             }
         }
     }
     return $Media;
 }
Esempio n. 4
0
 /**
  *	Builds an oEmbed configuration from settings.
  *
  *	@param string $url URL to embed.
  *	@return Config Configuration.
  */
 protected function _buildConfig($url)
 {
     $endpoint = Template::compile($this->get('endpoint'), compact('url'), 'urlencode');
     return new Config($endpoint, $this->get('format'));
 }