コード例 #1
0
ファイル: PreprocessorTest.php プロジェクト: paladox/2
 /**
  * Get XML preprocessor tree from the preprocessor (which may not be the
  * native XML-based one).
  *
  * @param string $wikiText
  * @return string
  */
 protected function preprocessToXml($wikiText)
 {
     if (method_exists($this->mPreprocessor, 'preprocessToXml')) {
         return $this->normalizeXml($this->mPreprocessor->preprocessToXml($wikiText));
     }
     $dom = $this->mPreprocessor->preprocessToObj($wikiText);
     if (is_callable(array($dom, 'saveXML'))) {
         return $dom->saveXML();
     } else {
         return $this->normalizeXml($dom->__toString());
     }
 }
コード例 #2
0
 static function register($filter = null, $class = null)
 {
     if (empty($filter)) {
         $filter = empty($class) ? new parent() : new $class();
     }
     $x = parent::register(new static());
     parent::register($filter);
     self::$processor = $filter;
     return $x;
 }
コード例 #3
0
ファイル: Parser.php プロジェクト: rrameshs/mediawiki
 /**
  * Call a parser function and return an array with text and flags.
  *
  * The returned array will always contain a boolean 'found', indicating
  * whether the parser function was found or not. It may also contain the
  * following:
  *  text: string|object, resulting wikitext or PP DOM object
  *  isHTML: bool, $text is HTML, armour it against wikitext transformation
  *  isChildObj: bool, $text is a DOM node needing expansion in a child frame
  *  isLocalObj: bool, $text is a DOM node needing expansion in the current frame
  *  nowiki: bool, wiki markup in $text should be escaped
  *
  * @since 1.21
  * @param PPFrame $frame The current frame, contains template arguments
  * @param string $function Function name
  * @param array $args Arguments to the function
  * @throws MWException
  * @return array
  */
 public function callParserFunction($frame, $function, array $args = array())
 {
     global $wgContLang;
     # Case sensitive functions
     if (isset($this->mFunctionSynonyms[1][$function])) {
         $function = $this->mFunctionSynonyms[1][$function];
     } else {
         # Case insensitive functions
         $function = $wgContLang->lc($function);
         if (isset($this->mFunctionSynonyms[0][$function])) {
             $function = $this->mFunctionSynonyms[0][$function];
         } else {
             return array('found' => false);
         }
     }
     list($callback, $flags) = $this->mFunctionHooks[$function];
     # Workaround for PHP bug 35229 and similar
     if (!is_callable($callback)) {
         throw new MWException("Tag hook for {$function} is not callable\n");
     }
     $allArgs = array(&$this);
     if ($flags & self::SFH_OBJECT_ARGS) {
         # Convert arguments to PPNodes and collect for appending to $allArgs
         $funcArgs = array();
         foreach ($args as $k => $v) {
             if ($v instanceof PPNode || $k === 0) {
                 $funcArgs[] = $v;
             } else {
                 $funcArgs[] = $this->mPreprocessor->newPartNodeArray(array($k => $v))->item(0);
             }
         }
         # Add a frame parameter, and pass the arguments as an array
         $allArgs[] = $frame;
         $allArgs[] = $funcArgs;
     } else {
         # Convert arguments to plain text and append to $allArgs
         foreach ($args as $k => $v) {
             if ($v instanceof PPNode) {
                 $allArgs[] = trim($frame->expand($v));
             } elseif (is_int($k) && $k >= 0) {
                 $allArgs[] = trim($v);
             } else {
                 $allArgs[] = trim("{$k}={$v}");
             }
         }
     }
     $result = call_user_func_array($callback, $allArgs);
     # The interface for function hooks allows them to return a wikitext
     # string or an array containing the string and any flags. This mungs
     # things around to match what this method should return.
     if (!is_array($result)) {
         $result = array('found' => true, 'text' => $result);
     } else {
         if (isset($result[0]) && !isset($result['text'])) {
             $result['text'] = $result[0];
         }
         unset($result[0]);
         $result += array('found' => true);
     }
     $noparse = true;
     $preprocessFlags = 0;
     if (isset($result['noparse'])) {
         $noparse = $result['noparse'];
     }
     if (isset($result['preprocessFlags'])) {
         $preprocessFlags = $result['preprocessFlags'];
     }
     if (!$noparse) {
         $result['text'] = $this->preprocessToDom($result['text'], $preprocessFlags);
         $result['isChildObj'] = true;
     }
     return $result;
 }
