php League-Plates-Engine类(方法)实例源码

下面列出了php League-Plates-Engine 类(方法)源码代码实例,从而了解它的用法。

作者:elevenon    项目:spark-project-foundatio   
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]);
 }

作者:Symfoman    项目:laravelcinem   
protected function setUp()
 {
     $plates = new Engine(__DIR__ . '/Resources/views');
     $plates->setFileExtension(null);
     $plates->addData(['foo' => 'bar']);
     $this->engine = new PlatesEngineAdapter($plates);
 }

作者:ezimue    项目:toni   
/**
  * {@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));
     });
 }

作者:hidayat36    项目:phpindonesia.or.id-membership   
/**
  * 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'));
 }

作者:perfume    项目:framewor   
/**
  * 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);
     }
 }

作者:glueph    项目:glue-plate   
/**
  * @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']);
 }

作者:jezqhie    项目:cms-package   
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;
 }

作者:elevenon    项目:sparkl   
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');
 }

作者:nikolapos    项目:devpag   
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));
 }

作者:jmrunkl    项目:ifitfitsifitbit   
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;
 }

作者:oscaroter    项目:static-boilerplat   
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);
 }

作者:jclyons5    项目:page-previe   
/**
  * @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());
 }

作者:oda    项目:psr7-full-stac   
/**
  * 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;
 }

作者:oscaroter    项目:fol   
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;
     };
 }

作者:kl4n    项目:statusboard-widget   
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;
 }

作者:glueph    项目:glue-plate   
public function register(App $glue)
 {
     $glue->singleton('League\\Plates\\Engine', function ($glue) {
         if (!$glue->config->exists('plates.path')) {
             // We need a default template folder
             throw new \Exception("You must configure the plates.path");
         }
         $engine = new Engine($glue->config->get('plates.path'));
         // Register some extensions
         $engine->loadExtension($glue->make('Glue\\Plates\\Extensions\\UrlHelpers'));
         return $engine;
     });
     $glue->alias('League\\Plates\\Engine', 'plates');
 }

作者:philipshar    项目:slim-view-plate   
/**
  * Get a Plates engine
  *
  * @return \League\Plates\Engine
  */
 public function getInstance()
 {
     if (!$this->engineInstance) {
         // Create new Plates engine
         $this->engineInstance = new \League\Plates\Engine($this->templatesPath ?: $this->getTemplatesDirectory());
         if ($this->fileExtension) {
             $this->engineInstance->setFileExtension($this->fileExtension);
         }
         if (count($this->templatesFolders)) {
             foreach ($this->templatesFolders as $name => $path) {
                 $this->engineInstance->addFolder($name, $path);
             }
         }
     }
     return $this->engineInstance;
 }

作者:media3    项目:slim-view-plate   
/**
  * Get an instance of the Plates Engine
  *
  * @return \League\Plates\Engine
  */
 public function getInstance()
 {
     if (!$this->engineInstance) {
         $this->engineInstance = new Engine($this->templatesPath ?: $this->getTemplatesDirectory());
         if ($this->fileExtension) {
             $this->engineInstance->setFileExtension($this->fileExtension);
         }
         if (count($this->templatesFolders) > 0) {
             foreach ($this->templatesFolders as $name => $path) {
                 $this->engineInstance->addFolder($name, $path);
             }
         }
         if (count($this->parserExtensions) > 0) {
             foreach ($this->parserExtensions as $extension) {
                 $this->engineInstance->loadExtension($extension);
             }
         }
     }
     return $this->engineInstance;
 }

作者:narrowspar    项目:framewor   
/**
  * Plates paths loader.
  */
 protected function getLoader() : LeagueEngine
 {
     if (!$this->engine) {
         $config = $this->config;
         $this->engine = new LeagueEngine($config['template']['default'] ?? null, $config['engine']['plates']['file_extension'] ?? null);
         if (($paths = $config['template']['paths'] ?? null) !== null) {
             foreach ($paths as $name => $addPaths) {
                 $this->engine->addFolder($name, $addPaths);
             }
         }
     }
     return $this->engine;
 }

作者:joelouisworthingto    项目:odesandin   
/**
  * Parse name to determine template folder and filename.
  */
 protected function parse()
 {
     $parts = explode('::', $this->name);
     if (count($parts) === 1) {
         if (is_null($this->engine->getDirectory())) {
             $this->throwParseException('The default directory has not been defined.');
         }
         if ($parts[0] === '') {
             $this->throwParseException('The template name cannot be empty.');
         }
         $this->file = $parts[0];
     } elseif (count($parts) === 2) {
         if ($parts[0] === '') {
             $this->throwParseException('The folder name cannot be empty.');
         }
         if ($parts[1] === '') {
             $this->throwParseException('The template name cannot be empty.');
         }
         if (!$this->engine->getFolders()->exists($parts[0])) {
             $this->throwParseException('The folder "' . $parts[0] . '" does not exist.');
         }
         $this->folder = $this->engine->getFolders()->get($parts[0]);
         $this->file = $parts[1];
     } else {
         $this->throwParseException('Do not use the folder namespace seperator "::" more than once.');
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号