function display(Jig $jig) { $functionHelper = new FunctionHelper(); $closureFunction = function () { $args = func_get_args(); echo "This is a closure function. The args were: " . var_export($args); }; $functionHelper->bindFunction('closureFunction', $closureFunction); $functionHelper->bindFunction('globalFunction', 'JigDemo\\Controller\\globalFunction'); $functionHelper->bindFunction('classFunction', [$this, 'classFunction']); $jig->addDefaultHelper(get_class($functionHelper)); return getTemplateCallable('functionExample', [$functionHelper]); }
public function __construct(JigConfig $jigConfig, Injector $injector, JigConverter $jigConverter = null, Escaper $escaper = null) { parent::__construct($jigConfig, $jigConverter); $this->injector = $injector; $this->injector->alias('Jig\\Jig', get_class($this)); $this->injector->share($this); if ($escaper === null) { $escaper = new ZendEscaperBridge(new ZendEscaper()); } $this->injector->alias('Jig\\Escaper', get_class($escaper)); $this->injector->share($escaper); $this->escaper = $escaper; }
public function testNeverCompile() { $jigConfig = new JigConfig($this->templateDirectory, $this->compileDirectory, Jig::COMPILE_NEVER, "php.tpl"); $jig = new Jig($jigConfig); $jig->compile("basic/basic"); }
/** * @param $templateFilename * @return bool */ public function isGeneratedFileOutOfDate($templateFilename) { $templateFullFilename = $this->jigConfig->getTemplatePath($templateFilename); $classPath = Jig::getCompiledFilenameInternal($templateFilename, $this->jigConverter, $this->jigConfig); $classPath = str_replace('\\', '/', $classPath); $templateTime = @filemtime($templateFullFilename); $classTime = @filemtime($classPath); if ($classTime < $templateTime) { return true; } return false; }
function prepareJig(Jig $jigRender, $injector) { $jigRender->addDefaultPlugin('ImagickDemo\\JigPlugin\\ImagickPlugin'); }
<?php use Auryn\Injector; use Jig\JigConfig; use Jig\Jig; // Register some directories in the autoloader - we don't do this in composer.json // to avoid any confusion with users of the library. $autoloader = (require_once realpath(__DIR__) . '/../vendor/autoload.php'); $autoloader->add('JigDemo', [realpath(__DIR__) . '/']); $autoloader->add('Jig', [realpath(__DIR__) . '/compile/']); $injector = new Injector(); // Setting the Jig config $jigConfig = new JigConfig(__DIR__ . "/templates/", __DIR__ . "/compile/", Jig::COMPILE_ALWAYS, "php.tpl"); // Tell the DIC that every class that needs an instance of JigConfig // should use this one. $injector->share($jigConfig); // Alias an interface to a concrete class so that it can be found in // the template. $injector->alias('JigDemo\\Model\\ColorScheme', '\\JigDemo\\Model\\PrimaryColorscheme'); // This is the template we will be compiling. $templateName = 'onePageExample'; // Create the Jig renderer $jig = new Jig($jigConfig); // Tell Jig to make sure the template is compiled. $jig->compile($templateName); // Get the classname that the template will be called $className = $jig->getFQCNFromTemplateName($templateName); // Call the template $contents = $injector->execute([$className, 'render']); echo $contents;
/** * @param Jig $jig * @param $injector */ public static function prepareJig(Jig $jig, $injector) { // This is where default plugins are added. $jig->addDefaultPlugin('GithubExample\\GithubPlugin'); }