forked from silverstripe/silverstripe-framework
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API Move environment / global / ini management into Environment class API Move getTempFolder into TempFolder class API Implement HTTPRequestBuilder / CLIRequestBuilder BUG Restore SS_ALLOWED_HOSTS check in original location API CoreKernel now requires $basePath to be passed in API Refactor installer.php to use application to bootstrap API move memstring conversion globals to Convert BUG Fix error in CoreKernel nesting not un-nesting itself properly.
- Loading branch information
Damian Mooyman
committed
Jun 20, 2017
1 parent
bba9791
commit 12bd31f
Showing
27 changed files
with
2,548 additions
and
2,432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
<?php | ||
|
||
// CLI specific bootstrapping | ||
use SilverStripe\Control\CLIRequestBuilder; | ||
use SilverStripe\Core\AppKernel; | ||
use SilverStripe\Core\HTTPApplication; | ||
use SilverStripe\Core\Startup\OutputMiddleware; | ||
use SilverStripe\Control\HTTPRequest; | ||
|
||
require __DIR__ . '/src/includes/cli.php'; | ||
require __DIR__ . '/src/includes/autoload.php'; | ||
|
||
// Ensure that people can't access this from a web-server | ||
if (!in_array(PHP_SAPI, ["cli", "cgi", "cgi-fcgi"])) { | ||
echo "cli-script.php can't be run from a web request, you have to run it on the command-line."; | ||
die(); | ||
} | ||
|
||
// Build request and detect flush | ||
$request = HTTPRequest::createFromEnvironment(); | ||
$request = CLIRequestBuilder::createFromEnvironment(); | ||
|
||
// Default application | ||
$kernel = new AppKernel(); | ||
$kernel = new AppKernel(BASE_PATH); | ||
$app = new HTTPApplication($kernel); | ||
$app->addMiddleware(new OutputMiddleware()); | ||
$app->handle($request); | ||
$response = $app->handle($request); | ||
$response->output(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
<?php | ||
|
||
use SilverStripe\Control\HTTPRequestBuilder; | ||
use SilverStripe\Core\AppKernel; | ||
use SilverStripe\Core\HTTPApplication; | ||
use SilverStripe\Core\Startup\ErrorControlChainMiddleware; | ||
use SilverStripe\Core\Startup\OutputMiddleware; | ||
use SilverStripe\Control\HTTPRequest; | ||
|
||
require __DIR__ . '/src/includes/autoload.php'; | ||
|
||
// Build request and detect flush | ||
$request = HTTPRequest::createFromEnvironment(); | ||
$request = HTTPRequestBuilder::createFromEnvironment(); | ||
|
||
// Default application | ||
$kernel = new AppKernel(); | ||
$kernel = new AppKernel(BASE_PATH); | ||
$app = new HTTPApplication($kernel); | ||
$app->addMiddleware(new OutputMiddleware()); | ||
$app->addMiddleware(new ErrorControlChainMiddleware($app)); | ||
$app->handle($request); | ||
$response = $app->handle($request); | ||
$response->output(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Control; | ||
|
||
/** | ||
* CLI specific request building logic | ||
*/ | ||
class CLIRequestBuilder extends HTTPRequestBuilder | ||
{ | ||
protected static function cleanEnvironment(array $variables) | ||
{ | ||
// Create all blank vars | ||
foreach (['_REQUEST', '_GET', '_POST', '_SESSION', '_SERVER', '_COOKIE', '_ENV', '_FILES'] as $key) { | ||
if (!isset($variables[$key])) { | ||
$variables[$key] = []; | ||
}; | ||
} | ||
|
||
// We update the $_SERVER variable to contain data consistent with the rest of the application. | ||
$variables['_SERVER'] = array_merge(array( | ||
'SERVER_PROTOCOL' => 'HTTP/1.1', | ||
'HTTP_ACCEPT' => 'text/plain;q=0.5', | ||
'HTTP_ACCEPT_LANGUAGE' => '*;q=0.5', | ||
'HTTP_ACCEPT_ENCODING' => '', | ||
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1;q=0.5', | ||
'SERVER_SIGNATURE' => 'Command-line PHP/' . phpversion(), | ||
'SERVER_SOFTWARE' => 'PHP/' . phpversion(), | ||
'SERVER_ADDR' => '127.0.0.1', | ||
'REMOTE_ADDR' => '127.0.0.1', | ||
'REQUEST_METHOD' => 'GET', | ||
'HTTP_USER_AGENT' => 'CLI', | ||
), $variables['_SERVER']); | ||
|
||
/** | ||
* 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 in the following get data: | ||
* args => array('somearg', 'otherarg'), | ||
* key => val | ||
* otherkey => val | ||
* third => val | ||
* fourth => val | ||
*/ | ||
if (isset($variables['_SERVER']['argv'][2])) { | ||
$args = array_slice($variables['_SERVER']['argv'], 2); | ||
foreach ($args as $arg) { | ||
if (strpos($arg, '=') == false) { | ||
$variables['_GET']['args'][] = $arg; | ||
} else { | ||
$newItems = array(); | ||
parse_str((substr($arg, 0, 2) == '--') ? substr($arg, 2) : $arg, $newItems); | ||
$variables['_GET'] = array_merge($variables['_GET'], $newItems); | ||
} | ||
} | ||
$_REQUEST = array_merge($_REQUEST, $variables['_GET']); | ||
} | ||
|
||
// Set 'url' GET parameter | ||
if (isset($variables['_SERVER']['argv'][1])) { | ||
$variables['_GET']['url'] = $variables['_SERVER']['argv'][1]; | ||
$variables['_SERVER']['REQUEST_URI'] = $variables['_SERVER']['argv'][1]; | ||
} | ||
|
||
// Parse rest of variables as standard | ||
return parent::cleanEnvironment($variables); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.