bootstrap.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. function find_root() {
  3. $root = dirname(__DIR__);
  4. if (is_dir($root . '/vendor/cakephp/cakephp')) {
  5. return $root;
  6. }
  7. $root = dirname(dirname(__DIR__));
  8. if (is_dir($root . '/vendor/cakephp/cakephp')) {
  9. return $root;
  10. }
  11. $root = dirname(dirname(dirname(__DIR__)));
  12. if (is_dir($root . '/vendor/cakephp/cakephp')) {
  13. return $root;
  14. }
  15. }
  16. function find_app() {
  17. if (is_dir(ROOT . '/App')) {
  18. return 'App';
  19. }
  20. if (is_dir(ROOT . '/vendor/cakephp/app/App')) {
  21. return 'vendor/cakephp/app/App';
  22. }
  23. }
  24. define('DS', DIRECTORY_SEPARATOR);
  25. define('ROOT', find_root());
  26. define('APP_DIR', find_app());
  27. define('WEBROOT_DIR', 'webroot');
  28. define('APP', ROOT . DS . APP_DIR . DS);
  29. define('WWW_ROOT', ROOT . DS . WEBROOT_DIR . DS);
  30. define('TESTS', ROOT . DS . 'Test' . DS);
  31. define('TMP', ROOT . DS . 'tmp' . DS);
  32. define('LOGS', TMP . 'logs' . DS);
  33. define('CACHE', TMP . 'cache' . DS);
  34. define('CAKE_CORE_INCLUDE_PATH', ROOT . '/vendor/cakephp/cakephp');
  35. define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
  36. define('CAKE', CORE_PATH . 'src' . DS);
  37. require ROOT . '/vendor/cakephp/cakephp/src/basics.php';
  38. require ROOT . '/vendor/autoload.php';
  39. Cake\Core\Configure::write('App', ['namespace' => 'App']);
  40. Cake\Core\Configure::write('debug', 2);
  41. $TMP = new \Cake\Utility\Folder(TMP);
  42. $TMP->create(TMP . 'cache/models', 0777);
  43. $TMP->create(TMP . 'cache/persistent', 0777);
  44. $TMP->create(TMP . 'cache/views', 0777);
  45. $cache = [
  46. 'default' => [
  47. 'engine' => 'File'
  48. ],
  49. '_cake_core_' => [
  50. 'className' => 'File',
  51. 'prefix' => 'crud_myapp_cake_core_',
  52. 'path' => CACHE . 'persistent/',
  53. 'serialize' => true,
  54. 'duration' => '+10 seconds'
  55. ],
  56. '_cake_model_' => [
  57. 'className' => 'File',
  58. 'prefix' => 'crud_my_app_cake_model_',
  59. 'path' => CACHE . 'models/',
  60. 'serialize' => 'File',
  61. 'duration' => '+10 seconds'
  62. ]
  63. ];
  64. Cake\Cache\Cache::config($cache);
  65. Cake\Core\Plugin::load('Tools', ['path' => './']);
  66. // Ensure default test connection is defined
  67. if (!getenv('db_class')) {
  68. putenv('db_class=Cake\Database\Driver\Sqlite');
  69. putenv('db_dsn=sqlite::memory:');
  70. }
  71. Cake\Datasource\ConnectionManager::config('test', [
  72. 'className' => 'Cake\Database\Connection',
  73. 'driver' => getenv('db_class'),
  74. 'dsn' => getenv('db_dsn'),
  75. 'database' => getenv('db_database'),
  76. 'login' => getenv('db_login'),
  77. 'password' => getenv('db_password'),
  78. 'timezone' => 'UTC',
  79. 'quoteIdentifiers' => true,
  80. ]);