コード例 #4
0
ファイル: FileHandler.php プロジェクト: tmaiaroto/li3_perf
 /**
  * Get a trace reader for the specific file.
  * 
  * If the file has not been preprocessed yet this will be done first.
  *
  * @param string File to read
  * @param Cost format for the reader
  * @return Webgrind_Reader Reader for $file
  */
 public function getTraceReader($file, $costFormat)
 {
     $prepFile = Webgrind::$config->storageDir . '/' . $file . Webgrind::$config->preprocessedSuffix;
     try {
         $r = new Reader($prepFile, $costFormat);
     } catch (Exception $e) {
         // Preprocessed file does not exist or other error
         Preprocessor::parse(Webgrind::$config->xdebugOutputDir . '/' . $file, $prepFile);
         $r = new Reader($prepFile, $costFormat);
     }
     return $r;
 }
コード例 #5
0
    static function getParser($file)
    {
        $parser = new Patchwork_PHP_Parser_Dumper();
        $parser = new Patchwork_PHP_Parser_ShortOpenEcho($parser);
        $parser = new Patchwork_PHP_Parser_Normalizer($parser);
        new Patchwork_PHP_Parser_BracketWatcher($parser);
        new Patchwork_PHP_Parser_CurlyDollarNormalizer($parser);
        new Patchwork_PHP_Parser_ShortArray($parser);
        $parser = new Patchwork_PHP_Parser_BinaryNumber($parser);
        $parser = new Patchwork_PHP_Parser_Backport54Tokens($parser);
        new Patchwork_PHP_Parser_Backport53Tokens($parser);
        new Patchwork_PHP_Parser_StringInfo($parser);
        new Patchwork_PHP_Parser_NamespaceInfo($parser);
        new Patchwork_PHP_Parser_ScopeInfo($parser);
        new Patchwork_PHP_Parser_ClassInfo($parser);
        new Patchwork_PHP_Parser_ConstantInliner($parser, realpath($file));
        new Patchwork_PHP_Parser_Scream($parser);
        return $parser;
    }
}
$parser = Preprocessor::getParser($file);
$code = file_get_contents($file);
$code = $parser->parse($code);
echo "\nResulting code\n==============\n";
echo $code, "\n";
if ($errors = $parser->getErrors()) {
    echo "Reported errors\n===============\n";
    foreach ($errors as $e) {
        echo "Line {$e['line']}: {$e['message']}\n";
    }
}
コード例 #6
0
 static function loadClass($req)
 {
     /**/
     if (PHP_VERSION_ID < 50303) {
         // Workaround http://bugs.php.net/50731
         isset($req[0]) && '\\' === $req[0] && ($req = substr($req, 1));
     }
     $lc_req = strtolower(strtr($req, '\\', '_'));
     $amark = $GLOBALS["a�"];
     $GLOBALS["a�"] = false;
     $bmark = $GLOBALS["b�"];
     // Step 1 - Get basic info
     $i = strrpos($req, '__');
     $level = false !== $i ? substr($req, $i + 2) : false;
     $isTop = false === $level || '' !== trim($level, '0123456789');
     if ($isTop) {
         // Top class
         $top = $req;
         $lc_top = $lc_req;
         $level = PATCHWORK_PATH_LEVEL;
     } else {
         // Preprocessor renammed class
         $top = substr($req, 0, $i);
         $lc_top = substr($lc_req, 0, $i);
         $level = min(PATCHWORK_PATH_LEVEL, '00' === $level ? -1 : (int) $level);
     }
     self::$preproc || (self::$preproc = 'patchwork_preprocessor' === $lc_top);
     // Step 2 - Get source file
     $src = '';
     if (($customSrc =& self::$prefix) && ($a = strlen($lc_top))) {
         // Look for a registered prefix autoloader
         $i = 0;
         $cache = array();
         do {
             $code = ord($lc_top[$i]);
             if (isset($customSrc[$code])) {
                 $customSrc =& $customSrc[$code];
                 isset($customSrc[-1]) && ($cache[] = $customSrc[-1]);
             } else {
                 break;
             }
         } while (++$i < $a);
         if ($cache) {
             do {
                 $src = array_pop($cache);
                 $src = $i < $a || !is_string($src) || function_exists($src) ? call_user_func($src, $top) : $src;
             } while (!$src && $cache);
         }
     }
     unset($customSrc);
     if ($customSrc = '' !== (string) $src) {
     } else {
         if ('_' !== substr($top, -1)) {
             $src = self::class2file($top);
             $src = trim($src, '/') === $src ? "class/{$src}.php" : '';
         }
     }
     $src && ($src = patchworkPath($src, $a, $level, 0));
     // Step 3 - Get parent class
     $src || ($a = -1);
     $isTop && ++$level;
     if ($level > $a) {
         do {
             $parent = $top . '__' . (0 <= --$level ? $level : '00');
         } while (!($parent_exists = self::exists($parent, false)) && $level > $a);
     } else {
         $parent = 0 <= $level ? $top . '__' . (0 < $level ? $level - 1 : '00') : false;
         $parent_exists = false;
     }
     // Step 4 - Load class definition
     $cache = false;
     if ($src && !$parent_exists) {
         $cache = self::class2cache($top . '.php', $level);
         $current_pool = false;
         $parent_pool =& self::$pool;
         self::$pool =& $current_pool;
         if (!(file_exists($cache) && (self::$turbo || filemtime($cache) > filemtime($src)))) {
             if (self::$preproc) {
                 file_exists($cache) && unlink($cache);
                 copy($src, $cache);
             } else {
                 Preprocessor::execute($src, $cache, $level, $top, $isTop, false);
             }
             self::resetOpcodeCache();
         }
         $current_pool = array();
         // Force fatal errors to be always reported
         PHP\InDepthErrorHandler::stackErrors();
         try {
             patchwork_include($cache);
         } catch (\Exception $x) {
         }
         PHP\InDepthErrorHandler::unstackErrors();
         if (isset($x)) {
             throw $x;
         }
         if ($parent && self::exists($req, false)) {
             $parent = false;
         }
         if (false !== $parent_pool) {
             $parent_pool[$parent ? $parent : $req] = $cache;
         }
     }
     // Step 5 - Finalize class loading
     $code = '';
     if ($parent ? $code = self::exists($parent, true) : self::exists($req, false) && !isset($GLOBALS["c�"][$lc_req])) {
         if (false !== ($a = strrpos($req, '\\'))) {
             $ns = substr($req, 0, $a + 1);
             $req = substr($req, $a + 1);
             $parent = substr($parent, $a + 1);
             $lc_req = substr($lc_req, $a + 1);
             $lc_ns = strtolower(strtr($ns, '\\', '_'));
         } else {
             $ns = $lc_ns = '';
         }
         if ($parent) {
             $code .= " {$req} extends {$parent}{}\$GLOBALS['c�']['{$lc_ns}{$lc_req}']=1;";
             $parent = strtolower($parent);
             if ($ns) {
                 $code .= "\\class_alias('{$ns}{$req}','{$lc_ns}{$lc_req}');";
             }
             if (isset(self::$abstracts[$lc_ns . $parent])) {
                 $code = 'abstract ' . $code;
                 self::$abstracts[$lc_ns . $lc_req] = 1;
             }
         } else {
             $parent = $lc_req;
         }
         if ($isTop && class_exists($ns . $parent, false)) {
             $a = "{$ns}{$parent}::i�";
             if (defined($a) ? $lc_req === constant($a) : method_exists($ns . $parent, '__init')) {
                 $code .= "{$parent}::__init();";
             }
             $a = "{$ns}{$parent}::f�";
             if (defined($a) ? $lc_req === constant($a) : method_exists($ns . $parent, '__free')) {
                 $a = "\\Patchwork\\ShutdownHandler::\$destructors[]='{$lc_ns}{$parent}';";
                 $code .= $a;
             }
         }
         if ($ns) {
             $req = $ns . $req;
             $parent = $lc_ns . $parent;
             $lc_req = $lc_ns . $lc_req;
             $ns = substr($ns, 0, -1);
             $ns = "namespace {$ns};";
         }
         if ($code) {
             eval($ns . $code);
         }
     }
     if (!self::$turbo || self::$preproc) {
         self::$preproc && (self::$preproc = 'patchwork_preprocessor' !== $lc_top);
         return;
     }
     if (class_exists('Patchwork\\Preprocessor', false) && Preprocessor::isRunning()) {
         return;
     }
     if ($code && isset($GLOBALS["c�"][$parent])) {
         // Include class declaration in its closest parent
         $src = self::parseMarker($GLOBALS["c�"][$parent], "\$GLOBALS['c�']['{$parent}']=%marker%;");
         list($src, $marker, $a) = $src;
         if (false !== $a) {
             if (!$isTop) {
                 $i = (string) mt_rand(1, mt_getrandmax());
                 $GLOBALS["c�"][$parent] = $src . '*' . $i;
                 $code .= substr($marker, 0, strrpos($marker, '*') + 1) . $i . "';";
             }
             $a = str_replace($marker, $code, $a);
             $cache === $src && $current_pool || self::write($a, $src);
         }
     } else {
         $a = false;
     }
     if ($cache) {
         if ($current_pool) {
             // Add an include directive of parent's code in the derivated class
             $code = '<?php ?' . '>';
             $a || ($a = file_get_contents($cache));
             if ('<?php ' != substr($a, 0, 6)) {
                 $a = '<?php ?' . '>' . $a;
             }
             $a = explode("\n", $a, 2);
             isset($a[1]) || ($a[1] = '');
             $i = '/^' . preg_replace('/__[0-9]+$/', '', $lc_req) . '__[0-9]+$/i';
             foreach ($current_pool as $parent => $src) {
                 if ($req instanceof $parent && false === strpos($a[0], $src)) {
                     $code = substr($code, 0, -2) . (preg_match($i, $parent) ? 'include' : 'include_once') . " '{$src}';?" . ">";
                 }
             }
             if ('<?php ?' . '>' !== $code) {
                 $a = substr($code, 0, -2) . substr($a[0], 6) . $a[1];
                 self::write($a, $cache);
             }
         }
         $cache = substr($cache, strlen(PATCHWORK_PROJECT_PATH) + 7, -11);
         if ($amark) {
             // Marker substitution
             list($src, $marker, $a) = self::parseMarker($amark, "\$a�=%marker%");
             if (false !== $a) {
                 if ($amark != $bmark) {
                     $GLOBALS["a�"] = $bmark;
                     $marker = "isset(\$c�['{$lc_req}'])||{$marker}";
                     $code = ".class_{$cache}.zcache.php";
                     $code = addslashes(PATCHWORK_PROJECT_PATH . $code);
                     $ns = empty($ns) ? '' : '\\';
                     $code = "isset(\$c�['{$lc_req}'])||{$ns}patchwork_include('{$code}')||1";
                 } else {
                     $marker = "\$e�=\$b�={$marker}";
                     $i = (string) mt_rand(1, mt_getrandmax());
                     $GLOBALS["a�"] = $GLOBALS["b�"] = $src . '*' . $i;
                     $i = substr($marker, 0, strrpos($marker, '*') + 1) . $i . "'";
                     $marker = "({$marker})&&\$d�&&";
                     $code = $customSrc ? "'{$cache}'" : $level + count($GLOBALS['patchwork_path']) - PATCHWORK_PATH_LEVEL;
                     $code = "\$c�['{$lc_req}']={$code}";
                     $code = "({$i})&&\$d�&&({$code})&&";
                 }
                 $a = str_replace($marker, $code, $a);
                 self::write($a, $src);
             }
         }
     }
 }
