Ejemplo n.º 1
0
 /**
  * Invoke Runner::main() and return output
  *
  * @param  string $webroot The web root
  * @param  string $config The configuration directory
  * @param  string $profile The server profile
  * @param  string $url The script URL
  * @return string
  */
 private function run($webroot, $config, $profile, $url)
 {
     $_ENV = [];
     $_SERVER = ['SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => $url, 'HTTP_HOST' => 'localhost'];
     ob_start();
     Runner::main([$webroot, $config, $profile, $url]);
     $content = ob_get_contents();
     ob_end_clean();
     return $content;
 }
Ejemplo n.º 2
0
    case 'cli-server':
        if (is_file($_SERVER['DOCUMENT_ROOT'] . $_SERVER['REQUEST_URI'])) {
            return FALSE;
        }
        header('HTTP/1.0 500 Internal Server Error');
        $_SERVER['SCRIPT_URL'] = substr($_SERVER['REQUEST_URI'], 0, strcspn($_SERVER['REQUEST_URI'], '?#'));
        $_SERVER['SERVER_PROFILE'] = getenv('SERVER_PROFILE');
        define('STDIN', fopen('php://stdin', 'rb'));
        define('STDOUT', fopen('php://stdout', 'wb'));
        define('STDERR', fopen('php://stderr', 'wb'));
        break;
    default:
        header('HTTP/1.0 500 Internal Server Error');
}
ini_set('error_prepend_string', '<xmp>');
ini_set('error_append_string', '</xmp>');
ini_set('html_errors', 0);
// Bootstrap
if (!(include __DIR__ . DIRECTORY_SEPARATOR . 'lang.base.php')) {
    trigger_error('[bootstrap] Cannot determine boot class path', E_USER_ERROR);
    exit(0x3d);
}
// Set up class path
$paths = array();
$scan = explode(PATH_SEPARATOR . PATH_SEPARATOR, get_include_path());
foreach (explode(PATH_SEPARATOR, $scan[0]) as $path) {
    $paths[] = '~' === $path[0] ? str_replace('~', $webroot, $path) : $path;
}
bootstrap(scanpath($paths, $webroot) . (isset($scan[1]) ? $scan[1] : ''));
exit(\xp\scriptlet\Runner::main(array($webroot, $configd, $_SERVER['SERVER_PROFILE'], $_SERVER['SCRIPT_URL'])));
Ejemplo n.º 3
0
 public function callingMain()
 {
     $temp = System::tempDir();
     // Create web.ini in system's temp dir
     $ini = new \io\File($temp, 'web.ini');
     $ini->open(FILE_MODE_WRITE);
     $ini->write("[app]\n" . "mappings=\"/:welcome\"\n" . "[app::welcome]\n" . "class=undefined\n" . "[app::welcome@dev]\n" . "class=\"" . self::$welcomeScriptlet->getName() . "\"\n");
     $ini->close();
     // Run
     ob_start();
     Runner::main(array($temp, $temp, 'dev', '/'));
     $content = ob_get_contents();
     ob_end_clean();
     $ini->unlink();
     // Assert
     $this->assertEquals('<h1>Welcome, we are open</h1>', $content);
 }