本文整理汇总了PHP中League\Plates\Engine类的典型用法代码示例。如果您正苦于以下问题:PHP Engine类的具体用法?PHP Engine怎么用?PHP Engine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Engine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
public function __invoke(array $input)
{
$name = 'index';
if (!empty($input['name'])) {
$name = $input['name'];
}
// $filename = APPPATH . 'templates/static/' . $name;
// if (file_exists($filename)) {
// echo "The file $filename does not exist";
// die('the file does not exist');
// }
// Create new Plates instance
$plates = new Engine(APPPATH . 'templates');
// Register extension
$plates->loadExtension(new Utils());
// Check static page or partial exists
if ($plates->exists('static/' . $name)) {
// Render a template
$template = $plates->render('static/' . $name);
} else {
header("HTTP/1.0 404 Not Found");
echo "PHP continues.\n";
echo "Not after a die, however.\n";
die;
}
// return
return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template]);
}
示例2: setUp
protected function setUp()
{
$plates = new Engine(__DIR__ . '/Resources/views');
$plates->setFileExtension(null);
$plates->addData(['foo' => 'bar']);
$this->engine = new PlatesEngineAdapter($plates);
}
示例3: register
/**
* {@inheritDoc}
*/
public function register()
{
$container = $this->getContainer();
// route map which contains routes for lookup
$container->singleton(Router\RouteMap::class, function () {
return new Router\RouteMap();
});
// handles errors in the life-cycle
$container->singleton(Handler\ErrorInterface::class, function () {
return new Handler\Error();
});
// handles not found errors in the life-cycle
$container->singleton(Handler\NotFoundInterface::class, function () {
return new Handler\NotFound();
});
// plates engine
$container->singleton(Engine::class, function () use($container) {
$engine = new Engine(__DIR__ . '/../view');
$engine->registerFunction('url', new View\Plates\UrlFunction($container->get(Router\RouteMap::class)));
return $engine;
});
// view manager
$container->singleton(View\Manager::class, function () use($container) {
return new View\Manager(new View\PlatesStrategy($container->get(Engine::class)));
});
// router
$container->add(Router\Router::class, function () use($container) {
return new Router\Router($container->get(Router\RouteMap::class));
});
}
示例4: register
/**
* Register extension functions.
* @return null
*/
public function register(Engine $engine)
{
$engine->registerFunction('fh_default_val', array($this, 'fhDefaultVal'));
$engine->registerFunction('fh_input_select', array($this, 'fhInputSelect'));
$engine->registerFunction('fh_error_css_class', array($this, 'fhErrorCssClass'));
$engine->registerFunction('fh_show_errors', array($this, 'fhShowErrors'));
}
示例5: __construct
/**
* PlatesProvider constructor.
* @param Engine $plates
* @param string $root_path
* @param string $namespace
*/
public function __construct(Engine $plates, $root_path, $namespace)
{
$this->plates = $plates;
$this->namespace = $namespace;
if (!$plates->getFolders()->exists($namespace)) {
$plates->addFolder($namespace, $root_path);
}
}
示例6: register
/**
* @param Engine $engine
*/
public function register(Engine $engine)
{
// Load the built in URI extension
$engine->loadExtension(new URI($this->request->getPathInfo()));
// Custom methods
$engine->registerFunction('route', [$this, 'route']);
$engine->registerFunction('asset', [$this, 'asset']);
}
示例7: plates
private function plates()
{
$league = new Plates\Engine(APP . 'views');
$league->setFileExtension('tpl');
$league->loadExtension(new Plates\Extension\URI(trim(strtok(str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['REQUEST_URI']), '?'), '/')));
$league->loadExtension(new MY\Plates\Extension());
return $league;
}
示例8: prepareEngine
public function prepareEngine(Engine $engine)
{
// set file extension
// $engine->setFileExtension('php');
// Add folders
$engine->addFolder('templates', APPPATH . 'templates');
$engine->addFolder('partials', APPPATH . 'templates/partials');
$engine->addFolder('staticpages', APPPATH . 'templates/staticpages');
}
示例9: __invoke
public function __invoke(array $config)
{
$theme = $config['theme'];
$templateEngine = new Engine();
$templateEngine->addFolder('app', 'templates');
$templateEngine->addFolder('theme', 'public/themes/' . $theme . '/templates');
$templateEngine->setFileExtension('phtml');
$templateEngine->loadExtensions([new AssetExt('public', true), new ThemeAssetExt('themes/' . $theme . '/assets')]);
return new Application($config, new PlatesTemplateRenderer($templateEngine));
}
示例10: getInstance
public function getInstance()
{
if (!$this->_engineInstance) {
// Create new Plates engine
$this->_engineInstance = new PlatesEngine($this->getTemplatesDirectory());
if ($this->fileExtension) {
$this->_engineInstance->setFileExtension($this->fileExtension);
}
}
return $this->_engineInstance;
}
示例11: __construct
public function __construct()
{
$this->setUrl(env('APP_URL'));
$this->pipe(Middleware::formatNegotiator());
$this->pipe(Middleware::whoops());
$this->source(new StaticFiles('build/**/*'))->build(false);
$this->source(new StaticFiles('source/img/**/*', '/img/**/*'));
$plates = new Engine('source/templates');
$plates->addData(['app' => $this]);
$this->source(new YamlFiles('source/data/*.yml'))->templates($plates);
}
示例12: render
/**
* @param string $type
* @return string
*/
public function render($type = null)
{
$templates = new Engine($this->viewPath);
if ($type === null) {
if ($this->media === false) {
$type = 'media';
} else {
$type = 'thumbnail';
}
}
return $templates->render($type, $this->toArray());
}
示例13: create
/**
* Create instance
*
* @return Engine
*/
public function create(Request $request)
{
$engine = new Engine($this->options['view_path'], null);
// Add folder shortcut (assets::file.js)
$engine->addFolder('assets', $this->options['assets_path']);
$engine->addFolder('view', $this->options['view_path']);
$session = $request->getAttribute(SessionMiddleware::ATTRIBUTE);
$baseUrl = $request->getAttribute('base_url');
// Register Asset extension
$cacheOptions = array('cachepath' => $this->options['cache_path'], 'cachekey' => $session->get('user.locale'), 'baseurl' => $baseUrl, 'minify' => $this->options['minify']);
$engine->loadExtension(new \Odan\Plates\Extension\AssetCache($cacheOptions));
return $engine;
}
示例14: register
public function register(Fol $app)
{
$app['templates'] = function ($app) {
$root = dirname(dirname(__DIR__));
$templates = new Engine($root . '/templates');
$icons = new Collection(new MaterialDesignIcons($root . '/assets/icons'));
$templates->addData(['app' => $app]);
$templates->registerFunction('icon', function ($name) use($icons) {
return $icons->get($name);
});
return $templates;
};
}
示例15: getTemplates
protected function getTemplates()
{
if (!self::$templates) {
// Create new Plates engine
self::$templates = new Engine(__DIR__ . '/../../views', 'tpl');
self::$templates->registerFunction('substr', function ($string, $start, $length) {
return substr($string, $start, $length);
});
self::$templates->registerFunction('cleanWikiSyntax', function ($string) {
return preg_replace("/\\[(wiki|url)\\=(?P<url>https?:\\/\\/[^\\]]*)\\](?P<text>[^\\[]*)\\[\\/(wiki|url)\\]/i", "\$3", $string);
});
}
return self::$templates;
}