PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms 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. function fromTo($from, $to) {
  3. echo "\t", sprintf('%-20s', $from), ' => ', $to, PHP_EOL;
  4. }
  5. echo 'Setting up', PHP_EOL;
  6. $root = realPath(__DIR__ . '/../application/settings') . DIRECTORY_SEPARATOR;
  7. $env = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'dev';
  8. fromTo('env.php', $root . 'env.php');
  9. file_put_contents($root . 'env.php', '<?php $config = \'' . $env . '\';');
  10. require dirName(__DIR__) . '/library/Nano.php';
  11. $files = array(
  12. 'db.php' => 'db.php'
  13. , 'log.php' => 'log.php'
  14. , 'selenium.php' => 'selenium.php'
  15. , 'web.php' => 'web.php'
  16. , 'assets.php' => 'assets.php'
  17. , 'plugins.php' => 'plugins.php'
  18. );
  19. $source = __DIR__ . '/setup/' . $env;
  20. if (file_exists($source)) {
  21. foreach ($files as $from => $to) {
  22. $sourceFile = $source . DS . $from;
  23. $destinationDir = realPath(dirName($root . $to));
  24. $destinationFile = $destinationDir . DS . baseName($to);
  25. if (file_exists($sourceFile)) {
  26. fromTo($from, $destinationFile);
  27. copy($sourceFile, $destinationFile);
  28. }
  29. }
  30. }
  31. echo 'Done', PHP_EOL;
  32. if (file_exists($source . '.php')) {
  33. include($source . '.php');
  34. if (function_exists('setupEnv')) {
  35. setupEnv();
  36. }
  37. }
  38. Nano::reloadConfig();