-
Notifications
You must be signed in to change notification settings - Fork 4
/
Install.php
56 lines (45 loc) · 1.72 KB
/
Install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Marvin\Marvin;
use Composer\Installer\PackageEvent;
class Install
{
public static function postPackageInstall(PackageEvent $event)
{
$installedPackage = $event->getOperation()->getPackage();
if ($installedPackage->getName() != 'marvin/marvin') {
return false;
}
$config = require 'config.php';
// Copy web dir
self::copy(__DIR__ ."/Web", $config['web_dir']);
// Create app/ folder
if (file_exists($config['app_dir']) === false) {
mkdir($config['app_dir'], 0755);
}
// Create app/config.php to allow installation
$appConfig = $config['app_dir'] .'/config.php';
if (file_exists($appConfig) === false) {
$fp = fopen($appConfig, 'w');
fwrite($fp, '<?php
$app["debug"] = true;
$config["website"]["name"] = "Marvin";
$config["website"]["description"] = "Marvin is a micro CMS for PHP 5.3";
$config["website"]["url"] = "http://marvin.linkesch.sk";
');
fclose($fp);
}
}
public static function copy($source, $dest)
{
if (!file_exists($dest)) {
mkdir($dest, 0755, true);
}
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
if ($item->isDir() && file_exists($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()) === false) {
mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
} elseif ($item->isFile()) {
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
}
}
}
}