Exemple #1
0
 public function execute(Engine\Executor $executor, array $args, Engine\Zval\Ptr $return = null, \PHPPHP\Engine\Objects\ClassInstance $ci = null, \PHPPHP\Engine\Objects\ClassEntry $ce = null)
 {
     $rawArgs = $this->compileArguments($args);
     ob_start();
     $ret = call_user_func_array($this->callback, $rawArgs);
     $out = ob_get_clean();
     if ($out) {
         $executor->getOutput()->write($out);
     }
     if ($return) {
         $return->setValue($this->compileReturn($ret));
     }
 }
Exemple #2
0
 protected function registerConstants(\PHPPHP\Engine\Executor $executor)
 {
     $store = $executor->getConstantStore();
     foreach (get_defined_constants(true) as $group => $set) {
         if ($group == 'user') {
             continue;
         }
         foreach ($set as $name => $value) {
             if (!$store->exists($name)) {
                 $store->register($name, Zval::factory($value));
             }
         }
     }
 }
Exemple #3
0
 public function handle(\PHPPHP\Engine\Executor $executor, $level, $message, $file, $line, $extra = '', $addFunc = true)
 {
     if ($executor->executorGlobals->error_reporting & $level) {
         $prefix = static::getErrorLevelName($level);
         $func = $addFunc && $executor->executorGlobals->call ? $executor->executorGlobals->call->getName() . '(): ' : '';
         $output = sprintf("%s: %s%s in %s on line %d%s", $prefix, $func, $message, $file, $line, $extra);
         if ($executor->executorGlobals->display_errors) {
             $executor->getOutput()->write("\n{$output}\n", true);
         }
         if ($level & (E_PARSE | E_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR)) {
             $executor->shutdown();
             throw new \PHPPHP\Engine\ErrorOccurredException();
         }
     }
 }
Exemple #4
0
 public function register(\PHPPHP\Engine\Executor $executor)
 {
     $functionStore = $executor->getFunctionStore();
     foreach ($this->getFunctions() as $name => $functionData) {
         $functionStore->register($name, $functionData);
     }
     $constantStore = $executor->getConstantStore();
     foreach ($this->getConstants() as $name => $value) {
         $constantStore->register($name, Engine\Zval::factory($value));
     }
     $classStore = $executor->getClassStore();
     foreach ($this->getClasses() as $ce) {
         $classStore->register($ce);
     }
 }
Exemple #5
0
 protected function checkParams(\PHPPHP\Engine\Executor $executor, array &$args, $checkTooMany = false)
 {
     $argNo = 0;
     $required = 0;
     $hasOptional = false;
     $has = count($args);
     $varargs = false;
     while ($param = $this->getParam($argNo)) {
         if ($param->type) {
             $error = "";
             if ($param->type == 'array') {
                 if (!isset($args[$argNo]) && !$param->isOptional) {
                     $error = "array";
                 } elseif (!isset($args[$argNo])) {
                     // Blank intentional
                 } elseif (!$args[$argNo]->isArray() && !($args[$argNo]->isNull() && $param->isOptional)) {
                     $error = "array";
                 }
             } elseif ($param->type == 'callable') {
                 //bypass the callable check for now...
             } else {
                 if (!isset($args[$argNo]) && !$param->isOptional) {
                     $error = "instance of {$param->type}";
                 } elseif (!isset($args[$argNo])) {
                     // Blank intentional
                 } elseif (!$args[$argNo]->isObject() && !($args[$argNo]->isNull() && $param->isOptional)) {
                     $error = "instance of {$param->type}";
                 } elseif (!$args[$argNo]->isObject()) {
                     // Blank intentional
                 } elseif (!$args[$argNo]->getValue()->getClassEntry()->isInstanceOf($param->type)) {
                     $error = "instance of {$param->type}";
                 }
             }
             if ($error) {
                 $type = "none";
                 if (isset($args[$argNo])) {
                     $type = $args[$argNo]->getType();
                     if ($type == 'object') {
                         $type = 'instance of ' . $args[$argNo]->getValue()->getClassEntry()->getName();
                     }
                 }
                 $extra = '';
                 if ($this->getFileName()) {
                     $extra = ' and defined in ' . $this->getFileName() . ' on line ' . $param->lineno;
                 }
                 $message = "Argument " . ($argNo + 1) . " passed to {$this->name}() must be an {$error}, {$type} given, called";
                 $executor->raiseError(E_RECOVERABLE_ERROR, $message, $extra, false);
             }
         }
         if (!$param->isOptional) {
             $required++;
             if (!isset($args[$argNo])) {
                 $args[$argNo] = Engine\Zval::ptrFactory();
             }
         } else {
             $hasOptional = true;
         }
         if ($param->name == '...') {
             $varargs = true;
         }
         $argNo++;
     }
     if ($required > $has) {
         $message = $this->name;
         $message .= "() expects ";
         $message .= $hasOptional ? "at least" : "exactly";
         $message .= " {$required} " . ($required == 1 ? "parameter" : "parameters");
         $message .= ", {$has} given";
         $executor->raiseError(E_WARNING, $message, '', false);
         return false;
     } elseif ($checkTooMany && !$varargs && $has > $argNo) {
         $message = $this->name;
         $message .= "() expects ";
         $message .= $hasOptional ? "at most" : "exactly";
         $message .= " {$argNo} " . ($argNo == 1 ? "parameter" : "parameters");
         $message .= ", {$has} given";
         $executor->raiseError(E_WARNING, $message, '', false);
         return false;
     }
     return true;
 }
Exemple #6
0
 public function register(\PHPPHP\Engine\Executor $executor)
 {
     $this->registerCoreConstants($executor->getConstantStore());
     parent::register($executor);
 }
Exemple #7
0
 public function __construct(\PHPPHP\Engine\Executor $executor)
 {
     $this->executor = $executor;
     $this->parent = $executor->getOutput();
 }