1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* admin |
5
|
|
|
* |
6
|
|
|
* @category Apparat |
7
|
|
|
* @package Apparat\Server |
8
|
|
|
* @subpackage Tollwerk\Admin\Infrastructure\Strategy |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Tollwerk\Admin\Infrastructure\Strategy; |
38
|
|
|
|
39
|
|
|
use Tollwerk\Admin\Application\Contract\VhostPersistenceAdapterStrategyInterface; |
40
|
|
|
use Tollwerk\Admin\Domain\Account\Account; |
41
|
|
|
use Tollwerk\Admin\Domain\Vhost\Vhost; |
42
|
|
|
use Tollwerk\Admin\Infrastructure\App; |
43
|
|
|
use Tollwerk\Admin\Infrastructure\Persistence\Apache; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Apache persistence adapter strategy |
47
|
|
|
* |
48
|
|
|
* @package Apparat\Server |
49
|
|
|
* @subpackage Tollwerk\Admin\Infrastructure |
50
|
|
|
*/ |
51
|
|
|
class ApachePersistenceAdapterStrategy implements VhostPersistenceAdapterStrategyInterface |
52
|
|
|
{ |
53
|
|
|
/** |
54
|
|
|
* Webroot directory |
55
|
|
|
* |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
protected $webroot; |
59
|
|
|
/** |
60
|
|
|
* Configuration root directory |
61
|
|
|
* |
62
|
|
|
* @var |
63
|
|
|
*/ |
64
|
|
|
protected $configroot; |
65
|
|
|
/** |
66
|
|
|
* Logging root directory |
67
|
|
|
* |
68
|
|
|
* @var |
69
|
|
|
*/ |
70
|
|
|
protected $logroot; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Constructor |
74
|
|
|
* |
75
|
|
|
* @throws \RuntimeException If the adapter configuration is invalid |
76
|
|
|
* @throws \RuntimeException If the Apache webroot configuration is invalid |
77
|
|
|
* @throws \RuntimeException If the Apache config root configuration is invalid |
78
|
|
|
*/ |
79
|
|
|
public function __construct() |
80
|
|
|
{ |
81
|
|
|
$apacheConfig = App::getConfig('apache'); |
82
|
|
|
|
83
|
|
|
// If the adapter configuration is invalid |
84
|
|
|
if (!is_array($apacheConfig)) { |
85
|
|
|
throw new \RuntimeException('Invalid apache adapter strategy configuration', 1475500531); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// If the Apache webroot configuration is invalid |
89
|
|
|
if (empty($apacheConfig['webroot']) || !is_dir($apacheConfig['webroot'])) { |
90
|
|
|
throw new \RuntimeException(sprintf('Invalid apache webroot configuration', 1475500605)); |
91
|
|
|
} |
92
|
|
|
$this->webroot = rtrim($apacheConfig['webroot'], DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
93
|
|
|
|
94
|
|
|
// If the Apache config root configuration is invalid |
95
|
|
|
if (empty($apacheConfig['config']) || !is_dir($apacheConfig['config'])) { |
96
|
|
|
throw new \RuntimeException(sprintf('Invalid apache config root configuration', 1475500666)); |
97
|
|
|
} |
98
|
|
|
$this->configroot = rtrim($apacheConfig['config'], DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
99
|
|
|
|
100
|
|
|
// If the Apache log root configuration is invalid |
101
|
|
|
if (empty($apacheConfig['logroot']) || !is_dir($apacheConfig['logroot'])) { |
102
|
|
|
throw new \RuntimeException(sprintf('Invalid apache logging root configuration', 1475506107)); |
103
|
|
|
} |
104
|
|
|
$this->logroot = rtrim($apacheConfig['logroot'], DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Persist a virtual host |
109
|
|
|
* |
110
|
|
|
* @param Account $account Account |
111
|
|
|
* @param Vhost $vhost Virtual host |
112
|
|
|
* @return bool Success |
113
|
|
|
* @throws \RuntimeException If a config file couldn't be written |
114
|
|
|
*/ |
115
|
|
|
public function persist(Account $account, Vhost $vhost) |
116
|
|
|
{ |
117
|
|
|
// TODO |
118
|
|
|
// $persister = new Apache($account); |
119
|
|
|
// $entries = $persister->persist($this->webroot, $this->configroot, $this->logroot); |
120
|
|
|
// |
121
|
|
|
// // Persist the file entries |
122
|
|
|
// foreach ($entries as $filename => $configParts) { |
123
|
|
|
// $configFile = $this->configroot.$account->getName().DIRECTORY_SEPARATOR.$filename; |
124
|
|
|
// if (!file_put_contents($configFile, implode(PHP_EOL.PHP_EOL, $configParts))) { |
125
|
|
|
// throw new \RuntimeException(sprintf('Couldn\'t write config file "%s"', $filename, 1475507805)); |
126
|
|
|
// } |
127
|
|
|
// } |
128
|
|
|
|
129
|
|
|
return true; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|