本文整理汇总了PHP中Parser::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::parse方法的具体用法?PHP Parser::parse怎么用?PHP Parser::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Renders the view
*
* @param array $data additional view data
*
* @return string
*/
public function render(array $data = [])
{
if (!empty($data)) {
$this->set($data);
}
return $this->parser->parse($this->file, $this->getData());
}
示例2: compile
/**
* Compile some CoffeeScript.
*
* Available options:
*
* 'filename' => The source file, for debugging (formatted into error messages)
* 'header' => Add a header to the generated source (default: TRUE)
* 'rewrite' => Enable rewriting token stream (debugging)
* 'tokens' => Reference to token stream (debugging)
* 'trace' => File to write parser trace to (debugging)
*
* @param string The source CoffeeScript code
* @param array Options (see above)
*
* @return string The resulting JavaScript (if there were no errors)
*/
static function compile($code, $options = array())
{
$lexer = new Lexer($code, $options);
if (isset($options['filename'])) {
Parser::$FILE = $options['filename'];
}
if (isset($options['tokens'])) {
$tokens =& $options['tokens'];
}
if (isset($options['trace'])) {
Parser::Trace(fopen($options['trace'], 'w', TRUE), '> ');
}
try {
$parser = new Parser();
foreach ($tokens = $lexer->tokenize() as $token) {
$parser->parse($token);
}
$js = $parser->parse(NULL)->compile($options);
} catch (\Exception $e) {
throw new Error("In {$options['filename']}, " . $e->getMessage());
}
if (!isset($options['header']) || $options['header']) {
$js = '// Generated by CoffeeScript PHP ' . VERSION . "\n" . $js;
}
return $js;
}
示例3: testParse
public function testParse()
{
$parser = new Parser();
$this->assertEquals('(0-1)*(1+2)', $parser->parse(' - ( 1 + 2 ) '));
$this->assertEquals('(0-1)*(1+2)', $parser->parse('-(1+2)'));
$this->assertEquals('(0-3)*(1+2)', $parser->parse('-3*(1+2)'));
$this->assertEquals('2*(0-3)*(1+2)', $parser->parse('2*(-3)*(1+2)'));
$this->assertEquals('2*(0-3)*(1+2)*(0-1)', $parser->parse('2*(-3)*(1+2)*(-1)'));
}
示例4: itShouldAnalyseAllFiles
/**
* @test
*/
public function itShouldAnalyseAllFiles()
{
$files = [fixture('MyClass.php')];
$nodes = [$this->node];
$parseRes = $this->parser->parse(Argument::type('string'));
$this->parser->parse(Argument::type('string'))->shouldBeCalled()->willReturn($nodes);
$this->nodeTraverser->traverse($nodes)->shouldBeCalled();
$this->analyser->analyse($files);
}
示例5: isValid
/**
* Tells whether a rule is valid (as in "can be parsed without error") or not.
*
* @return bool
*/
public function isValid()
{
try {
$this->parsedRule = $this->parser->parse($this->rule);
} catch (\Exception $e) {
$this->error = $e->getMessage();
return \false;
}
return \true;
}
示例6: testParse
/**
* @covers BehEh\Sulphur\Parser::parse
*/
public function testParse()
{
$response = $this->parser->parse(file_get_contents(__DIR__ . '/../data/reference.ini'));
$references = $response->all();
$reference = $references[0];
$this->assertEquals(12, $reference->Icon);
$this->assertEquals('Minor Melee', $reference->Title);
$this->assertEquals(true, $reference->IsNetworkGame);
$this->assertEquals(123456, $reference->GameId);
$this->assertNull($reference->Type);
}
示例7: testParseMultpileAgentStrings
public function testParseMultpileAgentStrings()
{
$handle = fopen(dirname(__DIR__) . "/fixtures/agents.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$result = $this->parser->parse($line);
}
fclose($handle);
} else {
// error opening the file.
}
}
示例8: parse
/**
* @param string $version
* @return Version
*/
function parse($version)
{
if (array_key_exists($version, $this->cache)) {
$obj = $this->cache[$version];
unset($this->cache[$version]);
$this->cache[$version] = $obj;
} else {
if (count($this->cache) == $this->limit) {
array_shift($this->cache);
}
$this->cache[$version] = $obj = $this->inner->parse($version);
}
return $obj;
}
示例9: WidgetTips
function WidgetTips($id, $params)
{
global $wgParser;
wfProfileIn(__METHOD__);
$user = RequestContext::getMain()->getUser();
$title = RequestContext::getMain()->getTitle();
$request = RequestContext::getMain()->getRequest();
if (isset($params['_widgetTag'])) {
// work-around for WidgetTag
$parser = new Parser();
} else {
$parser =& $wgParser;
}
$parser->mOptions = new ParserOptions($user);
$tips = WidgetTipsGetTips();
if ($tips == false) {
wfProfileOut(__METHOD__);
return $parser->parse('No tips found in [[Mediawiki:Tips]]! Contact your Wiki admin', $title, $parser->mOptions)->getText();
}
$tipsCount = count($tips);
// check requested operation
$op = $request->getVal('op') != '' ? $request->getVal('op') : 'rand';
$tipId = $request->getInt('tipId');
switch ($op) {
case 'prev':
$tipId--;
if ($tipId < 0) {
$tipId = $tipsCount - 1;
}
break;
case 'next':
$tipId++;
if ($tipId >= $tipsCount) {
$tipId = 0;
}
break;
default:
$tipId = array_rand($tips);
}
$id = intval(substr($id, 7));
// prev/next tip selector
if (!isset($params['_widgetTag'])) {
$selector = '<div class="WidgetTipsSelector">' . '<a onclick="WidgetTipsChange(' . $id . ', ' . $tipId . ', \'prev\')">« ' . wfMsg('allpagesprev') . '</a> ' . '<a onclick="WidgetTipsChange(' . $id . ', ' . $tipId . ', \'next\')">' . wfMsg('allpagesnext') . ' »</a></div>';
} else {
// fix RT #26752
$selector = '';
}
wfProfileOut(__METHOD__);
return $selector . $parser->parse($tips[$tipId], $title, $parser->mOptions)->getText();
}
示例10: compile
/**
* Compile some CoffeeScript.
*
* @param $code The source CoffeeScript code.
* @param $options Compiler options.
*/
function compile($code, $options = array(), &$tokens = NULL)
{
$lexer = new Lexer($code, $options);
if (isset($options['file'])) {
Parser::$FILE = $options['file'];
}
if (isset($options['trace'])) {
Parser::Trace(fopen($options['trace'], 'w', TRUE), '> ');
}
$parser = new Parser();
foreach ($tokens = $lexer->tokenize() as $token) {
$parser->parse($token);
}
return $parser->parse(NULL)->compile($options);
}
示例11: 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;
}
示例12: query
public function query($q)
{
$parser = new Parser($this->user, $q);
$error = $parser->parse();
if ($error) {
return $parser->getError();
}
$mysql_query = $parser->getSql();
$meta = $parser->getObjectMetaData();
$this->pearDB->startTransaction();
$result = $this->pearDB->pquery($mysql_query, array());
$error = $this->pearDB->hasFailedTransaction();
$this->pearDB->completeTransaction();
if ($error) {
throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
}
$noofrows = $this->pearDB->num_rows($result);
$output = array();
for ($i = 0; $i < $noofrows; $i++) {
$row = $this->pearDB->fetchByAssoc($result, $i);
if (!$meta->hasPermission(EntityMeta::$RETRIEVE, $row["crmid"])) {
continue;
}
$output[] = DataTransform::sanitizeDataWithColumn($row, $meta);
}
return $output;
}
示例13: testCreate
/**
* @covers Geissler\Converter\Standard\CSL\Creator::create
* @covers Geissler\Converter\Standard\CSL\Creator::getType
* @covers Geissler\Converter\Standard\CSL\Creator::createPerson
* @covers Geissler\Converter\Standard\CSL\Creator::createDate
* @covers Geissler\Converter\Standard\CSL\Creator::retrieve
* @dataProvider dataProviderForCreate
*/
public function testCreate($input, $titles, $types, $authors = false, $issued = false, $issuedFull = false)
{
$parser = new Parser();
$this->assertTrue($parser->parse($input));
$this->assertTrue($this->object->create($parser->retrieve()));
$csl = json_decode($this->object->retrieve(), true);
$count = 0;
foreach ($csl as $entry) {
$this->assertEquals($titles[$count], $entry['title']);
$this->assertEquals($types[$count], $entry['type']);
if ($authors !== false) {
$countAuthors = count($authors[$count]);
for ($i = 0; $i < $countAuthors; $i++) {
$this->assertEquals($authors[$count][$i]['family'], $entry['author'][$i]['family']);
$this->assertEquals($authors[$count][$i]['given'], $entry['author'][$i]['given']);
}
}
if ($issued !== false && isset($issued[$count]) == true) {
$this->assertEquals($issued[$count]['year'], $entry['issued'][0]['year']);
$this->assertArrayNotHasKey('day', $entry['issued'][0]);
$this->assertArrayNotHasKey('month', $entry['issued'][0]);
}
if ($issuedFull !== false && isset($issuedFull[$count]) == true) {
$this->assertEquals($issuedFull[$count]['year'], $entry['issued'][0]['year']);
$this->assertEquals($issuedFull[$count]['day'], $entry['issued'][0]['day']);
$this->assertEquals($issuedFull[$count]['month'], $entry['issued'][0]['month']);
}
$count++;
}
}
示例14: 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;
}
示例15: 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);
}