|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Helick\Composer; |
|
4
|
|
|
|
|
5
|
|
|
use Composer\Composer; |
|
6
|
|
|
use Composer\EventDispatcher\EventSubscriberInterface; |
|
7
|
|
|
use Composer\IO\IOInterface; |
|
8
|
|
|
use Composer\Plugin\PluginInterface; |
|
9
|
|
|
|
|
10
|
|
|
final class Plugin implements PluginInterface, EventSubscriberInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @inheritDoc |
|
14
|
|
|
*/ |
|
15
|
|
|
public static function getSubscribedEvents() |
|
16
|
|
|
{ |
|
17
|
|
|
return [ |
|
18
|
|
|
'post-install-cmd' => ['install'], |
|
19
|
|
|
'post-update-cmd' => ['install'], |
|
20
|
|
|
]; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @inheritDoc |
|
25
|
|
|
*/ |
|
26
|
|
|
public function activate(Composer $composer, IOInterface $io) |
|
27
|
|
|
{ |
|
28
|
|
|
// |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Kick-off the installation. |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public function install(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$source = dirname(__DIR__, 1) . '/resources/stubs'; |
|
39
|
|
|
$dest = dirname(__DIR__, 5) . '/web'; |
|
40
|
|
|
|
|
41
|
|
|
$this->createDirectories($dest); |
|
42
|
|
|
|
|
43
|
|
|
$this->copyFiles($source, $dest); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Create necessary directories. |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $dest |
|
50
|
|
|
* |
|
51
|
|
|
* @return void |
|
52
|
|
|
*/ |
|
53
|
|
|
private function createDirectories(string $dest): void |
|
54
|
|
|
{ |
|
55
|
|
|
mkdir($dest); |
|
56
|
|
|
mkdir($dest . '/content'); |
|
57
|
|
|
mkdir($dest . '/content/mu-plugins'); |
|
58
|
|
|
mkdir($dest . '/content/plugins'); |
|
59
|
|
|
mkdir($dest . '/content/themes'); |
|
60
|
|
|
mkdir($dest . '/content/uploads'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Copy necessary files. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $source |
|
67
|
|
|
* @param string $dest |
|
68
|
|
|
* |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
|
|
private function copyFiles(string $source, string $dest): void |
|
72
|
|
|
{ |
|
73
|
|
|
copy($source . '/index.php.stub', $dest . '/index.php'); |
|
74
|
|
|
copy($source . '/wp-config.php.stub', $dest . '/wp-config.php'); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|