Skip to content

Commit

Permalink
API Refactor bootstrap, request handling
Browse files Browse the repository at this point in the history
See silverstripe#7037
and silverstripe#6681

Squashed commit of the following:

commit 8f65e56
Author: Ingo Schommer <me@chillu.com>
Date:   Thu Jun 22 22:25:50 2017 +1200

    Fixed upgrade guide spelling

commit 76f9594
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Thu Jun 22 16:38:34 2017 +1200

    BUG Fix non-test class manifest including sapphiretest / functionaltest

commit 9379834
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Thu Jun 22 15:50:47 2017 +1200

    BUG Fix nesting bug in Kernel

commit 188ce35
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Thu Jun 22 15:14:51 2017 +1200

    BUG fix db bootstrapping issues

commit 7ed4660
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Thu Jun 22 14:49:07 2017 +1200

    BUG Fix issue in DetailedErrorFormatter

commit 738f50c
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Thu Jun 22 11:49:19 2017 +1200

    Upgrading notes on mysite/_config.php

commit 6279d28
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Thu Jun 22 11:43:28 2017 +1200

    Update developer documentation

commit 5c90d53
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Thu Jun 22 10:48:44 2017 +1200

    Update installer to not use global databaseConfig

commit f9b2ba4
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Wed Jun 21 21:04:39 2017 +1200

    Fix behat issues

commit 5b59a91
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Wed Jun 21 17:07:11 2017 +1200

    Move HTTPApplication to SilverStripe\Control namespace

commit e2c4a18
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Wed Jun 21 16:29:03 2017 +1200

    More documentation
    Fix up remaining tests
    Refactor temp DB into TempDatabase class so it’s available outside of unit tests.

commit 5d235e6
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Wed Jun 21 12:13:15 2017 +1200

    API HTTPRequestBuilder::createFromEnvironment() now cleans up live globals
    BUG Fix issue with SSViewer
    Fix Security / View tests

commit d88d4ed
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Tue Jun 20 16:39:43 2017 +1200

    API Refactor AppKernel into CoreKernel

commit f7946ae
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Tue Jun 20 16:00:40 2017 +1200

    Docs and minor cleanup

commit 12bd31f
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Tue Jun 20 15:34:34 2017 +1200

    API Remove OutputMiddleware
    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.

commit bba9791
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Mon Jun 19 18:07:53 2017 +1200

    API Create HTTPMiddleware and standardise middleware for request handling

commit 2a10c23
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Mon Jun 19 17:42:42 2017 +1200

    Fixed ORM tests

commit d75a8d1
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Mon Jun 19 17:15:07 2017 +1200

    FIx i18n tests

commit 06364af
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Mon Jun 19 16:59:34 2017 +1200

    Fix controller namespace
    Move states to sub namespace

commit 2a278e2
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Mon Jun 19 12:49:45 2017 +1200

    Fix forms namespace

commit b65c212
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Thu Jun 15 18:56:48 2017 +1200

    Update API usages

commit d1d4375
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Thu Jun 15 18:41:44 2017 +1200

    API Refactor $flush into HTPPApplication
    API Enforce health check in Controller::pushCurrent()
    API Better global backup / restore
    Updated Director::test() to use new API

commit b220534
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Tue Jun 13 22:05:57 2017 +1200

    Move app nesting to a test state helper

commit 6037041
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Tue Jun 13 21:46:04 2017 +1200

    Restore kernel stack to fix multi-level nesting

commit 2f6336a
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Tue Jun 13 17:23:21 2017 +1200

    API Implement kernel nesting

commit fc7188d
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Tue Jun 13 15:43:13 2017 +1200

    Fix core tests

commit a0ae723
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Tue Jun 13 15:23:52 2017 +1200

    Fix manifest tests

commit ca03395
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Tue Jun 13 15:00:00 2017 +1200

    API Move extension management into test state

