bootstrap.php 3.0 KB

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