bootstrap.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. error_reporting( E_ALL | E_STRICT );
  3. // change this, if your php files and data is outside of your webservers document root
  4. if (!defined('PATH')) define('PATH', '..' . DIRECTORY_SEPARATOR);
  5. if (!defined('PUBLIC_PATH')) define('PUBLIC_PATH', '..');
  6. require PATH . 'lib/auto.php';
  7. class helper
  8. {
  9. /**
  10. * delete directory and all its contents recursively
  11. *
  12. * @param string $path
  13. * @throws Exception
  14. */
  15. public static function rmdir($path)
  16. {
  17. $path .= DIRECTORY_SEPARATOR;
  18. $dir = dir($path);
  19. while(false !== ($file = $dir->read())) {
  20. if($file != '.' && $file != '..') {
  21. if(is_dir($path . $file)) {
  22. self::rmdir($path . $file);
  23. } elseif(is_file($path . $file)) {
  24. if(!@unlink($path . $file)) {
  25. throw new Exception('Error deleting file "' . $path . $file . '".');
  26. }
  27. }
  28. }
  29. }
  30. $dir->close();
  31. if(!@rmdir($path)) {
  32. throw new Exception('Error deleting directory "' . $path . '".');
  33. }
  34. }
  35. /**
  36. * create ini file
  37. *
  38. * @param string $pathToFile
  39. * @param array $values
  40. */
  41. public static function createIniFile($pathToFile, $values)
  42. {
  43. if (count($values)) {
  44. @unlink($pathToFile);
  45. $ini = fopen($pathToFile, 'a');
  46. foreach ($values as $section => $options) {
  47. fwrite($ini, "[$section]" . PHP_EOL);
  48. foreach($options as $option => $setting) {
  49. if (is_null($setting)) {
  50. continue;
  51. } elseif (is_string($setting)) {
  52. $setting = '"' . $setting . '"';
  53. } else {
  54. $setting = var_export($setting, true);
  55. }
  56. fwrite($ini, "$option = $setting" . PHP_EOL);
  57. }
  58. fwrite($ini, PHP_EOL);
  59. }
  60. fclose($ini);
  61. }
  62. }
  63. /**
  64. * a var_export that returns arrays without line breaks
  65. * by linus@flowingcreativity.net via php.net
  66. *
  67. * @param mixed $var
  68. * @param bool $return
  69. * @return void|string
  70. */
  71. public static function var_export_min($var, $return = false)
  72. {
  73. if (is_array($var)) {
  74. $toImplode = array();
  75. foreach ($var as $key => $value) {
  76. $toImplode[] = var_export($key, true) . ' => ' . self::var_export_min($value, true);
  77. }
  78. $code = 'array(' . implode(', ', $toImplode) . ')';
  79. if ($return) {
  80. return $code;
  81. } else {
  82. echo $code;
  83. }
  84. } else {
  85. return var_export($var, $return);
  86. }
  87. }
  88. }