commit c66d433
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Tue Jun 13 14:10:59 2017 +1200

    API Refactor SapphireTest state management into SapphireTestState
    API Remove Injector::unregisterAllObjects()
    API Remove FakeController

commit f26ae75
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Mon Jun 12 18:04:34 2017 +1200

    Implement basic CLI application object

commit 001d559
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Mon Jun 12 17:39:38 2017 +1200

    Remove references to SapphireTest::is_running_test()
    Upgrade various code

commit de079c0
Author: Damian Mooyman <damian@silverstripe.com>
Date:   Wed Jun 7 18:07:33 2017 +1200

    API Implement APP object
    API Refactor of Session
  • Loading branch information
Damian Mooyman authored and Aaron Carlino committed Jun 26, 2017
1 parent 63414a6 commit c22cdb5
Show file tree
Hide file tree
Showing 202 changed files with 7,008 additions and 5,374 deletions.
20 changes: 20 additions & 0 deletions _config/tests.yml
@@ -0,0 +1,20 @@
---
Name: sapphiretest
---
SilverStripe\Core\Injector\Injector:
SilverStripe\Dev\State\SapphireTestState:
properties:
States:
globals: %$SilverStripe\Dev\State\GlobalsTestState
extensions: %$SilverStripe\Dev\State\ExtensionTestState
flushable: %$SilverStripe\Dev\State\FlushableTestState
requirements: %$SilverStripe\View\Dev\RequirementsTestState
---
Name: kerneltest
Before: '*'
---
SilverStripe\Core\Injector\Injector:
SilverStripe\Dev\State\SapphireTestState:
properties:
States:
kernel: %$SilverStripe\Dev\State\KernelTestState
159 changes: 15 additions & 144 deletions cli-script.php
@@ -1,152 +1,23 @@
<?php

use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataModel;
use SilverStripe\Control\Director;
// CLI specific bootstrapping
use SilverStripe\Control\CLIRequestBuilder;
use SilverStripe\Control\HTTPApplication;
use SilverStripe\Core\CoreKernel;

require __DIR__ . '/src/includes/autoload.php';

/**
* File similar to main.php designed for command-line scripts
*
* This file lets you execute SilverStripe requests from the command-line. The URL is passed as the first argument to
* the scripts.
*/

/**
* Ensure that people can't access this from a web-server
*/
if(PHP_SAPI != "cli" && PHP_SAPI != "cgi" && PHP_SAPI != "cgi-fcgi") {
echo "cli-script.php can't be run from a web request, you have to run it on the command-line.";
die();
}

// We update the $_SERVER variable to contain data consistent with the rest of the application.
$_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',
), $_SERVER);

/**
* 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']));

/**
* 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($_SERVER['argv'][2])) {
$args = array_slice($_SERVER['argv'],2);
if(!isset($_GET)) $_GET = array();
if(!isset($_REQUEST)) $_REQUEST = array();
foreach($args as $arg) {
if(strpos($arg,'=') == false) {
$_GET['args'][] = $arg;
} else {
$newItems = array();
parse_str( (substr($arg,0,2) == '--') ? substr($arg,2) : $arg, $newItems );
$_GET = array_merge($_GET, $newItems);
}
}
$_REQUEST = array_merge($_REQUEST, $_GET);
}

// Set 'url' GET parameter
if(isset($_SERVER['argv'][1])) {
$_REQUEST['url'] = $_SERVER['argv'][1];
$_GET['url'] = $_SERVER['argv'][1];
}

// require composers autoloader
if (file_exists($autoloadPath = dirname(__DIR__) . '/vendor/autoload.php')) {
require_once $autoloadPath;
}
else {
echo "Failed to include composer's autoloader, unable to continue\n";
exit(1);
}

/**
* Include SilverStripe's core code
*/
require_once("Core/Core.php");

global $databaseConfig;

// We don't have a session in cli-script, but this prevents errors
$_SESSION = null;

