|
1
|
|
|
<?php |
|
2
|
|
|
namespace Buttress\Concrete\Client\Adapter; |
|
3
|
|
|
|
|
4
|
|
|
use Buttress\Concrete\Client\Connection\ModernConnection; |
|
5
|
|
|
use Buttress\Concrete\Console\Console; |
|
6
|
|
|
use Buttress\Concrete\Locator\Site; |
|
7
|
|
|
|
|
8
|
|
|
class ModernAdapter implements Adapter |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
/** @var \Concrete\Core\Application\Application */ |
|
12
|
|
|
protected static $app; |
|
13
|
|
|
|
|
14
|
|
|
/** @var \Buttress\Concrete\Locator\Site $site */ |
|
15
|
|
|
protected $site; |
|
16
|
|
|
|
|
17
|
|
|
/** @var \Buttress\Concrete\Console\Console */ |
|
18
|
|
|
protected $console; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct(Site $site, Console $console) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->site = $site; |
|
23
|
|
|
$this->console = $console; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Get the attached Application object |
|
28
|
|
|
* @return \Concrete\Core\Application\Application |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getApplication() |
|
31
|
|
|
{ |
|
32
|
|
|
return static::$app; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Attach to a modern concrete5 site |
|
37
|
|
|
* @return void |
|
38
|
|
|
*/ |
|
39
|
|
|
public function attach() |
|
40
|
|
|
{ |
|
41
|
|
|
$connection = new ModernConnection(); |
|
42
|
|
|
$connection->connect($this->resolveApplication()); |
|
43
|
|
|
|
|
44
|
|
|
return $connection; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Resolve the application object from a concrete5 site |
|
49
|
|
|
* @return \Concrete\Core\Application\Application |
|
50
|
|
|
*/ |
|
51
|
|
|
private function resolveApplication() |
|
52
|
|
|
{ |
|
53
|
|
|
$path = $this->site->getPath(); |
|
54
|
|
|
chdir($path); |
|
55
|
|
|
|
|
56
|
|
|
// Define some required constants |
|
57
|
|
|
define('DIR_BASE', $path); |
|
58
|
|
|
define('C5_ENVIRONMENT_ONLY', true); |
|
59
|
|
|
|
|
60
|
|
|
// Load in the required constants |
|
61
|
|
|
require $path . '/concrete/bootstrap/configure.php'; |
|
62
|
|
|
|
|
63
|
|
|
// Load in concrete5's autoloader |
|
64
|
|
|
require $path . '/concrete/bootstrap/autoload.php'; |
|
65
|
|
|
|
|
66
|
|
|
// Get the concrete5 application |
|
67
|
|
|
/** @var \Concrete\Core\Application\Application $cms */ |
|
68
|
|
|
$cms = require $path . '/concrete/bootstrap/start.php'; |
|
69
|
|
|
|
|
70
|
|
|
// Boot the runtime |
|
71
|
|
|
if (method_exists($cms, 'getRuntime')) { |
|
72
|
|
|
$runtime = $cms->getRuntime(); |
|
73
|
|
|
$runtime->boot(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$this->console->registerErrorHandler(); |
|
77
|
|
|
return $cms; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|