bootstrap.php 2.7 KB

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