Skip to content

Commit

Permalink
cleaned up server app runner. No longer needs a separate scripts dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamagokun committed Jan 23, 2014
1 parent 7bb1487 commit fd94ca3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 47 deletions.
76 changes: 35 additions & 41 deletions bin/rackem
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,59 @@

if(!class_exists("\\Rackem\Server"))
{
try {
require_once dirname(__DIR__).'/rackem.php';
}catch(Exception $e)
{
echo "Failed to load Rack'em library. Is rackem installed in the proper location?\n";
}
try {
require_once dirname(__DIR__).'/rackem.php';
} catch(Exception $e) {
echo "Failed to load Rack'em library. Is rackem installed in the proper location?\n";
}
}

if(function_exists("date_default_timezone_set"))
date_default_timezone_set('UTC');
date_default_timezone_set('UTC');

$argv = $GLOBALS['argv'];
array_shift($argv);

$flags = array('h','basic','v','version');
$args = array();
$opts = array();
while(list($k,$arg) = each($argv))
{
$opt_regex = '/-{1,2}(\w*)(=.*)?/';
if(preg_match($opt_regex,$arg,$m) !== 1)
{
$args[] = $arg;
continue;
}
$opts[$m[1]] = true;
if(!empty($m[2]))
{
$opts[$m[1]] = ltrim($m[2],'=');
continue;
}
if(in_array($m[1],$flags)) continue;
if(($next = current($argv)) === false) continue;
if(preg_match($opt_regex,$next) === 1) continue;
$opts[$m[1]] = $next;
each($argv);
while( list($k,$arg) = each($argv) ) {
$opt_regex = '/-{1,2}(\w*)(=.*)?/';
if(preg_match($opt_regex,$arg,$m) !== 1) {
$args[] = $arg;
continue;
}
$opts[$m[1]] = true;
if(!empty($m[2])) {
$opts[$m[1]] = ltrim($m[2],'=');
continue;
}
if(in_array($m[1],$flags)) continue;
if(($next = current($argv)) === false) continue;
if(preg_match($opt_regex,$next) === 1) continue;
$opts[$m[1]] = $next;
each($argv);
}

if(isset($opts['h']))
{
$server = new \Rackem\Server();
$server->help();
exit(0);

if(isset($opts['h'])) {
$server = new \Rackem\Server();
$server->help();
exit(0);
}

if(isset($opts['v']) || isset($opts['version']))
{
echo "Rack'em version ".implode(".", \Rackem::version())."\n";
exit(0);
if(isset($opts['v']) || isset($opts['version'])) {
echo "Rack'em version ".implode(".", \Rackem::version())."\n";
exit(0);
}

$app = count($argv) > 0? $argv[0] : 'config.php';

if(isset($opts['basic'])) $app = dirname(__DIR__).'/script/basic.php';

if(!file_exists($app))
{
echo "configuration {$app} not found\n";
exit(1);
if(isset($opts['basic'])) {
$app = "\Rackem::run(\"\Rackem\BasicWebServer\")";
}elseif(!file_exists($app)) {
echo "configuration {$app} not found\n";
exit(1);
}

$host = isset($opts['host'])? $opts['host'] : '0.0.0.0';
Expand Down
3 changes: 2 additions & 1 deletion lib/Rackem/Server/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@ public function process($app)
$env["HTTP_$env_name"] = is_array($v) ? implode("\n", $v) : $v;
}

$app = file_exists($app)? 'require "'.$app.'";' : 'return '.$app.';';
$dir = dirname(dirname(dirname(__DIR__))).'/rackem.php';
$code = <<<EOT
if (!class_exists("\Rackem\Server")) require_once "$dir";
if(function_exists("date_default_timezone_set")) date_default_timezone_set("UTC");
require "$app";
$app
EOT;

$php = defined("PHP_BINARY") ? PHP_BINARY : PHP_BINDIR."/php";
Expand Down
5 changes: 0 additions & 5 deletions script/basic.php

This file was deleted.

0 comments on commit fd94ca3

Please sign in to comment.