2007-07-19 12:40:28 +02:00
|
|
|
#!/usr/bin/php5
|
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2008-02-25 03:10:37 +01:00
|
|
|
* File similar to main.php designed for command-line scripts
|
|
|
|
*
|
|
|
|
* This file lets you execute Sapphire requests from the command-line. The URL is passed as the first argument to the scripts.
|
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage core
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-01-09 05:18:36 +01:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
/**
|
|
|
|
* Ensure that people can't access this from a web-server
|
|
|
|
*/
|
|
|
|
if(isset($_SERVER['HTTP_HOST'])) {
|
|
|
|
echo "cli-script.php can't be run from a web request, you have to run it on the command-line.";
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Identify the cli-script.php file and change to its container directory, so that require_once() works
|
|
|
|
*/
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
|
|
|
|
chdir(dirname($_SERVER['SCRIPT_FILENAME']));
|
|
|
|
|
2008-09-25 06:49:01 +02:00
|
|
|
/**
|
|
|
|
* Process arguments and load them into the $_GET and $_REQUEST arrays
|
|
|
|
* For example,
|
|
|
|
* sake my/url somearg otherarg key=val --otherkey=val third=val&fourth=val
|
|
|
|
*
|
|
|
|
* Will result int he following get data:
|
|
|
|
* args => array('somearg', 'otherarg'),
|
|
|
|
* key => val
|
|
|
|
* otherkey => val
|
|
|
|
* third => val
|
|
|
|
* fourth => val
|
|
|
|
*/
|
2008-08-13 03:44:43 +02:00
|
|
|
if(isset($_SERVER['argv'][2])) {
|
2008-09-25 06:49:01 +02:00
|
|
|
$args = array_slice($_SERVER['argv'],2);
|
|
|
|
$_GET = array();
|
|
|
|
foreach($args as $arg) {
|
|
|
|
if(strpos($arg,'=') == false) {
|
|
|
|
$_GET['args'][] = $arg;
|
|
|
|
} else {
|
|
|
|
$newItems = parse_str( (substr($arg,0,2) == '--') ? substr($arg,2) : $arg );
|
|
|
|
$_GET = array_merge($_GET, $newItems);
|
|
|
|
}
|
|
|
|
}
|
2008-08-13 03:44:43 +02:00
|
|
|
$_REQUEST = $_GET;
|
|
|
|
}
|
2008-02-25 03:10:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Include Sapphire's core code
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
require_once("core/Core.php");
|
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
// We don't have a session in cli-script, but this prevents errors
|
|
|
|
$_SESSION = null;
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
// Connect to database
|
|
|
|
require_once("core/model/DB.php");
|
|
|
|
DB::connect($databaseConfig);
|
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
// Get the request URL from the querystring arguments
|
2007-07-19 12:40:28 +02:00
|
|
|
$url = $_SERVER['argv'][1];
|
2008-09-30 01:41:50 +02:00
|
|
|
$_SERVER['REQUEST_URI'] = BASE_URL . '/' . $url;
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
// Direct away - this is the "main" function, that hands control to the apporopriate controller
|
2007-11-11 08:22:24 +01:00
|
|
|
Director::direct($url);
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-05-24 07:57:09 +02:00
|
|
|
?>
|