本文整理汇总了PHP中Twig_Loader_Filesystem::addPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Loader_Filesystem::addPath方法的具体用法?PHP Twig_Loader_Filesystem::addPath怎么用?PHP Twig_Loader_Filesystem::addPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Loader_Filesystem
的用法示例。
在下文中一共展示了Twig_Loader_Filesystem::addPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
$view_dir = [__DIR__ . '/../Views', __DIR__ . '/../Templates'];
$twigConfig = [];
if ($this->config['twig']['cache']) {
$twigConfig["cache"] = $this->app['cache']['twig'];
}
$twigConfig["debug"] = $this->config['twig']['debug'];
$loader = new \Twig_Loader_Filesystem($view_dir);
foreach ($view_dir as $d) {
$loader->addPath($d, 'Meister');
}
foreach ($this->config['modules'] as $app) {
if (file_exists($this->app['Modules'] . $app . '/Views')) {
$loader->addPath($this->app['Modules'] . $app . '/Views', $app);
}
if (file_exists($this->app['Modules'] . $app . '/Templates')) {
$loader->addPath($this->app['Modules'] . $app . '/Templates', $app);
}
}
$this->twig = new \Twig_Environment($loader, $twigConfig);
$this->twig->addExtension(new \Twig_Extensions_Extension_I18n());
/**
* Verifica permissões para exibir determinada coisa
*/
$function = new \Twig_SimpleFunction('permission', function ($rule) {
return $this->app['auth']->checkRules($rule);
});
$this->twig->addFunction($function);
}
示例2: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('<comment>Iniciando busca de templates</comment>');
/**
* @var $app \app\AppInit
*/
$app = $this->getHelper('init')->getInit();
$cache = $app->getCache();
$src = $app->getBaseDir() . "/src";
$loader = new \Twig_Loader_Filesystem($src);
$twig = new \Twig_Environment($loader, array('cache' => $cache['twig'], 'auto_reload' => true));
$config = $app->config();
$container = $app->container();
foreach ($config['modules'] as $ap) {
if (file_exists($container['Modules'] . $ap . '/Views')) {
$loader->addPath($container['Modules'] . $ap . '/Views', $ap);
}
if (file_exists($container['Modules'] . $ap . '/Templates')) {
$loader->addPath($container['Modules'] . $ap . '/Templates', $ap);
}
}
$twig->addExtension(new \Twig_Extensions_Extension_I18n());
$d = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($src), \RecursiveIteratorIterator::LEAVES_ONLY);
$Regex2 = new \RegexIterator($d, '/\\.html.twig$/i');
foreach ($Regex2 as $file) {
if ($file->isFile()) {
$twig->loadTemplate(str_replace($src . '/', '', $file));
}
}
#$output->writeln("<comment>Finalizando</comment>");
}
示例3: paths
public static function paths()
{
$loader = new Twig_Loader_Filesystem(TEMPLATES);
$loader->addPath(TEMPLATES . "module/user/", 'ModuleUser');
$loader->addPath(TEMPLATES . "module/login/", 'ModuleLogin');
$loader->addPath(TEMPLATES . "modales/", 'Modal');
return $loader;
}
示例4: createLoader
private function createLoader($templatePath)
{
$loader = new \Twig_Loader_Filesystem($templatePath);
$loader->addPath($_SERVER["DOCUMENT_ROOT"] . SITE_TEMPLATE_PATH . "/", "templateRoot");
$loader->addPath($_SERVER["DOCUMENT_ROOT"] . SITE_TEMPLATE_PATH . "/template/", "template");
$loader->addPath($_SERVER["DOCUMENT_ROOT"] . SITE_TEMPLATE_PATH . "/components/", "templateComponents");
return $loader;
}
示例5: createLoader
private function createLoader($templatePath)
{
$loader = new \Twig_Loader_Filesystem($templatePath);
$loader->addPath($templatePath . "/", "root");
$loader->addPath($templatePath . "/components", "components");
$loader->addPath($templatePath . "/template", "template");
return $loader;
}
示例6: addDir
/**
* add a directory to template search dirs
* @param string $directory
* @param bool|true $primary
* @return ITemplateEngine|void
*/
public function addDir($directory, $primary = true)
{
if ($primary) {
$this->twigLoader->prependPath($directory);
} else {
$this->twigLoader->addPath($directory);
}
$this->twigEnv->setLoader($this->twigLoader);
return $this;
}
示例7: __construct
public function __construct(Twig_Loader_Filesystem $loader, $path, $namespace = self::STORE_NAMESPACE)
{
$this->loader = $loader;
$this->path = str_replace('\\', '/', rtrim($path, '/\\') . '/');
$path = rtrim($this->path, '/\\');
if (!file_exists($path)) {
mkdir($path, 0777, true);
chmod($path, 0777);
// just for sure
}
$this->loader->addPath($this->path, $namespace);
}
示例8: testLoadTemplateAndRenderBlockWithCache
public function testLoadTemplateAndRenderBlockWithCache()
{
$loader = new Twig_Loader_Filesystem(array());
$loader->addPath(dirname(__FILE__) . '/Fixtures/themes/theme2');
$loader->addPath(dirname(__FILE__) . '/Fixtures/themes/theme1');
$loader->addPath(dirname(__FILE__) . '/Fixtures/themes/theme1', 'default_theme');
$twig = new Twig_Environment($loader);
$template = $twig->loadTemplate('blocks.html.twig');
$this->assertSame('block from theme 1', $template->renderBlock('b1', array()));
$template = $twig->loadTemplate('blocks.html.twig');
$this->assertSame('block from theme 2', $template->renderBlock('b2', array()));
}
示例9: getLoader
static function getLoader($request)
{
$loader = new \Twig_Loader_Filesystem();
$project = Project::getCurrent();
foreach ($project->getSetting('TEMPLATE_DIRS', []) as $dir) {
$dir = realpath($dir);
if (is_dir($dir)) {
$loader->addPath($dir);
}
}
$loader->addPath(dirname(__DIR__) . '/BuiltIn/');
return $loader;
}
示例10: initExtension
public function initExtension($extension, \Twig_Environment $render, \Twig_Loader_Filesystem $fileSystemLoader)
{
if (false === strpos($extension, "\\")) {
$extension = "\\" . $extension;
}
$config = $this->getConfig();
switch ($extension) {
case "\\TranslationExtension":
$config = isset($config["translationExtension"]) ? $config["translationExtension"] : [];
$lang = isset($config["lang"]) ? $config["lang"] : "ru";
$locale = isset($config["locale"]) ? $config["locale"] : "ru_RU";
$translator = new \Symfony\Component\Translation\Translator($locale);
$translator->addLoader('xlf', new \Symfony\Component\Translation\Loader\XliffFileLoader());
$vendorFormDir = VENDOR_DIR . '/symfony/form/Symfony/Component/Form';
$vendorValidatorDir = VENDOR_DIR . '/symfony/validator/Symfony/Component/Validator';
$translator->addResource('xlf', $vendorFormDir . "/Resources/translations/validators.{$lang}.xlf", $locale, 'validators');
$translator->addResource('xlf', $vendorValidatorDir . "/Resources/translations/validators.{$lang}.xlf", $locale, 'validators');
$extension = new \Symfony\Bridge\Twig\Extension\TranslationExtension($translator);
break;
case "\\FormExtension":
$config = isset($config["formExtension"]) ? $config["formExtension"] : [];
$templates = $config["templates"] ?: "/vendor/symfony/twig-bridge/Resources/views/Form";
$templates = $this->getRootDir() . "/" . $templates;
$fileSystemLoader->addPath($templates);
$formTemplate = $config["formTheme"] ?: "form_div_layout.html.twig";
$formTemplate = (array) $formTemplate;
$formEngine = new \Symfony\Bridge\Twig\Form\TwigRendererEngine($formTemplate);
$formEngine->setEnvironment($render);
$extension = new \Symfony\Bridge\Twig\Extension\FormExtension(new \Symfony\Bridge\Twig\Form\TwigRenderer($formEngine, $this->getFormCsrfProvider()));
break;
default:
$extension = new $extension();
}
return $extension;
}
示例11: getTwig
protected function getTwig()
{
$options = ['cache' => false, 'strict_variables' => true];
$loader = new \Twig_Loader_Filesystem();
$loader->addPath($this->skeletonDirs);
return new \Twig_Environment($loader, $options);
}
示例12: __construct
/**
* Response constructor.
* @param $view
* @param array $param
*/
public function __construct($view, $param = [])
{
$loader = new \Twig_Loader_Filesystem(SRC_ROUTE . "/Views");
$loader->addPath(SRC_ROUTE . "/", "");
$this->_twig = new \Twig_Environment($loader, ["charset" => "utf-8", "debug" => true]);
echo $this->_twig->render($view, $param);
}
示例13: testGetNamespaces
public function testGetNamespaces()
{
$loader = new Twig_Loader_Filesystem(sys_get_temp_dir());
$this->assertEquals(array(Twig_Loader_Filesystem::MAIN_NAMESPACE), $loader->getNamespaces());
$loader->addPath(sys_get_temp_dir(), 'named');
$this->assertEquals(array(Twig_Loader_Filesystem::MAIN_NAMESPACE, 'named'), $loader->getNamespaces());
}
示例14: render
public function render($echo = false)
{
// Load template directories.
$loader = new \Twig_Loader_Filesystem();
$loader->addPath('templates');
// Set up Twig.
$twig = new \Twig_Environment($loader, array('debug' => true, 'strct_variables' => true));
$twig->addExtension(new \Twig_Extension_Debug());
// Mardown support.
$twig->addFilter(new \Twig_SimpleFilter('markdown', function ($text) {
$parsedown = new \Parsedown();
return $parsedown->text($text);
}));
// DB queries.
$twig->addFunction(new \Twig_SimpleFunction('db_queries', function () {
return Db::getQueries();
}));
// Render.
$string = $twig->render($this->template, $this->data);
if ($echo) {
echo $string;
} else {
return $string;
}
}
示例15: getEnvironment
public static function getEnvironment()
{
if (!self::$environment) {
$applicationReflector = new \ReflectionClass(Application::getInstance());
$loader = new \Twig_Loader_Filesystem();
self::$environment = new Twig_Environment($loader);
// ppFramework built-in views
$loader->addPath(__DIR__ . DIRECTORY_SEPARATOR . "View", "ppFramework");
// Application view namespace
$path = dirname($applicationReflector->getFileName()) . DIRECTORY_SEPARATOR . $applicationReflector->getShortName() . DIRECTORY_SEPARATOR . "View";
if (is_dir($path)) {
$loader->addPath($path, $applicationReflector->getShortName());
}
}
return self::$environment;
}