|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverLeague\Console\Framework; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Control\HTTPApplication; |
|
6
|
|
|
use SilverStripe\Control\HTTPRequestBuilder; |
|
7
|
|
|
use SilverStripe\Core\CoreKernel; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Loads and configures SilverStripe |
|
11
|
|
|
* |
|
12
|
|
|
* @package silverstripe-console |
|
13
|
|
|
* @author Robbie Averill <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class Bootstrap |
|
16
|
3 |
|
{ |
|
17
|
|
|
/** |
|
18
|
3 |
|
* Ensure SilverStripe is loaded and configured |
|
19
|
|
|
*/ |
|
20
|
|
|
public function initialize() |
|
21
|
|
|
{ |
|
22
|
|
|
if (!$this->findSilverStripe()) { |
|
23
|
3 |
|
echo 'A SilverStripe installation could not be found. Please run ssconsole from your ' |
|
24
|
3 |
|
. 'SilverStripe root.', PHP_EOL; |
|
25
|
|
|
exit(1); |
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Find and require SilverStripe. This will look in: |
|
31
|
|
|
* |
|
32
|
|
|
* - The current working directory (for when installed globally with composer) |
|
33
|
|
|
* - The next directory up (for when installed locally into a SilverStripe project) |
|
34
|
|
|
* - The console's "silverstripe" directory (for when installed in a build process) |
|
35
|
3 |
|
* |
|
36
|
|
|
* @return bool |
|
37
|
3 |
|
*/ |
|
38
|
3 |
|
protected function findSilverStripe() |
|
39
|
3 |
|
{ |
|
40
|
3 |
|
if (defined('SILVERSTRIPE_ROOT_DIR')) { |
|
41
|
3 |
|
return true; |
|
42
|
3 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
foreach ([getcwd(), CONSOLE_BASE_DIR . '/../', CONSOLE_BASE_DIR . '/silverstripe'] as $rootFolder) { |
|
45
|
|
|
if (file_exists($rootFolder . '/vendor/silverstripe/framework/src/Core/CoreKernel.php')) { |
|
46
|
|
|
define('SILVERSTRIPE_ROOT_DIR', $rootFolder); |
|
47
|
|
|
|
|
48
|
|
|
require_once $rootFolder . '/vendor/autoload.php'; |
|
49
|
|
|
|
|
50
|
|
|
$_SERVER['REQUEST_URI'] = '/'; |
|
51
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET'; |
|
52
|
|
|
$_SERVER['SERVER_PROTOCOL'] = 'http'; |
|
53
|
3 |
|
|
|
54
|
|
|
$request = HTTPRequestBuilder::createFromEnvironment(); |
|
55
|
3 |
|
|
|
56
|
3 |
|
// Default application |
|
57
|
3 |
|
$kernel = new CoreKernel(BASE_PATH); |
|
58
|
|
|
$app = new HTTPApplication($kernel); |
|
59
|
3 |
|
$app->handle($request); |
|
60
|
|
|
|
|
61
|
|
|
return true; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return false; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|