コード例 #7
0
 static function getProcessedPath($file, $lazy = false)
 {
     /**/
     if ('\\' === DIRECTORY_SEPARATOR) {
         false !== strpos($file, '\\') && ($file = strtr($file, '\\', '/'));
     }
     if (false !== strpos('.' . $file, './') || '\\' === DIRECTORY_SEPARATOR && ':' === substr($file, 1, 1)) {
         if ($f = realpath($file)) {
             $file = $f;
         }
         $p = $GLOBALS['patchwork_path'];
         for ($i = PATCHWORK_PATH_LEVEL + 1; $i < count($GLOBALS['patchwork_path']); ++$i) {
             if (0 === strncmp($file, $p[$i], strlen($p[$i]))) {
                 $file = substr($file, strlen($p[$i]));
                 break;
             }
         }
         if (count($GLOBALS['patchwork_path']) === $i) {
             return $f;
         }
     }
     $source = patchworkPath('class/' . $file, $level);
     if (false === $source) {
         return false;
     }
     $cache = self::file2cache($file, $level);
     if (file_exists($cache) && (self::$turbo || filemtime($cache) > filemtime($source))) {
         return $cache;
     }
     Preprocessor::execute($source, $cache, $level, false, true, $lazy);
     self::resetOpcodeCache();
     return $cache;
 }
