PhpSandbox\PHPSandbox::prepareConsts PHP Méthode

prepareConsts() protected méthode

Prepare defined constants for execution
protected prepareConsts ( )
    protected function prepareConsts()
    {
        $output = [];
        foreach ($this->definitions['constants'] as $name => $value) {
            if (is_scalar($value) || is_null($value)) {
                if (is_bool($value)) {
                    $output[] = '\\define(' . "'" . $name . "', " . ($value ? 'true' : 'false') . ');';
                } else {
                    if (is_int($value)) {
                        $output[] = '\\define(' . "'" . $name . "', " . ($value ? $value : '0') . ');';
                    } else {
                        if (is_float($value)) {
                            $output[] = '\\define(' . "'" . $name . "', " . ($value ? $value : '0.0') . ');';
                        } else {
                            if (is_string($value)) {
                                $output[] = '\\define(' . "'" . $name . "', '" . addcslashes($value, "'\\") . "');";
                            } else {
                                $output[] = '\\define(' . "'" . $name . "', null);";
                            }
                        }
                    }
                }
            } else {
                $this->validationError("Sandboxed code attempted to define non-scalar constant value: {$name}", Error::DEFINE_CONST_ERROR, null, $name);
            }
        }
        return count($output) ? implode("\r\n", $output) . "\r\n" : '';
    }
PHPSandbox