PageRenderTime 1ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 10ms app.codeStats 0ms

/scripts/setup.php

https://github.com/studio-v/nano
PHP | 47 lines | 38 code | 9 blank | 0 comment | 4 complexity | a3c3b984fa4b2f796c84401a038e9187 MD5 | raw file
 1<?php
 2
 3function fromTo($from, $to) {
 4	echo "\t", sprintf('%-20s', $from), ' => ', $to, PHP_EOL;
 5}
 6
 7echo 'Setting up', PHP_EOL;
 8$root = realPath(__DIR__ . '/../application/settings') . DIRECTORY_SEPARATOR;
 9$env  = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'dev';
10fromTo('env.php', $root . 'env.php');
11file_put_contents($root . 'env.php', '<?php $config = \'' . $env . '\';');
12
13require dirName(__DIR__) . '/library/Nano.php';
14
15$files = array(
16	  'db.php'        => 'db.php'
17	, 'log.php'       => 'log.php'
18	, 'selenium.php'  => 'selenium.php'
19	, 'web.php'       => 'web.php'
20	, 'assets.php'    => 'assets.php'
21	, 'plugins.php'   => 'plugins.php'
22);
23
24$source = __DIR__ . '/setup/' . $env;
25
26if (file_exists($source)) {
27	foreach ($files as $from => $to) {
28		$sourceFile      = $source . DS . $from;
29		$destinationDir  = realPath(dirName($root . $to));
30		$destinationFile = $destinationDir . DS . baseName($to);
31		if (file_exists($sourceFile)) {
32			fromTo($from, $destinationFile);
33			copy($sourceFile, $destinationFile);
34		}
35	}
36}
37echo 'Done', PHP_EOL;
38
39if (file_exists($source . '.php')) {
40	include($source . '.php');
41
42	if (function_exists('setupEnv')) {
43		setupEnv();
44	}
45}
46
47Nano::reloadConfig();