/** * 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()); }
/** * 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; }
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)')); }
/** * @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); }
/** * 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; }
/** * @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); }
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. } }
/** * @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; }
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(); }
/** * 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); }
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; }
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; }
/** * @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++; } }
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; }
/** * 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); }
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); }
/** * {@inheritdoc} */ public function parse(string $payload) : array { if (!$this->taggedKey) { return parent::parse($payload); } return $this->group($this->taggedKey, parent::parse($payload)); }
/** * @return DOMDocument */ private function createAst() { $input = file_get_contents($this->fixtureDir . DIRECTORY_SEPARATOR . "test_grammar.ebnf"); $scanner = new Scanner($input); $parser = new Parser($scanner); return $parser->parse(); }
function testParse() { $url = __DIR__ . '/data/feed.xml'; $num = Parser::parse($url); $this->assertEquals(5, $num); $this->assertEquals("Product: Azuri", substr(file_get_contents("var/35c9eda8ca5eb46de65764e88fcb707f.txt"), 0, 14)); }
function sandboxParse($wikiText){ global $wgUser; $myParser = new Parser(); $myParserOptions = ParserOptions::newFromUser( $wgUser ); $result = $myParser->parse($wikiText, $this->getTitle(), $myParserOptions); return $result->getText(); }
/** * @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()); }
public function testParseNull() { $this->parser->setUA(null); $result = $this->parser->parse(); $this->assertArrayHasKey("user_agent", $result); $this->assertArrayHasKey("ip_address", $result); }
function generate($source) { global $savefile; $p = new Parser(); $p->parse('types.hh'); $p->parse($source); ob_start(); $p->render('implementation.cc'); $contents = ob_get_contents(); ob_clean(); if (!$savefile) { echo $contents; } else { file_put_contents('generated/' . str_replace('.i', '.cpp', $source), $contents); } }
private function dumpAst($expression) { $parser = new Parser(); $ast = $parser->parse($expression); fwrite($this->out, "AST\n========\n\n"); fwrite($this->out, json_encode($ast, JSON_PRETTY_PRINT) . "\n"); }
/** * Loads the mapping table. */ private function loadTable() { // no need to load multiple times. if ($this->loaded) { return; } $this->loaded = true; $title = Title::newFromText(self::$tablePageName); if (!$title->exists()) { return; } $tablePageRev = Revision::newFromTitle($title); if (is_object($tablePageRev)) { $tablePage = $tablePageRev->getText(); global $wgUser; $parser = new Parser(); $parser->setFunctionHook('tag_to_template', array($this, 'mg_tag_to_template')); // this will populate the 'map' variable // assuming of course that the page was edited with // {{#tag_to_template| ... }} instructions. $this->initPhase = true; $parser->parse($tablePage, $title, new ParserOptions($wgUser)); $this->initPhase = false; } }
function WidgetWikiPage($id, $params) { global $wgTitle, $wgParser; wfProfileIn(__METHOD__); if (!is_object($wgTitle)) { $wgTitle = new Title(); } // clean up inputs $params['source'] = trim($params['source']); $params['name'] = trim($params['name']); //stopgap for 67038 $source = Title::newFromText($params['source']); if (is_object($source) && !$source->userCan('read')) { wfProfileOut(__METHOD__); return array('body' => '', 'title' => $params['name']); } // // parse message and clean it up // // fixes #2774 if (isset($params['_widgetTag'])) { // work-around for WidgetTag $parser = new Parser(); } else { $parser =& $wgParser; } $options = new ParserOptions(); $options->setMaxIncludeSize(2048); if (empty($params['source'])) { // blank source pagename, use default message $ret = $parser->parse(wfMsg('widgetwikipage', $params['source']), $wgTitle, $options)->getText(); } else { // has a source value // get contents $article = WidgetFramework::getArticle($params['source']); if ($article == false) { // failed to get text, show error message, failed pagename is in $1 $ret = $parser->parse('<span class="widget-error-wikipage-missing">' . wfMsg('widgetwikipagemissing', $params['source']) . '</span>', $wgTitle, $options)->getText(); // TODO: change title if page missing? } else { // got text, parse it! $ret = $parser->parse($article, $wgTitle, $options)->getText(); } } wfProfileOut(__METHOD__); return array('body' => $ret, 'title' => $params['name']); }
public function __construct(IProviderProvider $provider, Parser $parser) { $post = $parser->parse(file_get_contents('php://input')); if (!is_array($post)) { $post = []; } $this->data = $post; }
/** * @dataProvider provideBadNames * @expectedException MWException * @covers Parser::setFunctionTagHook */ public function testBadFunctionTagHooks($tag) { global $wgParserConf, $wgContLang; $parser = new Parser($wgParserConf); $parser->setFunctionTagHook($tag, array($this, 'functionTagCallback'), Parser::SFH_OBJECT_ARGS); $parser->parse("Foo<{$tag}>Bar</{$tag}>Baz", Title::newFromText('Test'), ParserOptions::newFromUserAndLang(new User(), $wgContLang)); $this->fail('Exception not thrown.'); }
public function parse() { $parsed = parent::parse(); // POST PROCESSING: // Replace <pre></code> with <pre> $parsed = preg_replace('/<pre\\b[^>]*><code\\b[^>]*>(.*)?<\\/code><\\/pre>/si', '<pre>\\1</pre>', $parsed); return $parsed; }
/** * Parses an query and returns the parsed form. * If the query is not a string but a Query object, * it will just be returned. * * @param $query mixed String or Query object * @return Query query object * @throws Exception If $query is no string and no Query object */ function _parseSparqlQuery($query) { if ($this->queryParser === null) { require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlParser.php'; $this->queryParser = new SparqlParser(); } return $this->queryParser->parse($query); }