本文整理汇总了PHP中Twig_Loader_Filesystem::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Loader_Filesystem::exists方法的具体用法?PHP Twig_Loader_Filesystem::exists怎么用?PHP Twig_Loader_Filesystem::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Loader_Filesystem
的用法示例。
在下文中一共展示了Twig_Loader_Filesystem::exists方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exists
/**
* Do same stuff than Twig_Loader_Filesystem::exists() plus check if the file is
* readable.
*
* @see Twig_Loader_Filesystem::exists()
*/
public function exists($name)
{
$name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'));
$exists = parent::exists($name);
$readable = false;
if (true === $exists) {
$readable = is_readable($this->cache[$name]);
}
return $readable;
}
示例2: exists
/**
* {@inheritdoc}
*/
public function exists($template)
{
if (parent::exists($template)) {
return true;
}
// same logic as findTemplate below for the fallback
try {
$this->cache[(string) $template] = $this->locator->locate($this->parser->parse($template));
} catch (\Exception $e) {
return false;
}
return true;
}
示例3: getTemplatePathname
/**
* Get a fully qualified path to a given template.
* @param string $file Filename of the template to find in referenced templates directories.
* @param string $namespace Namespace of a specific set of templates directories.
* @return string The full pathname to the template or 'false' if not found.
*/
public function getTemplatePathname($file, $namespace = false)
{
$pathname = false;
if ($this->_loader->exists($file)) {
$paths = StringUtils::emptyOrSpaces($namespace) ? $this->_loader->getPaths() : $this->_loader->getPaths(trim($namespace));
foreach ($paths as $path) {
$tmp_pathname = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($file, DIRECTORY_SEPARATOR);
if (file_exists($tmp_pathname)) {
$pathname = $tmp_pathname;
break;
}
}
}
return $pathname;
}
示例4: testFunctionnal
/**
* Test if the breadcrumb is functionnal.
*
* @cover BreadcrumbExtension::getTemplateName()
* @cover BreadcrumbExtension::breadcrumbRender()
* @cover BreadcrumbExtension::breadcrumbDisplay()
*/
public function testFunctionnal()
{
$service = new BreadcrumbService();
$extension = new BreadcrumbExtension($this->environment, $service);
// Test default
$template = $extension->getTemplateName();
$this->assertEquals('bs_breadcrumb/breadcrumb.html.twig', $template);
$this->assertTrue($this->filesystemLoader->exists($template));
ob_start();
$extension->breadcrumbDisplay();
$display = ob_get_contents();
ob_end_clean();
$html = $extension->breadcrumbRender();
$this->assertTrue(is_string($html));
$this->assertGreaterThan(20, strlen($html));
$this->assertEquals($display, $html);
$dom = new \DOMDocument();
$dom->loadXML($html);
$this->assertTrue($dom->hasChildNodes());
$container = $dom->firstChild;
$this->assertEquals('div', $container->nodeName);
$this->assertEquals('container-fluid', $container->attributes->getNamedItem('class')->nodeValue);
$this->assertEquals(1, $container->childNodes->length);
$row = $container->firstChild;
$this->assertEquals('div', $row->nodeName);
$this->assertEquals('row', $row->attributes->getNamedItem('class')->nodeValue);
$this->assertEquals(1, $row->childNodes->length);
$breadcrumb = $row->firstChild;
$this->assertEquals('ol', $breadcrumb->nodeName);
$this->assertEquals('breadcrumb', $breadcrumb->attributes->getNamedItem('class')->nodeValue);
$this->assertEquals(0, $breadcrumb->childNodes->length);
// Test content
$data_test = array(array('Page 1 ' . uniqid(), '/', 'glyphicon-home'), array('Page 2 ' . uniqid(), 'bootstrap-bundle-test-route', null), array('Page 3 ' . uniqid(), null, null));
foreach ($data_test as $attrs) {
$link = new BreadcrumbLink($attrs[0], $attrs[1], $attrs[2]);
$service->pushLink($link);
}
$html = $extension->breadcrumbRender();
$dom->loadXML($html);
$breadcrumb = $dom->firstChild->firstChild->firstChild;
$this->assertEquals('ol', $breadcrumb->nodeName);
$this->assertEquals('breadcrumb', $breadcrumb->attributes->getNamedItem('class')->nodeValue);
$this->assertEquals(3, $breadcrumb->childNodes->length);
foreach ($breadcrumb->childNodes as $k => $node) {
$this->assertEquals($data_test[$k][0], $node->nodeValue);
}
$this->assertEquals('a', $breadcrumb->childNodes->item(0)->firstChild->nodeName);
$this->assertEquals('a', $breadcrumb->childNodes->item(1)->firstChild->nodeName);
$this->assertEquals('#text', $breadcrumb->childNodes->item(2)->firstChild->nodeName);
$this->assertEquals($data_test[0][1], $breadcrumb->childNodes->item(0)->firstChild->attributes->getNamedItem('href')->nodeValue);
$this->assertEquals($data_test[1][1], $breadcrumb->childNodes->item(1)->firstChild->attributes->getNamedItem('href')->nodeValue);
$this->assertEquals('i', $breadcrumb->childNodes->item(0)->firstChild->firstChild->nodeName);
$this->assertEquals('#text', $breadcrumb->childNodes->item(1)->firstChild->firstChild->nodeName);
$this->assertEquals('glyphicon ' . $data_test[0][2], $breadcrumb->childNodes->item(0)->firstChild->firstChild->attributes->getNamedItem('class')->nodeValue);
// Test with the url generator
$service = new BreadcrumbService($this->urlGenerator);
$extension = new BreadcrumbExtension($this->environment, $service);
foreach ($data_test as $attrs) {
$link = new BreadcrumbLink($attrs[0], $attrs[1], $attrs[2]);
$service->pushLink($link);
}
$html = $extension->breadcrumbRender();
$dom->loadXML($html);
$breadcrumb = $dom->firstChild->firstChild->firstChild;
$this->assertEquals($data_test[0][1], $breadcrumb->childNodes->item(0)->firstChild->attributes->getNamedItem('href')->nodeValue);
$this->assertEquals($this->urlGenerator->generate($data_test[1][1]), $breadcrumb->childNodes->item(1)->firstChild->attributes->getNamedItem('href')->nodeValue);
}
示例5: view
/**
* Modification view opencart
* @param $template
* @param array $data
* @return string
*/
public function view($template, $data = array())
{
//se o twig for desativado
if (!Util::getConfig('enable_twig')) {
return $this->viewRaw($template, $data);
}
\Twig_Autoloader::register();
$paths = [];
//pega o nome do template atual
$current_theme = Util::getConfig('config_template');
//remove theme paths
$view = str_replace(['default/template/', $current_theme . '/template/'], '', $template);
//check vqmod view
$vqmod_template = Vqmod::modCheck(DIR_TEMPLATE . $current_theme . '/' . $view);
if (strpos($vqmod_template, DIR_VQMOD_CACHE) !== false) {
$paths[] = DIR_VQMOD_CACHE;
$view = str_replace(DIR_VQMOD_CACHE, '', $vqmod_template);
} else {
if (Util::getConfig('is_admin')) {
$paths[] = DIR_TEMPLATE;
} else {
//load theme view
if (is_dir(DIR_TEMPLATE . $current_theme . '/template/')) {
$paths[] = DIR_TEMPLATE . $current_theme . '/template/';
}
//load theme default
if (is_dir(DIR_TEMPLATE . Util::getConfig('theme_default') . '/template/')) {
$paths[] = DIR_TEMPLATE . Util::getConfig('theme_default') . '/template/';
}
}
}
//Get all extensions
$extensions = Extension::getAll();
if ($extensions) {
//load extension view
if (Util::getConfig('is_admin')) {
foreach (Util::getConfig('admin_extensions_paths') as $path_extension) {
$extensions_path = glob(DIR_ROOT . '/' . Util::getConfig('extension_path') . '/*/*/' . $path_extension . '/view/template/', GLOB_ONLYDIR);
if ($extensions_path && is_array($extensions_path) && count($extensions_path)) {
$paths = array_merge($paths, $extensions_path);
}
}
} else {
$extensions_path = glob(DIR_ROOT . '/' . Util::getConfig('extension_path') . '/*/*/' . Util::getConfig('theme_path') . '/template/', GLOB_ONLYDIR);
if ($extensions_path && is_array($extensions_path) && count($extensions_path)) {
foreach ($extensions_path as $item) {
if (file_exists($item . $view)) {
$template = $view;
$paths = array_merge($paths, $extensions_path);
}
}
}
}
}
$fileSystem = new \Twig_Loader_Filesystem($paths);
$cache = false;
if (Util::getConfig('twig_cache')) {
$cache = DIR_STORAGE . '/' . Util::getConfig('twig_cache');
}
$twig = new \Twig_Environment($fileSystem, array('autoescape' => Util::getConfig('twig_autoescape'), 'cache' => $cache, 'debug' => Util::getConfig('twig_debug')));
$twig->addExtension(new \Twig_Extension_Debug());
$twig->addExtension(new Ecommerce(Util::getRegistry()));
Util::getRegistry()->set('twig', $twig);
extract($data);
ob_start();
if ($fileSystem->exists(str_replace('.tpl', '', $view) . '.twig', $data)) {
$output = Util::getRegistry()->get('twig')->render(str_replace('.tpl', '', $view) . '.twig', $data);
} else {
if ($fileSystem->exists($view, $data)) {
$output = Util::getRegistry()->get('twig')->render($view, $data);
} else {
trigger_error('Error: Could not load template ' . $template . '!');
exit;
}
}
eval(' ?>' . $output);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
示例6: exists
/**
* {@inheritdoc}
*
* The name parameter might also be a TemplateReferenceInterface.
*/
public function exists($name)
{
return parent::exists((string) $name);
}
示例7: exists
/**
* @param string $name
*
* @return bool
*/
public function exists($name)
{
$name = $this->getName($name);
return parent::exists($name);
}
示例8: exists
public function exists($name)
{
return $this->loader->exists($this->getName($name));
}
示例9: view
public function view($template, $data = array())
{
Twig_Autoloader::register();
$paths = [];
//pega o nome do template atual
$template_name = $this->registry->get('config')->get('config_template');
//fix se ta sentando tema default
if (strpos($template, 'default/template/') !== false) {
$template = str_replace('default/template/', $template_name . '/template/', $template);
}
//check vqmod view
$vqmod_template = VQMod::modCheck(DIR_TEMPLATE . $template);
if (strpos($vqmod_template, DIR_VQMOD_CACHE) !== false) {
$paths[] = DIR_VQMOD_CACHE;
$template = str_replace(DIR_VQMOD_CACHE, '', $vqmod_template);
} else {
//load theme view
if (is_dir(DIR_TEMPLATE . $template_name . '/template')) {
$paths[] = DIR_TEMPLATE . $template_name . '/template';
}
if (is_dir(DIR_TEMPLATE . 'default/template')) {
$paths[] = DIR_TEMPLATE . 'default/template';
}
//load others view
$paths[] = DIR_TEMPLATE;
//load extension view
if (IS_ADMIN) {
$extensions_path = glob(DIR_ROOT . '/extensions/*/app/' . CATALOG_OR_ADMIN . '/view/template/', GLOB_ONLYDIR);
if ($extensions_path && is_array($extensions_path) && count($extensions_path)) {
$paths = array_merge($paths, $extensions_path);
}
} else {
$template_extension = str_replace($template_name . '/template/', '', $template);
$extensions_path = glob(DIR_ROOT . '/extensions/*/theme/template/', GLOB_ONLYDIR);
if ($extensions_path && is_array($extensions_path) && count($extensions_path)) {
foreach ($extensions_path as $item) {
if (file_exists($item . $template_extension)) {
$template = $template_extension;
$paths = array_merge($paths, $extensions_path);
}
}
}
}
}
$fileSystem = new Twig_Loader_Filesystem($paths);
$loader = new Twig_Loader_Chain([$fileSystem]);
$cache = false;
if (defined('TWIG_CACHE')) {
$cache = TWIG_CACHE;
}
$twig = new Twig_Environment($fileSystem, array('autoescape' => false, 'cache' => $cache, 'debug' => true));
$twig->addExtension(new Twig_Extension_Debug());
$twig->addExtension(new \Newcart\System\TwigExtensions\Ecommerce($this->registry));
$this->registry->set('twig', $twig);
extract($data);
ob_start();
// First Step - Render Twig Native Templates
if ($fileSystem->exists(str_replace('.tpl', '', $template) . '.twig', $data)) {
$output = $this->registry->get('twig')->render(str_replace('.tpl', '', $template) . '.twig', $data);
} else {
$output = $this->registry->get('twig')->render($template, $data);
}
// Second Step - IF template has PHP Syntax, then execute
eval(' ?>' . $output);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
示例10: testOutput
/**
* Test is the navbar is functionnal.
*
* @cover NavbarExtension::navbarRender()
* @cover NavbarExtension::navbarDisplay()
*/
public function testOutput()
{
$container = new NavbarService();
$extension = new NavbarExtension($this->environment, $container, $this->configuration);
// Test default
$template = $extension->getTemplateName();
$this->assertEquals('bs_navbar/navbar.html.twig', $template);
$this->assertTrue($this->filesystemLoader->exists($template));
ob_start();
$extension->navbarDisplay();
$display = ob_get_contents();
ob_end_clean();
$html = $extension->navbarRender();
$this->assertTrue(is_string($html));
$this->assertGreaterThan(20, strlen($html));
$this->assertEquals($display, $html);
$dom = new \DOMDocument();
$dom->loadXML($html);
$this->assertTrue($dom->hasChildNodes());
$navbar = $dom->firstChild;
$this->assertEquals('nav', $navbar->nodeName);
$this->assertEquals('navbar navbar-fixed-top', $navbar->attributes->getNamedItem('class')->nodeValue);
$this->assertEquals(1, $navbar->childNodes->length);
$container = $navbar->firstChild;
$this->assertEquals('div', $container->nodeName);
$this->assertEquals('container-fluid', $container->attributes->getNamedItem('class')->nodeValue);
$this->assertEquals(2, $container->childNodes->length);
$header = $container->firstChild;
$this->assertEquals('div', $header->nodeName);
$this->assertEquals('navbar-header', $header->attributes->getNamedItem('class')->nodeValue);
$this->assertEquals(2, $header->childNodes->length);
$collapse = $container->childNodes->item(1);
$this->assertEquals('div', $collapse->nodeName);
$this->assertEquals('collapse navbar-collapse', $collapse->attributes->getNamedItem('class')->nodeValue);
$this->assertEquals('neimheadh-bootstrap-navbar-collapse', $collapse->attributes->getNamedItem('id')->nodeValue);
$this->assertEquals(1, $collapse->childNodes->length);
$menus = $collapse->firstChild;
$this->assertEquals('ul', $menus->nodeName);
$this->assertEquals('nav navbar-nav navbar-right', $menus->attributes->getNamedItem('class')->nodeValue);
$this->assertEquals('neimheadh-bootstrap-nav', $menus->attributes->getNamedItem('id')->nodeValue);
$this->assertEquals(0, $menus->childNodes->length);
$button = $header->firstChild;
$this->assertEquals('button', $button->nodeName);
$this->assertEquals('button', $button->attributes->getNamedItem('type')->nodeValue);
$this->assertEquals('navbar-toggle collapsed', $button->attributes->getNamedItem('class')->nodeValue);
$this->assertEquals('collapse', $button->attributes->getNamedItem('data-toggle')->nodeValue);
$this->assertEquals('#' . $collapse->attributes->getNamedItem('id')->nodeValue, $button->attributes->getNamedItem('data-target')->nodeValue);
$this->assertEquals('false', $button->attributes->getNamedItem('aria-expanded')->nodeValue);
$this->assertEquals(4, $button->childNodes->length);
foreach ($button->childNodes as $i => $node) {
$this->assertEquals('span', $node->nodeName);
$this->assertEquals($i == 0 ? 'sr-only' : 'icon-bar', $node->attributes->getNamedItem('class')->nodeValue);
if ($i == 0) {
$this->assertEquals('Navigation', $node->nodeValue);
}
}
// Test config
$configuration = $this->getConfigurationExample('navbar.config1.yml');
$configuration = $configuration['neimheadh_bootstrap']['navbar'];
$container = new NavbarService();
$extension = new NavbarExtension($this->environment, $container, $configuration);
// The templates will not be good
$error = false;
try {
$extension->navbarRender();
} catch (\Twig_Error_Loader $e) {
$error = true;
}
$this->assertTrue($error);
$configuration['template'] = 'bs_navbar/navbar.html.twig';
$extension->setConfiguration($configuration);
$error = false;
try {
$extension->navbarRender();
} catch (\Twig_Error_Loader $e) {
$error = true;
}
$this->assertTrue($error);
$configuration['header']['template'] = 'bs_navbar/navbar-header.html.twig';
$extension->setConfiguration($configuration);
$error = false;
try {
$extension->navbarRender();
} catch (\Twig_Error_Loader $e) {
$error = true;
}
$this->assertTrue($error);
$configuration['menu']['_list']['template'] = 'bs_navbar/navbar-menu.html.twig';
$extension->setConfiguration($configuration);
$html = $extension->navbarRender();
$dom = new \DOMDocument();
$dom->loadXML($html);
$this->assertTrue($dom->hasChildNodes());
$navbar = $dom->firstChild;
//.........这里部分代码省略.........
示例11: generateStaticPosts
/**
* Generate HTML from source + templates and sitemap.xml into output directory.
*
* @return bool
*/
public function generateStaticPosts()
{
if ($this->sourcePath === null || $this->templatePath === null || $this->outputPath === null) {
throw new \InvalidArgumentException('Check paths');
}
$sourceFiles = array();
foreach (glob($this->sourcePath . '/*.md') as $mdFile) {
$sourceFiles[] = $mdFile;
}
if (count($sourceFiles) === 0) {
throw new \LengthException('No Markdown files found to crunch.');
}
/**
* Source files prefixed with running number => goodness
* '1-first-post.md','2-second-post.md' etc.
*/
natsort($sourceFiles);
$sourceFiles = array_reverse($sourceFiles);
$lastPostKey = false;
$postFilenames = $links = $posts = array();
foreach ($sourceFiles as $key => $mdFile) {
$post = new Post($mdFile);
if ($post->isPublic()) {
$links[] = array('url' => $post->getHtmlFilename(), 'title' => $post->getTitle());
}
if ($lastPostKey === false && $post->isPublic()) {
$lastPostKey = $key;
}
if (array_search($post->getHtmlFilename(), $postFilenames) !== false) {
throw new \LogicException('Titles resulting in identical filenames found "' . $post->getTitle() . '"');
}
$postFilenames[] = $post->getHtmlFilename();
$posts[$key] = $post;
}
foreach (glob($this->outputPath . '/*.html') as $htmlFile) {
unlink($htmlFile);
}
$twigLoader = new \Twig_Loader_Filesystem($this->templatePath);
$twig = new \Twig_Environment($twigLoader);
$siteMapUrls = array();
/* @var $post \Oblog\Post */
foreach ($posts as $key => $post) {
$postHtml = $twig->render('post.html', array('title' => $post->getTitle(), 'modifiedAt' => $post->getModifiedAt(), 'post' => $post->getHtml(), 'filename' => $post->getHtmlFilename()));
$pageVariables = array('article' => $postHtml, 'links' => $links, 'title' => $post->getTitle(), 'baseUrl' => $this->baseUrl, 'filename' => $post->getHtmlFilename());
if ($key == $lastPostKey) {
$pageVariables['canonical'] = $this->baseUrl . '/' . $post->getHtmlFilename();
}
$pageHtml = $twig->render('page.html', $pageVariables);
$outputFilename = $post->getHtmlFilename();
file_put_contents($this->outputPath . '/' . $outputFilename, $pageHtml);
touch($this->outputPath . '/' . $outputFilename, $post->getModifiedAt());
if ($key == $lastPostKey) {
file_put_contents($this->outputPath . '/index.html', $pageHtml);
}
if ($post->isPublic()) {
$siteMapUrls[] = array('loc' => $this->baseUrl . '/' . $outputFilename, 'priority' => 0.5, 'lastmod' => date('Y-m-d', $post->getModifiedAt()), 'title' => $post->getTitle(), 'updated' => date('c', $post->getModifiedAt()));
} else {
echo PHP_EOL . 'DRAFT at ' . $this->baseUrl . '/' . $outputFilename;
}
}
$feedUrls = $siteMapUrls;
if ($lastPostKey !== false) {
$siteMapUrls[] = array('loc' => $this->baseUrl . '/', 'priority' => '1', 'lastmod' => date('Y-m-d', $posts[$lastPostKey]->getModifiedAt()), 'changefreq' => 'daily');
}
if ($twigLoader->exists('sitemap.xml')) {
$sitemapXml = $twig->render('sitemap.xml', array('urls' => $siteMapUrls));
$path = $this->outputPath . '/sitemap.xml';
file_put_contents($path, $sitemapXml);
echo PHP_EOL . "Sitemap generated to " . $path . ' ' . $this->baseUrl . '/' . basename($path);
}
if ($twigLoader->exists('atom.xml')) {
$atomFeed = $twig->render('atom.xml', array('urls' => $feedUrls, 'name' => $this->name, 'author' => $this->author, 'baseUrl' => $this->baseUrl));
$path = $this->outputPath . '/atom.xml';
file_put_contents($path, $atomFeed);
echo PHP_EOL . "Atom feed generated to " . $path . ' ' . $this->baseUrl . '/' . basename($path);
}
if ($twigLoader->exists('rss.xml')) {
$atomFeed = $twig->render('rss.xml', array('urls' => $feedUrls, 'name' => $this->name, 'author' => $this->author, 'baseUrl' => $this->baseUrl, 'description' => $this->description));
$path = $this->outputPath . '/rss.xml';
file_put_contents($path, $atomFeed);
echo PHP_EOL . "RSS feed generated to " . $path . ' ' . $this->baseUrl . '/' . basename($path);
}
return true;
}