|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Buttress\ConcreteClient\Adapter; |
|
4
|
|
|
|
|
5
|
|
|
use Concrete\Core\Application\Application; |
|
6
|
|
|
|
|
7
|
|
|
abstract class ModernAdapter implements Adapter |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Attach to a modern concrete5 site |
|
12
|
|
|
* @param string $path |
|
13
|
|
|
* @return \Buttress\ConcreteClient\Connection\Connection $connection |
|
14
|
|
|
*/ |
|
15
|
8 |
|
public function attach($path) |
|
16
|
4 |
|
{ |
|
17
|
8 |
|
$connection = $this->createConnection(); |
|
18
|
8 |
|
$connection->connect($this->resolveApplication($path)); |
|
19
|
|
|
|
|
20
|
8 |
|
return $connection; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Get the connection to connect with |
|
25
|
|
|
* @return \Buttress\ConcreteClient\Connection\ModernConnection |
|
26
|
|
|
*/ |
|
27
|
|
|
abstract protected function createConnection(); |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Resolve the application object from a concrete5 site |
|
31
|
|
|
* @param string $path |
|
32
|
|
|
* @return \Concrete\Core\Application\Application |
|
33
|
|
|
*/ |
|
34
|
8 |
|
private function resolveApplication($path) |
|
35
|
|
|
{ |
|
36
|
8 |
|
chdir($path); |
|
37
|
|
|
|
|
38
|
|
|
// Setup |
|
39
|
8 |
|
$this->defineConstants($path); |
|
40
|
8 |
|
$this->registerAutoload($path); |
|
41
|
|
|
|
|
42
|
|
|
// Get the concrete5 application |
|
43
|
8 |
|
$cms = $this->getApplicationInstance($path); |
|
44
|
|
|
|
|
45
|
|
|
// Boot the runtime |
|
46
|
8 |
|
$this->bootApplication($cms); |
|
47
|
|
|
|
|
48
|
8 |
|
return $cms; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param $path |
|
53
|
|
|
*/ |
|
54
|
8 |
|
protected function defineConstants($path) |
|
55
|
|
|
{ |
|
56
|
|
|
// Define some required constants |
|
57
|
8 |
|
define('DIR_BASE', $path); |
|
58
|
8 |
|
define('C5_ENVIRONMENT_ONLY', true); |
|
59
|
|
|
|
|
60
|
|
|
// Load in the rest of them |
|
61
|
8 |
|
require $path . '/concrete/bootstrap/configure.php'; |
|
62
|
8 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param $path |
|
66
|
|
|
*/ |
|
67
|
8 |
|
protected function registerAutoload($path) |
|
68
|
|
|
{ |
|
69
|
|
|
// Load in concrete5's autoloader |
|
70
|
8 |
|
require $path . '/concrete/bootstrap/autoload.php'; |
|
71
|
8 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param $path |
|
75
|
|
|
* @return \Concrete\Core\Application\Application |
|
76
|
|
|
*/ |
|
77
|
8 |
|
protected function getApplicationInstance($path) |
|
78
|
|
|
{ |
|
79
|
8 |
|
return require $path . '/concrete/bootstrap/start.php'; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param $cms |
|
84
|
|
|
*/ |
|
85
|
8 |
|
protected function bootApplication(Application $cms) |
|
86
|
|
|
{ |
|
87
|
8 |
|
if (method_exists($cms, 'getRuntime')) { |
|
88
|
4 |
|
$runtime = $cms->getRuntime(); |
|
89
|
4 |
|
$runtime->boot(); |
|
90
|
2 |
|
} |
|
91
|
8 |
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|