// Connect to database
if(!isset($databaseConfig) || !isset($databaseConfig['database']) || !$databaseConfig['database']) {
echo "\nPlease configure your database connection details. You can do this by creating a file
called .env in " . BASE_PATH;
echo <<<ENVCONTENT
Put the following content into this file:
--------------------------------------------------
# Change this from 'dev' to 'live' for a production environment.
SS_ENVIRONMENT_TYPE="dev"
/* This defines a default database user */
SS_DATABASE_SERVER="localhost"
SS_DATABASE_USERNAME="<user>"
SS_DATABASE_PASSWORD="<password>"
SS_DATABASE_NAME="<database>"
--------------------------------------------------
Once you have done that, run 'composer install' or './framework/sake dev/build' to create
an empty database.
For more information, please read this page in our docs:
http://docs.silverstripe.org/en/getting_started/environment_management/
ENVCONTENT;
exit(1);
}
DB::connect($databaseConfig);

// register_argc_argv: Tells PHP whether to declare the argv & argc variables (that would contain the GET information)
// http://php.net/manual/en/ini.core.php#ini.register-argc-argv
if (!(int)ini_get('register_argc_argv')) {
echo 'register_argc_argv is required to obtain the GET information but is disabled.'
.'Please enable it in your php.ini ('
. php_ini_loaded_file()
.')';
// 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();
}

// Get the request URL from the querystring arguments
$url = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : null;
if(!$url) {
echo 'Please specify an argument to cli-script.php/sake. For more information, visit'
. ' http://docs.silverstripe.org/en/developer_guides/cli' . "\n";
die();
}

$_SERVER['REQUEST_URI'] = BASE_URL . '/' . $url;

// Direct away - this is the "main" function, that hands control to the apporopriate controller
DataModel::set_inst(new DataModel());
Director::direct($url, DataModel::inst());

// Build request and detect flush
$request = CLIRequestBuilder::createFromEnvironment();

