本文整理汇总了PHP中Parser类的典型用法代码示例。如果您正苦于以下问题:PHP Parser类的具体用法?PHP Parser怎么用?PHP Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sbParserInit
function sbParserInit(Parser $parser)
{
// Register <scratchblocks> tag
$parser->setHook('scratchblocks', 'sbRenderTag');
$parser->setHook('sb', 'sbRenderInlineTag');
return true;
}
示例2: testWrapper
/**
* @dataProvider mwParserWrapperDataProvider
*
* @param $wikitext
* @param $params
*/
public function testWrapper($wikitext, $params, $newline)
{
$frame = $this->parser->getPreprocessor()->newCustomFrame($params);
$wrapper = new \Wikia\PortableInfobox\Parser\MediaWikiParserService($this->parser, $frame);
$output = $wrapper->parseRecursive($wikitext);
$this->assertEquals($this->parse($wikitext, $params, $newline), $output);
}
示例3: set_from_parser
/**
* Sets node attributes based on the parser's current position.
*/
public function set_from_parser(Parser $parser)
{
$this->parser = $parser;
$this->line_number = $parser->line_number();
$this->indent_level = $parser->indent_level();
$this->content = $parser->content();
}
示例4: getMessagesFormatted
function getMessagesFormatted($severity = self::MESSAGE_WARNING, $header = null)
{
global $wgTitle, $wgUser;
$ret = '';
foreach ($this->mMessages as $message) {
if ($message[1] <= $severity) {
$ret .= '* ' . $message[0] . "\n";
}
}
if ($ret != '') {
if (!$this->mParser) {
$parser = new Parser();
}
if ($header == null) {
$header = '';
} elseif ($header != '') {
$header = Html::rawElement('div', array('class' => 'heading'), $header);
}
$ret = Html::rawElement('div', array('class' => 'messages'), $header . "\n" . $ret);
$ret = $parser->parse($ret, $wgTitle, ParserOptions::newFromUser($wgUser));
} else {
$ret = null;
}
return $ret;
}
示例5: renderGallery
/**
* Parser hook handler for {{#articletype}}
*
* @param Parser $parser : Parser instance available to render
* wikitext into html, or parser methods.
*
* @return string: HTML to insert in the page.
*/
public static function renderGallery($input, array $args, Parser $parser, PPFrame $frame)
{
$parser->getOutput()->addModules('ext.promoter.gallery');
$pageName = $parser->getTitle()->getText();
try {
$renderedAds = array();
$adChooser = new AdChooser($pageName, !$parser->getUser()->isLoggedIn());
$ads = $adChooser->getAds();
foreach ($ads as $ad) {
$renderedAds[] = Ad::fromName($ad['name'])->renderHtml();
}
} catch (AdCampaignExistenceException $e) {
wfDebugLog('Promoter', $e->getMessage());
//@todo i18n
return '<span class="error">No campaign for this page</span>';
} catch (MWException $e) {
wfDebugLog('Promoter', $e->getMessage());
return '<span class="error text-danger">An error occurred [' . $e->getMessage() . ']</span>';
}
$html = '<div class="promotion-gallery hidden hidden-print">' . '<h5 class="sr-only">זוהי גלריה המקדמת ערכים שונים באתר.</h5>' . '<div class="gallery-controls">' . '<span class="sr-only">בכל רגע מוצגות 3 ידיעות בגלריה. ניתן להציג ידיעה נוספת או לחזור לאחור באמצעות הכפתורים הבאים, או באמצעות מקשי החיצים כאשר הפוקוס הוא על הגלריה</span>' . '<a href="#" class="owl-prev"><span class="fa fa-chevron-right fa-lg" title="הקודם"></span><span class="sr-only">הצגת הידיעה הקודמת</span></a>' . '<a href="#" class="owl-next"><span class="fa fa-chevron-left fa-lg" title="הבא"></span><span class="sr-only">הצגת הידיעה הבאה</span></a>' . '</div>';
if ($args['title']) {
$html .= '<div class="header">' . $args['title'] . '</div>';
}
$html .= '<div class="owl-carousel clearfix" tabindex="0">' . implode('', $renderedAds) . '</div>' . '</div>';
return $html;
}
示例6: setUp
function setUp()
{
parent::setUp();
$parser = new Parser();
$options = new ParserOptions();
$options->setTemplateCallback(array($this, 'templateCallback'));
$parser->startExternalParse(Title::newMainPage(), $options, Parser::OT_HTML, true);
try {
$engine = new Scribunto_LuaSandboxEngine(array('parser' => $parser) + $this->sandboxOpts);
$engine->setTitle($parser->getTitle());
$engine->getInterpreter();
$this->engines['LuaSandbox'] = $engine;
} catch (Scribunto_LuaInterpreterNotFoundError $e) {
$this->markTestSkipped("LuaSandbox interpreter not available");
return;
}
try {
$engine = new Scribunto_LuaStandaloneEngine(array('parser' => $parser) + $this->standaloneOpts);
$engine->setTitle($parser->getTitle());
$engine->getInterpreter();
$this->engines['LuaStandalone'] = $engine;
} catch (Scribunto_LuaInterpreterNotFoundError $e) {
$this->markTestSkipped("LuaStandalone interpreter not available");
return;
}
}
示例7: getInfo
/**
* Get the package information
*
* @return Info
*/
public function getInfo()
{
exec("rpm -qi {$this->packageName}", $rawInfo);
$rawInfo = implode("\n", $rawInfo);
$parser = new Parser();
return $parser->parse($rawInfo);
}
示例8: run
private function run($name, $options, $contents)
{
require_once CORE_DIR . 'parser.php';
$parser = new Parser();
$data = html_entity_decode($parser->parse($contents, $options));
return file_put_contents(strtolower($name) . '.php', $data) ? true : false;
}
示例9: doTestPrettyPrintMethod
protected function doTestPrettyPrintMethod($method, $name, $code, $dump)
{
$parser = new Parser(new Lexer\Emulative());
$prettyPrinter = new PrettyPrinter\Standard();
$stmts = $parser->parse($code);
$this->assertEquals($this->canonicalize($dump), $this->canonicalize($prettyPrinter->{$method}($stmts)), $name);
}
示例10: domainWithTld
/**
* Validate a domain with a Tld.
*
* @access public
* @static
* @param string $domain
* @return boolean
*/
public static function domainWithTld($domain)
{
$domainParser = new Parser($domain);
$tld = $domainParser->getTld();
$domainWithoutTld = $domainParser->getDomainWithoutTld();
return self::domainWithoutTld($domainWithoutTld) && $tld && filter_var('http://' . $domain, FILTER_VALIDATE_URL);
}
示例11: renderCollection
public static function renderCollection($input, array $args, Parser $parser, PPFrame $frame)
{
$string_array = array();
$parsed_input = $parser->recursiveTagParse($input, $frame);
if (Collection::startsWith($parsed_input, "Coll") === true) {
$results = Collection::getResults($parsed_input);
$string_array[] = '{| class="wikitable"';
$string_array[] = "! ";
foreach ($results['langs'] as $lang) {
$string_array[] = "!" . $lang;
}
$string_array[] = "|-";
foreach (array_keys($results['data']) as $pagename) {
$string_array[] = "|[[" . $pagename . " |Edit]]";
foreach ($results['langs'] as $lang) {
if (isset($results['data'][$pagename][$lang])) {
$string_array[] = "|" . implode("<br/>", $results['data'][$pagename][$lang]);
} else {
$string_array[] = "|";
}
}
$string_array[] = "|-";
}
$string_array[] = "|}";
return $parser->recursiveTagParse(implode("\n\n", $string_array), $frame);
} else {
return $parser->recursiveTagParse("No results", $frame);
}
}
示例12: renderTagPage
/**
* Hook: ParserBeforeStrip
* @param $parser Parser
* @param $text
* @param $state
* @return bool
*/
public static function renderTagPage($parser, &$text, $state)
{
$title = $parser->getTitle();
if (strpos($text, '<translate>') !== false) {
try {
$parse = TranslatablePage::newFromText($parser->getTitle(), $text)->getParse();
$text = $parse->getTranslationPageText(null);
} catch (TPException $e) {
// Show ugly preview without processed <translate> tags
}
}
// Set display title
$page = TranslatablePage::isTranslationPage($title);
if (!$page) {
return true;
}
list(, $code) = TranslateUtils::figureMessage($title->getText());
$name = $page->getPageDisplayTitle($code);
if ($name) {
// BC for MW < 1.19
if (is_callable(array($parser, 'recursivePreprocess'))) {
$name = $parser->recursivePreprocess($name);
} else {
$newParser = new Parser();
$name = $newParser->preprocess($name, $parser->getTitle(), $parser->getOptions());
}
$name = $parser->recursivePreprocess($name);
$parser->getOutput()->setDisplayTitle($name);
}
return true;
}
示例13: testCreate
/**
* @covers Geissler\Converter\Standard\RIS\Creator::create
* @covers Geissler\Converter\Standard\RIS\Creator::getPerson
* @covers Geissler\Converter\Standard\RIS\Creator::getDate
* @covers Geissler\Converter\Standard\RIS\Creator::getType
* @covers Geissler\Converter\Standard\RIS\Creator::retrieve
* @dataProvider dataProviderCreate
*/
public function testCreate($input, $output)
{
$parser = new Parser();
$this->assertTrue($parser->parse($input));
$this->assertTrue($this->object->create($parser->retrieve()));
$this->assertEquals($output, $this->object->retrieve());
}
示例14: build
public function build()
{
$article = $this->Agent->getArticle();
$text = $article->getContent(true);
# Strip comments and <nowiki>
$text = preg_replace("/<!--.*?-->/s", "", $text);
$text = preg_replace("@<nowiki>.*?</nowiki>@s", "", $text);
# change template usage to substitution; note that this is WRONG
#$tchars = Title::legalChars();
#$text = preg_replace("/(?<!{){{([$tchars]+)(\|.*?)?}}(?!})/", "{{subst:$1$2}}", $text);
$parser = new Parser();
# so the magic variables work out right
$parser->mOptions = new ParserOptions();
$parser->mTitle = $this->Agent->getTitle();
$parser->mOutputType = OT_WIKI;
$parser->initialiseVariables();
$parser->clearState();
$text = $parser->replaceVariables($text);
preg_match_all("@<rdf>(.*?)</rdf>@s", $text, $matches, PREG_PATTERN_ORDER);
$content = $matches[1];
$rdf = implode(' ', array_values($content));
$model = MwRdf::Model();
if (strlen($rdf) > 0) {
$parser->mOutputType = OT_HTML;
$rdf = $parser->replaceVariables($rdf);
$turtle_parser = MwRdf::Parser('turtle');
$base_uri = $this->Agent->getTitle()->getFullUrl();
$prelude = MwRdf::getNamespacePrelude();
$model->loadStatementsFromString($turtle_parser, $prelude . $rdf);
}
return $model;
}
示例15: imageLink
/**
* Outputs the internal image wrapped in a link
* @param Parser $parser Instance of running Parser.
* @param String $image Name of image to display.
* @param String $url External URL to which to link
* @param String $alt Alternate text for image and link (optional)
* @return String A parser strip flag which will be later replaced with raw html.
*/
function imageLink($parser, $image = null, $url = null, $alt = '')
{
# Short-circuit if requried params are missing
if ($image === null || $url === null) {
return $this->error('missing-params');
}
# Prepare incomming params
$image = trim($image);
$url = trim($url);
$alt = trim($alt);
# Check for bad URLs
if (!preg_match('/^(' . wfUrlProtocols() . ')/', $url) || preg_match('/\'"/', $url)) {
$t = Title::newFromText($url);
if (!$t) {
return $this->error('bad-url', $url);
}
$url = $t->getFullURL();
}
# Check to see that the selected image exists
$imageObj = Image::newFromName($image);
if (!$imageObj->exists()) {
return $this->error('no-such-image', $image);
}
# Finally, since all checks passed, display it!
return $parser->insertStripItem($this->msg('embed-clause', htmlentities($url, ENT_COMPAT), $imageObj->getURL(), htmlentities($alt, ENT_COMPAT)), $parser->mStripState);
}