bootstrap.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. if (!defined('DS')) {
  3. define('DS', DIRECTORY_SEPARATOR);
  4. }
  5. if (!defined('WINDOWS')) {
  6. if (DS == '\\' || substr(PHP_OS, 0, 3) === 'WIN') {
  7. define('WINDOWS', true);
  8. } else {
  9. define('WINDOWS', false);
  10. }
  11. }
  12. define('ROOT', dirname(__DIR__));
  13. define('TMP', ROOT . DS . 'tmp' . DS);
  14. define('LOGS', TMP . 'logs' . DS);
  15. define('CACHE', TMP . 'cache' . DS);
  16. define('APP', sys_get_temp_dir());
  17. define('APP_DIR', 'src');
  18. define('CAKE_CORE_INCLUDE_PATH', ROOT . '/vendor/cakephp/cakephp');
  19. define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
  20. define('CAKE', CORE_PATH . APP_DIR . DS);
  21. define('WWW_ROOT', ROOT . DS . 'webroot' . DS);
  22. define('CONFIG', dirname(__FILE__) . DS . 'config' . DS);
  23. ini_set('intl.default_locale', 'de-DE');
  24. require ROOT . '/vendor/autoload.php';
  25. require CORE_PATH . 'config/bootstrap.php';
  26. Cake\Core\Configure::write('App', [
  27. 'namespace' => 'App',
  28. 'encoding' => 'UTF-8']);
  29. Cake\Core\Configure::write('debug', true);
  30. Cake\Core\Configure::write('Config', [
  31. 'adminEmail' => 'test@example.com',
  32. 'adminName' => 'Mark']);
  33. Cake\Mailer\Email::setConfig('default', ['transport' => 'Debug']);
  34. Cake\Mailer\TransportFactory::setConfig('Debug', [
  35. 'className' => 'Debug'
  36. ]);
  37. mb_internal_encoding('UTF-8');
  38. $Tmp = new Cake\Filesystem\Folder(TMP);
  39. $Tmp->create(TMP . 'cache/models', 0770);
  40. $Tmp->create(TMP . 'cache/persistent', 0770);
  41. $Tmp->create(TMP . 'cache/views', 0770);
  42. $cache = [
  43. 'default' => [
  44. 'engine' => 'File',
  45. 'path' => CACHE
  46. ],
  47. '_cake_core_' => [
  48. 'className' => 'File',
  49. 'prefix' => 'crud_myapp_cake_core_',
  50. 'path' => CACHE . 'persistent/',
  51. 'serialize' => true,
  52. 'duration' => '+10 seconds'
  53. ],
  54. '_cake_model_' => [
  55. 'className' => 'File',
  56. 'prefix' => 'crud_my_app_cake_model_',
  57. 'path' => CACHE . 'models/',
  58. 'serialize' => 'File',
  59. 'duration' => '+10 seconds'
  60. ]
  61. ];
  62. Cake\Cache\Cache::setConfig($cache);
  63. //Cake\Core\Plugin::load('Tools', ['path' => ROOT . DS, 'bootstrap' => true]);
  64. (new Cake\Core\PluginCollection)->add(new Tools\Plugin(['bootstrap' => true]));
  65. // Ensure default test connection is defined
  66. if (!getenv('db_class')) {
  67. putenv('db_class=Cake\Database\Driver\Sqlite');
  68. putenv('db_dsn=sqlite::memory:');
  69. //putenv('db_class=Cake\Database\Driver\Postgres');
  70. //putenv('db_dsn=postgres://postgres@127.0.0.1/test');
  71. }
  72. Cake\Datasource\ConnectionManager::setConfig('test', [
  73. 'className' => 'Cake\Database\Connection',
  74. 'driver' => getenv('db_class') ?: null,
  75. 'dsn' => getenv('db_dsn') ?: null,
  76. 'database' => getenv('db_database') ?: null,
  77. 'username' => getenv('db_username') ?: null,
  78. 'password' => getenv('db_password') ?: null,
  79. 'timezone' => 'UTC',
  80. 'quoteIdentifiers' => true,
  81. 'cacheMetadata' => true,
  82. ]);