本文整理匯總了PHP中type::parse方法的典型用法代碼示例。如果您正苦於以下問題:PHP type::parse方法的具體用法?PHP type::parse怎麽用?PHP type::parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類type
的用法示例。
在下文中一共展示了type::parse方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: findTemplate
/**
* Returns the path to the template file.
*
* The file locator is used to locate the template when the naming convention
* is the symfony one (i.e. the name can be parsed).
* Otherwise the template is located using the locator from the twig library.
*
* @param string|TemplateReferenceInterface $template The template
*
* @throws \Twig_Error_Loader if the template could not be found
*
* @return string The path to the template file
*/
protected function findTemplate($template)
{
$logicalName = (string) $template;
if (isset($this->cache[$logicalName])) {
return $this->cache[$logicalName];
}
$file = null;
$previous = null;
try {
$template = $this->parser->parse($template);
try {
$file = $this->locator->locate($template);
} catch (\InvalidArgumentException $e) {
$previous = $e;
}
} catch (\Exception $e) {
try {
$file = parent::findTemplate($template);
} catch (\Twig_Error_Loader $e) {
$previous = $e;
}
}
if (false === $file || null === $file) {
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $logicalName), -1, null, $previous);
}
return $this->cache[$logicalName] = $file;
}
示例2: supports
/**
* Returns true if this class is able to render the given template.
*
* @param string $name A template name
*
* @return boolean True if this class supports the given resource, false otherwise
*/
public function supports($name)
{
if ($name instanceof \Twig_Template) {
return true;
}
$template = $this->parser->parse($name);
return 'twig' === $template->get('engine');
}
示例3: parseNewsTags
/**
* Parsing the News tags.
*
* @global type $_ARRAYLANG
* @param type $objTpl
* @param type $newsId
*/
public function parseNewsTags($objTpl = null, $newsId = null, $block = 'newsTagList')
{
global $_ARRAYLANG;
if (!empty($newsId)) {
$newsTagDetails = $this->getNewsTags($newsId);
$newsTags = $newsTagDetails['tagList'];
}
$tags = $this->getTags(array_keys($newsTags));
if (empty($tags)) {
if ($objTpl->blockExists('noTags')) {
$objTpl->setVariable('TXT_NEWS_NO_TAGS_FOUND', $_ARRAYLANG['TXT_NEWS_NO_TAGS_FOUND']);
$objTpl->showBlock('noTags');
}
return;
}
$tagCount = count($tags);
$currentTagCount = 0;
if ($objTpl->blockExists($block) && !empty($tags)) {
foreach ($tags as $tag) {
++$currentTagCount;
$newsLink = \Cx\Core\Routing\Url::fromModuleAndCmd('news', '', FRONTEND_LANG_ID, array('tag' => urlencode($tag)));
$objTpl->setVariable(array('NEWS_TAG_NAME' => $tag, 'NEWS_TAG_LINK' => '<a class="tags" href="' . $newsLink . '">' . ucfirst($tag) . '</a>' . ($currentTagCount < $tagCount ? ',' : '')));
$objTpl->parse($block);
}
if ($objTpl->blockExists('tagsBlock')) {
$objTpl->touchBlock('tagsBlock');
}
}
}
示例4: generateChapters
/**
* Generates chapter HTML files.
*/
protected function generateChapters($langCode, $markdown)
{
$this->log("Generating chapters in HTML format for language {$langCode}\n");
$upperAdContent = null;
$lowerAdContent = null;
if ($this->bookProps['google_adsence']['enabled'] == true) {
if (is_readable($this->bookDir . $this->bookProps['google_adsence']['chapter_upper_ad'])) {
$upperAdContent = file_get_contents($this->bookDir . $this->bookProps['google_adsence']['chapter_upper_ad']);
}
if (is_readable($this->bookDir . $this->bookProps['google_adsence']['chapter_bottom_ad'])) {
$lowerAdContent = file_get_contents($this->bookDir . $this->bookProps['google_adsence']['chapter_bottom_ad']);
}
}
$this->markdownParser->parse($markdown);
foreach ($this->markdownParser->warnings as $warning) {
$this->log('Warning: ' . $warning . "\n");
}
$this->warnings = array_merge($this->warnings, $this->markdownParser->warnings);
$linkCurrentChapter = null;
$currentChapterTitle = '';
// Generate an HTML file per chapter
$outFiles = $this->markdownParser->outFiles;
foreach ($outFiles as $idx => $outFile) {
$id = $outFile['id'];
$isSection = strpos($id, '/') != false;
$title = $outFile['title'];
$content = $outFile['content'];
if (!$isSection) {
$linkCurrentChapter = $id;
$currentChapterTitle = $title;
}
$linkPrev = null;
if ($idx > 0) {
$linkPrev = $outFiles[$idx - 1]['id'];
}
$linkNext = null;
if ($idx < count($outFiles) - 1) {
$linkNext = $outFiles[$idx + 1]['id'];
}
$vars = ['content' => $content, 'linkPrev' => $linkPrev, 'linkNext' => $linkNext, 'linkCurrentChapter' => $isSection ? $linkCurrentChapter : null, 'currentChapterTitle' => $currentChapterTitle, 'upperAdContent' => $upperAdContent, 'lowerAdContent' => $lowerAdContent, 'bookProps' => $this->bookProps, 'langCode' => $langCode, 'dirPrefix' => $isSection ? '../../' : '../', 'langDirPrefix' => $isSection ? '../' : ''];
$this->phpRenderer->clearVars();
$content = $this->phpRenderer->render("data/theme/default/layout/chapter.php", $vars);
$html = $this->renderMainLayout($content, $title, $isSection ? '../../' : '../', $langCode);
$outFile = $this->outDir . $langCode . '/' . $id;
$dirName = dirname($outFile);
if (!is_dir($dirName)) {
mkdir($dirName, 0775, true);
}
$this->log("Generating chapter: {$outFile}\n");
file_put_contents($outFile, $html);
$this->siteUrls[] = [$this->bookProps['book_website'] . '/' . $langCode . '/' . $id, 0.5];
}
if ($this->validateLinks) {
// Validate links
$this->log("Validating links\n");
foreach ($this->markdownParser->links as $link) {
$url = $link['url'];
$chapterId = $link['chapter_id'];
$errorMsg = '';
$isValid = $this->linkValidator->validateLink($url, $errorMsg);
if (!$isValid) {
$this->log('Warning:' . $errorMsg . " (in chapter {$chapterId})\n");
$this->warnings[] = $errorMsg . " (in chapter {$chapterId})";
} else {
$this->log($errorMsg);
}
}
}
// Add image files to be copied later
foreach ($this->markdownParser->images as $fileName) {
$srcFilePath = $this->bookDir . 'manuscript/' . $langCode . '/' . $fileName;
$dstFilePath = $this->outDir . $langCode . '/' . $fileName;
$this->filesToCopy[$srcFilePath] = $dstFilePath;
}
}
示例5: link_shortcode_handler
/**
* Modify the content to include subsite links
* @global array $subsiteDomainIDs
* @param array $arguments
* @param string $content
* @param type $parser
* @return string links
*/
public static function link_shortcode_handler($arguments, $content = null, $parser = null)
{
if (!isset($arguments['id'])) {
return;
}
$argumentarray = explode('-', $arguments['id']);
if (count($argumentarray) != 2) {
return;
}
$subsiteid = $argumentarray[0];
$id = $argumentarray[1];
$page = null;
if ($id) {
$page = DataObject::get_by_id('SiteTree', $id);
// Get the current page by ID.
if (!$page) {
$page = Versioned::get_latest_version('SiteTree', $id);
// Attempt link to old version.
}
} else {
$page = DataObject::get_one('ErrorPage', '"ErrorPage"."ErrorCode" = \'404\'');
// Link to 404 page.
}
if (!$page) {
return;
// There were no suitable matches at all.
}
$currentSubsite = Subsite::get()->byID((int) $subsiteid);
$currenturl = null;
if ($currentSubsite) {
if (Director::isDev()) {
$currenturl = $currentSubsite->DevDomainID ? $currentSubsite->DevDomain() : null;
}
if (Director::isTest()) {
$currenturl = $currentSubsite->TestDomainID ? $currentSubsite->TestDomain() : null;
}
if (!$currenturl) {
$currenturl = $currentSubsite->getPrimarySubsiteDomain();
}
$currenturl = $currenturl->getFullProtocol() . $currenturl->Domain;
// override
if (Director::isDev() || Director::isTest()) {
if (defined('DEV_SUBSITE_' . (int) $subsiteid)) {
$subsiteurl = 'DEV_SUBSITE_' . (int) $subsiteid;
$currenturl = constant($subsiteurl);
}
}
}
$link = Convert::raw2att($page->Link());
if ($content) {
return sprintf('<a href="%s">%s</a>', $currenturl . $link, $parser->parse($content));
} else {
return $currenturl . $link;
}
}