protected function getTests($directory, $fileExtension) { $it = new \RecursiveDirectoryIterator($directory); $it = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::LEAVES_ONLY); $it = new \RegexIterator($it, '(\\.' . preg_quote($fileExtension) . '$)'); $tests = array(); foreach ($it as $file) { $fileName = realpath($file->getPathname()); $fileContents = file_get_contents($fileName); // evaluate @@{expr}@@ expressions $fileContents = preg_replace_callback('/@@\\{(.*?)\\}@@/', function ($matches) { return eval('return ' . $matches[1] . ';'); }, $fileContents); // parse sections $parts = array_map('trim', explode('-----', $fileContents)); // first part is the name $name = array_shift($parts) . ' (' . $fileName . ')'; $shortName = basename($fileName, '.test'); // multiple sections possible with always two forming a pair $chunks = array_chunk($parts, 2); foreach ($chunks as $i => $chunk) { $dataSetName = $shortName . (count($chunks) > 1 ? '#' . $i : ''); list($expected, $mode) = $this->extractMode(canonicalize($chunk[1])); $tests[$dataSetName] = array($name, $chunk[0], $expected, $mode); } } return $tests; }
private function getParseOutput(Parser $parser, $code, $dumpPositions) { $errors = new ErrorHandler\Collecting(); $stmts = $parser->parse($code, $errors); $output = ''; foreach ($errors->getErrors() as $error) { $output .= $this->formatErrorMessage($error, $code) . "\n"; } if (null !== $stmts) { $dumper = new NodeDumper(['dumpComments' => true, 'dumpPositions' => $dumpPositions]); $output .= $dumper->dump($stmts, $code); } return canonicalize($output); }
// get run information $stmt = $pdo->prepare("SELECT folder FROM workflows WHERE workflows.id=?"); if (!$stmt->execute(array($workflowid))) { die('Invalid query: ' . error_database()); } $run = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); $folder = str_replace("//", "/", $run['folder']); // return dataset switch ($type) { case "file": if (!isset($_REQUEST['name'])) { die("Need name."); } $name = $_REQUEST['name']; $file = canonicalize("{$folder}/{$name}"); if (substr($file, 0, strlen($folder)) != $folder) { die("Invalid file name specified."); } if (substr($name, -4) === ".xml") { $mime = "text/xml"; } else { if (substr($name, -4) === ".txt") { $mime = "text/plain"; } else { if (substr($name, -4) === ".log") { $mime = "text/plain"; } else { if (substr($name, -4) === ".pdf") { $mime = "application/pdf"; } else {
public function testJsonSerialization() { $code = <<<'PHP' <?php // comment /** doc comment */ function functionName(&$a = 0, $b = 1.0) { echo 'Foo'; } PHP; $expected = <<<'JSON' [ { "nodeType": "Stmt_Function", "byRef": false, "name": "functionName", "params": [ { "nodeType": "Param", "type": null, "byRef": true, "variadic": false, "name": "a", "default": { "nodeType": "Scalar_LNumber", "value": 0, "attributes": { "startLine": 4, "endLine": 4, "kind": 10 } }, "attributes": { "startLine": 4, "endLine": 4 } }, { "nodeType": "Param", "type": null, "byRef": false, "variadic": false, "name": "b", "default": { "nodeType": "Scalar_DNumber", "value": 1, "attributes": { "startLine": 4, "endLine": 4 } }, "attributes": { "startLine": 4, "endLine": 4 } } ], "returnType": null, "stmts": [ { "nodeType": "Stmt_Echo", "exprs": [ { "nodeType": "Scalar_String", "value": "Foo", "attributes": { "startLine": 5, "endLine": 5, "kind": 1 } } ], "attributes": { "startLine": 5, "endLine": 5 } } ], "attributes": { "startLine": 4, "comments": [ { "nodeType": "Comment", "text": "\/\/ comment\n", "line": 2, "filePos": 6 }, { "nodeType": "Comment_Doc", "text": "\/** doc comment *\/", "line": 3, "filePos": 17 } ], "endLine": 6 } } ] JSON; $parser = new Parser\Php7(new Lexer()); $stmts = $parser->parse(canonicalize($code)); $json = json_encode($stmts, JSON_PRETTY_PRINT); $this->assertEquals(canonicalize($expected), canonicalize($json)); }
function NormalizeURL($url) { // Test if url is absolute if (stristr($url, 'http://')) { return $url; } $siteurlparsed = parse_url(SITEURL); $host = $siteurlparsed['scheme'] . '://' . $siteurlparsed['host']; // If http not in url, assumes relative address to blog url return canonicalize($host . $url); }
<?php require dirname(__FILE__) . '/url.php'; require dirname(__FILE__) . '/vendor/lessc.inc.php'; // List my ressources $ressources = array('components/url-config.less', 'components/reset.less', 'components/text.less', 'components/forms.less', 'components/img.less', 'components/mixins.less', 'components/superfish.less', 'grids/grid.less', 'grids/desktop.less', 'grids/tablet.less', 'grids/mobile.less', 'components/variables.less', 'master.less', 'components/print.less'); // Dynamic css $dynamic_less = ''; // Parse & compile LESS foreach ($ressources as $file) { $dynamic_less .= file_get_contents(dirname(__FILE__) . '/../../assets/css/' . $file); } // Dynamic build URL $dynamic_less = str_replace('{theme_url}', canonicalize(get_full_url($_SERVER, true) . '../..'), $dynamic_less); // Build CSS $less = new lessc(); $css_output = $less->parse($dynamic_less); // Fix bug with IE6-IE7-IE8 $css_output = str_replace(' / ', '/', $css_output); // send header CSS header("Content-Type: text/css"); echo $css_output; exit;