Bootstrap.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. use \ThurData\Servers\KerioEmail\Core\ModuleConstants;
  3. use \ThurData\Servers\KerioEmail\Core\ServiceLocator;
  4. use \ThurData\Servers\KerioEmail\Core\FileReader\PathValidator;
  5. use \ThurData\Servers\KerioEmail\Core\FileReader\File;
  6. use \ThurData\Servers\KerioEmail\Core\DependencyInjection\Builder;
  7. use \ThurData\Servers\KerioEmail\Core\DependencyInjection\Services;
  8. if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
  9. if (!defined('PS')) define('PS', PATH_SEPARATOR);
  10. if (!defined('CRLF')) define('CRLF', "\r\n");
  11. require_once dirname(__DIR__) . DS . "vendor" . DS . "autoload.php";
  12. /**
  13. * Initialize base values
  14. */
  15. ModuleConstants::initialize();
  16. /**
  17. * Initailize DI builder
  18. */
  19. new Builder();
  20. /**
  21. * Initialize Services
  22. */
  23. new Services();
  24. /**
  25. * Check file permission
  26. */
  27. if (is_dir(ModuleConstants::getFullPath('storage')) === false
  28. || is_writable(ModuleConstants::getFullPath('storage')) === false
  29. || is_writable(ModuleConstants::getFullPath('storage', 'app')) === false
  30. || is_writable(ModuleConstants::getFullPath('storage', 'crons')) === false
  31. || is_writable(ModuleConstants::getFullPath('storage', 'logs')) === false)
  32. {
  33. File::createPaths(
  34. ['full' => ModuleConstants::getFullPath('storage'), 'permission' => 0777],
  35. ['full' => ModuleConstants::getFullPath('storage', 'app'), 'permission' => 0777],
  36. ['full' => ModuleConstants::getFullPath('storage', 'crons'), 'permission' => 0777],
  37. ['full' => ModuleConstants::getFullPath('storage', 'logs'), 'permission' => 0777]
  38. );
  39. }
  40. $pathValidator = new PathValidator();
  41. if (!$pathValidator->validatePath(ModuleConstants::getFullPath('storage', 'logs'), true, true, true))
  42. {
  43. ServiceLocator::call('errorManager')->addError(
  44. 'Bootstrap',
  45. PHP_EOL . ServiceLocator::call('lang')->absoluteT('permissionsStorage'),
  46. ['path' => ModuleConstants::getFullPath('storage')]
  47. );
  48. }