コード例 #8
0
ファイル: Config.php プロジェクト: KWICKCommunity/Pushup
 /**
  * config factory
  *
  * @param			string			registry index
  * @return			mixed			registry entry
  * @throws			Exception		if no entry is registerd for given index
  */
 public static function get($index)
 {
     // check if config is already loaded
     if (isset(self::$data[$index])) {
         return self::$data[$index];
     }
     // try magic autoloading
     switch ($index) {
         case 'cfg':
             require 'configs/base.php';
             // set defaults
             if (empty($cfg['layout'])) {
                 $cfg['layout'] = 'set1';
             }
             $cfg['urlImg'] = $cfg['image_baseurl'];
             $cfg['urlIcons'] = $cfg['urlImg'] . $cfg['layout'] . '/ic/';
             $cfg['urlGfx'] = $cfg['urlImg'] . $cfg['layout'] . '/gfx/';
             $cfg['urlCSS'] = $cfg['urlImg'] . $cfg['layout'] . '/css/';
             self::setConfig('cfg', $cfg);
             break;
         case 'lvs':
             require 'configs/LVSConfig.php';
             self::setConfig('lvs', $cfg);
             break;
         default:
             $includePath = get_include_path();
             $includePath = explode(':', $includePath);
             foreach ($includePath as $path) {
                 if (substr($path, -1, 1) != DIRECTORY_SEPARATOR) {
                     $path .= DIRECTORY_SEPARATOR;
                 }
                 $file = $path . 'configs' . DIRECTORY_SEPARATOR . $index . '.php';
                 if (is_readable($file)) {
                     // prepare regEx
                     if (null === self::$cacheConfigRegEx) {
                         self::$cacheConfigRegEx = '~^(' . implode('|', self::$cacheConfigs) . ')~';
                     }
                     // check if config is cachable
                     if (!preg_match(self::$cacheConfigRegEx, $index)) {
                         require $file;
                         if (isset($cfg)) {
                             self::setConfig($index, $cfg);
                         } else {
                             error_log('cant´t find variable $cfg in configfile ' . $file);
                         }
                         break 2;
                     }
                     // prepare and cache config
                     $cacheFile = $path . self::$cacheDir . Localizer::getLanguage() . DIRECTORY_SEPARATOR . $index . '.php';
                     // load cached config
                     if (!KWICK_DEV && is_readable($cacheFile)) {
                         require $cacheFile;
                         self::setConfig($index, $cfg);
                         break 2;
                     }
                     // process
                     $data = file_get_contents($file);
                     Preprocessor::process($data, $index, Translatr::TYPE_CONFIG, $path);
                     // save and load cache file
                     try {
                         File::put($cacheFile, $data);
                     } catch (Exception $e) {
                         SC_Log::get()->exception($e);
                     }
                     require $cacheFile;
                     self::setConfig($index, $cfg);
                     break 2;
                 }
             }
             throw new Exception('No entry is registered and autoloading has failed for key "' . $index . '"');
     }
     if (isset(self::$data[$index])) {
         return self::$data[$index];
     } else {
         return false;
     }
 }
コード例 #9
0
ファイル: API.php プロジェクト: rakshazi/social2atom
 public function __construct($di)
 {
     parent::__construct($di);
     $this->init();
 }