// Default application
$kernel = new CoreKernel(BASE_PATH);
$app = new HTTPApplication($kernel);
$response = $app->handle($request);
$response->output();
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -82,12 +82,12 @@
"SilverStripe\\Framework\\Tests\\Behaviour\\": "tests/behat/src/"
},
"files": [
"src/Core/Constants.php",
"src/Dev/PhpUnitShim.php"
"src/includes/constants.php"
]
},
"include-path": [
"src/",
"src/includes/",
"thirdparty/"
],
"scripts": {
Expand Down
11 changes: 6 additions & 5 deletions docs/en/00_Getting_Started/00_Server_Requirements.md
Expand Up @@ -24,12 +24,13 @@ Our web-based [PHP installer](installation/) can check if you meet the requireme
* `/dev/urandom`
* [`mcrypt_create_iv()`](http://php.net/manual/en/function.mcrypt-create-iv.php)
* CAPICOM Utilities (`CAPICOM.Utilities.1`, Windows only)
* Required modules: dom, gd2, fileinfo, hash, iconv, mbstring, mysqli (or other database driver), session, simplexml, tokenizer, xml.
* Required modules: ctype, dom, fileinfo, hash, intl, mbstring, session, simplexml, tokenizer, xml.
* At least one from each group of extensions:
* Image library extension (gd2, imagick)
* DB connector library (pdo, mysqli, pgsql)
* Recommended configuration

safe_mode = Off
magic_quotes_gpc = Off
memory_limit = 48M
* Dev (local development for running test framework): memory_limit 512MB
* Production: memory_limit = 64M

* See [phpinfo()](http://php.net/manual/en/function.phpinfo.php) for more information about your environment
* One of the following databases:
Expand Down
Expand Up @@ -27,9 +27,9 @@ First we're telling Homebrew about some new repositories to get the PHP installa
brew tap homebrew/dupes
brew tap homebrew/php

We're installing PHP 5.5 here, with the required `mcrypt` module:
We're installing PHP 5.6 here, with the required `mcrypt` module:

brew install php55 php55-mcrypt
brew install php56 php56-mcrypt php56-intl php56-apcu

There's a [Homebrew Troubleshooting](https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Troubleshooting.md) guide if Homebrew doesn't work out as expected (run `brew update` and `brew doctor`).

Expand Down
23 changes: 14 additions & 9 deletions docs/en/00_Getting_Started/04_Directory_Structure.md
Expand Up @@ -18,25 +18,30 @@ Directory | Description
We're using `<mysite>` as an example - arbitrary directory-names are allowed, as long as they don't collide with
existing modules or the directories lists in "Core Structure".

| Directory | Description |
| --------- | ----------- |
| Directory | Description |
| --------- | ----------- |
| `<mysite>/` | This directory contains all of your code that defines your website. |
| `<mysite>/_config` | YAML configuration specific to your application |
| `<mysite>/code` | PHP code for model and controller (subdirectories are optional) |
| `<mysite>/templates` | HTML [templates](/developer_guides/templates) with *.ss-extension |
| `<mysite>/src` | PHP code for model and controller (subdirectories are optional) |
| `<mysite>/tests` | PHP Unit tests |
| `<mysite>/templates` | HTML [templates](/developer_guides/templates) with *.ss-extension for the `$default` theme |
| `<mysite>/css ` | CSS files |
| `<mysite>/images ` | Images used in the HTML templates |
| `<mysite>/javascript` | Javascript and other script files |
| `<mysite>/javascript` | Javascript and other script files |
| `<mysite>/client` | More complex projects can alternatively contain frontend assets in a common `client` folder |
| `<mysite>/themes/<yourtheme>` | Custom nested themes (note: theme structure is described below) |

Check our [JavaScript Coding Conventions](javascript_coding_conventions) for more details
on folder and file naming in SilverStripe core modules.

## Themes Structure

| `themes/simple/` | Standard "simple" theme |
| ------------------ | --------------------------- |
| `themes/yourtheme/` | The themes folder can contain more than one theme - here's your own |
| Directory | Description |
| ------------------ | --------------------------- |
| `themes/simple/` | Standard "simple" theme |
| `themes/<yourtheme>/` | Custom theme base directory |
| `themes/<yourtheme>/templates` | Theme templates |
| `themes/<yourtheme>/css` | Theme CSS files |


See [themes](/developer_guides/templates/themes)
Expand Down Expand Up @@ -77,7 +82,7 @@ Example Forum Documentation:
| `forum/docs/en/` | English documentation |
| `forum/docs/en/index.md` | Documentation homepage. Should provide an introduction and links to remaining docs |
| `forum/docs/en/Getting_Started.md` | Documentation page. Naming convention is Uppercase and underscores. |
| `forum/docs/en//_images/` | Folder to store any images or media |
| `forum/docs/en/_images/` | Folder to store any images or media |
| `forum/docs/en/Some_Topic/` | You can organise documentation into nested folders. Naming convention is Uppercase and underscores. |
|`forum/docs/en/04_Some_Topic/00_Getting_Started.md`|Structure is created by use of numbered prefixes. This applies to nested folders and documentations pages, index.md should not have a prefix.|

Expand Down
15 changes: 5 additions & 10 deletions docs/en/02_Developer_Guides/08_Performance/05_Resource_Usage.md
Expand Up @@ -19,16 +19,11 @@ resources are required temporarily. In general, we recommend running resource in
[command line](../cli), where configuration defaults for these settings are higher or even unlimited.

<div class="info" markdown="1">
SilverStripe can request more resources through `increase_memory_limit_to()` and `increase_time_limit_to()` functions.
SilverStripe can request more resources through `Environment::increaseMemoryLimitTo()` and
`Environment::increaseTimeLimitTo()` functions.
</div>

:::php
function myBigFunction() {
increase_time_limit_to(400);

// or..
set_increase_time_limit_max();

// ..
}
public function myBigFunction() {
Environment::increaseTimeLimitTo(400);
}

0 comments on commit c22cdb5

Please sign in to comment.