bootstrap.php 3.0 KB

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