Ejemplo n.º 1
0
 /**
  * Standard error logger printing to stderr with program name
  */
 static function format_logline(PLUGError $Err)
 {
     if (PLUG::is_compiled()) {
         return sprintf('%s: %s: %s', basename(self::arg(0)), $Err->getTypeString(), $Err->getMessage());
     } else {
         return sprintf('%s: %s: %s in %s#%u', basename(self::arg(0)), $Err->getTypeString(), $Err->getMessage(), basename($Err->getFile()), $Err->getLine());
     }
 }
Ejemplo n.º 2
0
<?php

/**
 * Example shows how to import the jParser classes for library development
 * Be sure to set up your system config in conf/PLUG.conf.php
 */
// PLUG framework is required to import classes
require '../../PLUG/plug.php';
// My aswell import everything from the JavaScript package
import('PLUG.JavaScript.*');
// Using the JTokenizer class directly
$src = 'alert("Hello World")';
$Tokenizer = new JTokenizer(true, true);
$tokens = $Tokenizer->get_all_tokens($src);
//var_dump( $tokens );
// Using the JParser class directly
try {
    $Parser = new JParser();
    $Tree = $Parser->parse($tokens);
} catch (ParseError $Ex) {
    $error = $Ex->getMessage() . "\n----\n" . $Ex->snip($src);
    die('<pre>' . htmlentities($error, ENT_COMPAT, 'UTF-8') . '</pre>');
}
// PLUG buffers errors, so we need to see if anything went wrong.
if (PLUG::is_error()) {
    PLUG::dump_errors();
} else {
    echo 'Done without error.';
}
Ejemplo n.º 3
0
 /**
  * Default error formatting function
  * @param PLUGError
  * @return string
  */
 static function display(PLUGError $Err)
 {
     $html = ini_get('html_errors');
     if ($html) {
         $s = '<div class="error"><strong>%s:</strong> %s. in <strong>%s</strong> on line <strong>%u</strong></div>';
     } else {
         $s = "\n%s: %s. in %s on line %u";
     }
     $args = array($s, $Err->getTypeString(), $Err->getMessage(), $Err->getFile(), $Err->getLine());
     // add trace in dev mode
     if (!PLUG::is_compiled()) {
         $args[0] .= $html ? "\n<pre>%s</pre>" : "\n%s";
         $args[] = $Err->getTraceAsString();
     }
     return call_user_func_array('sprintf', $args);
 }
Ejemplo n.º 4
0
 /**
  * Start compilation
  * @return string optimized source
  */
 function compile($path = null)
 {
     // process as root script if path not passed
     $isroot = is_null($path);
     if ($isroot) {
         $path = $this->path;
         $this->incs = array();
         $this->dependencies = array();
     }
     // compile initial source for top-level file
     //
     $this->inphp = false;
     $this->lasttoken = null;
     $src = $this->compile_php($path, null, $isroot);
     // second pass to replace constants with literals if option set
     //
     if ($this->opt(COMPILER_OPTION_LITERALS)) {
         $tokens = token_get_all($src);
         $src = '';
         do {
             $tok = current($tokens);
             $s = is_array($tok) ? $tok[1] : $tok;
             if (is_array($tok) && T_STRING === $tok[0]) {
                 $c = $tok[1];
                 if (isset($this->conf_consts[$c])) {
                     // replace current definition with target config value
                     $s = var_export($this->conf_consts[$c], 1);
                 } else {
                     if (defined($c) && $this->opt(COMPILER_OPTION_LITERALS_SYS)) {
                         // WARNING: extension constants could differ on target environment
                         $s = var_export(constant($c), 1);
                     }
                 }
             }
             $src .= $s;
         } while (next($tokens) !== false);
     }
     // bytecode compilation with bcompiler extension
     //
     if ($this->opt(COMPILER_OPTION_BYTECODE)) {
         // extension can only operate on files
         $srcpath = tempfile($stdin, null);
         file_put_contents($srcpath, $src);
         unset($src);
         // run via shell due to conflict bugs in bcompiler
         PLUG::exec_bin('bcompile', array($srcpath), $src);
     }
     return $src;
 }
Ejemplo n.º 5
0
 /**
  * Register a callback for getting the current system user's id, or name.
  * - This is useful for logging errors etc..
  * - self::current_user() will return 0, unless you define a handler.
  * @param string | array handler callable with call_user_func
  * @return bool
  */
 static function set_current_user_getter($handler)
 {
     if (!is_callable($handler)) {
         trigger_error('current user getter is not callable (' . var_export($handler, 1) . ')', E_USER_WARNING);
         return false;
     }
     self::$current_user_func = $handler;
     return true;
 }
Ejemplo n.º 6
0
<?php

define('PLUG_COMPILED', true);
require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
/**
 * Import top-level PLUG class
 */
import('PLUG.core.PLUG');
/**
 * Initialize PLUG environment
 */
PLUG::init();
Ejemplo n.º 7
0
 /**
  * Raise a PLUGError originating from this instance.
  * @param int error code.
  * @param string error message text
  * @param int error type constant
  * @return void
  */
 protected function trigger_error($code, $message, $type = E_USER_NOTICE)
 {
     $trace = debug_backtrace();
     $Err = PLUG::raise_error($code, $message, $type, $trace);
     $this->on_trigger_error($Err);
 }