Goetas\Twital\TwitalLoader::addSourceAdapter PHP Method

addSourceAdapter() public method

If $pattern is a string, then must be a valid regex that matches the template filename. If $pattern is a callback, then must return true if the template is compilable, false otherwise.
public addSourceAdapter ( string | callback $pattern, Goetas\Twital\SourceAdapter $adapter ) : TwitalLoader
$pattern string | callback
$adapter Goetas\Twital\SourceAdapter
return TwitalLoader
    public function addSourceAdapter($pattern, SourceAdapter $adapter)
    {
        $this->sourceAdapters[$pattern] = $adapter;
        return $this;
    }

Usage Example

 /**
  * Render a string
  *
  * A special option in the $locals array can be used to define the Twital adapter to use.
  * The array key is `__twital-adapter`, and the value is an instance of `\Goetas\Twital\SourceAdapter`
  *
  * @param string $template The template content to render
  * @param array $locals The variable to use in template
  * @return null|string
  *
  * @throws \Twig_Error_Loader
  * @throws \Twig_Error_Runtime
  * @throws \Twig_Error_Syntax
  */
 public function render($template, array $locals = array())
 {
     if (array_key_exists('__twital-adapter', $locals)) {
         $this->stringLoader->addSourceAdapter('/.*/', $locals['__twital-adapter']);
     }
     // Render the file using the straight string.
     $this->environment->setLoader($this->stringLoader);
     return $this->environment->render($template, $locals);
 }
All Usage Examples Of Goetas\Twital\TwitalLoader::addSourceAdapter