Guest User

Untitled

a guest
Dec 24th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * Expected configuration config.local.neon:
  5. * database:
  6. * dsn: 'mysql:host=127.0.0.1;dbname=hicoriastatus;port=3307' # or without the ;port=XXXX
  7. * user: username
  8. * password: password
  9. *
  10. */
  11.  
  12. $neon = \Nette\Neon\Neon();
  13.  
  14. if (file_exists($configFile = __DIR__ . '/app/config/config.local.neon'))
  15. {
  16. $file = file_get_contents($configFile);
  17. } else {
  18. throw new \Nette\Neon\Exception('File \'config.local.neon\' not found. in ' . $configFile . '.');
  19. }
  20.  
  21. $decoded = $neon->decode($file);
  22.  
  23. $database = isset($decode['database']) ? $decoded['database'] : ['user' => '', 'password' => '', 'dsn' => 'mysql:host=localhost;dbname=database'];
  24.  
  25.  
  26. $tmp = explode(':',$database['dsn']);
  27. $adapter = $tmp[0];
  28. $tmp = explode(';', $tmp[1]);
  29.  
  30. foreach ($tmp as $n)
  31. {
  32. $n = explode('=', $n);
  33. $dsn[$n[0]] = $n[1];
  34. }
  35.  
  36. return [
  37. 'paths' => [
  38. 'migrations' => 'migrations',
  39. 'seeds' => 'migrations/seeds'
  40. ],
  41. 'environments' => [
  42. 'default_migration_table' => '_phinx_log',
  43. 'default_database' => 'production',
  44. 'production' => [
  45. 'adapter' => !empty($adapter) ? $adapter : 'mysql',
  46. 'host' => $dsn['host'],
  47. 'name' => $dsm['dbname'],
  48. 'user' => $database['user'],
  49. 'pass' => $database['password'],
  50. 'port' => !empty($dsn['port']) ? $dsn['port'] : 3306
  51. ]
  52. ]
  53. ];
Add Comment
Please, Sign In to add comment