Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. *
  5. *
  6. * Spouštět pomocí ./phinx.sh nebo pomocí php vendor/bin/phinx
  7. *
  8. * Obsah souboru ./phinx.sh:
  9. * #!/bin/bash
  10. * php vendor/bin/phinx $@
  11. *
  12. *
  13. */
  14.  
  15. define ('DSN_REGEX', '/^((?P<driver>\w+):\/\/)?((?P<user>\w+)?(:(?P<password>\w+))?@)?((?P<adapter>\w+):)?((host=(?P<host>[\w-\.]+))|(unix_socket=(?P<socket_file>[\w\/\.]+)))(:(?P<port>\d+))?((;dbname=|\/)(?P<database>[\w\-]+))?$/Uim');
  16.  
  17. /**
  18. * Očekává konfigurační soubor se strukturou:
  19. * nette:
  20. * database:
  21. * dsn: 'mysql:host=mysql-server;dbname=databaze'
  22. * user: 'uzivatel'
  23. * password: 'heslo'
  24. * options:
  25. * lazy: yes
  26. *
  27. * Případně pouze:
  28. * nette:
  29. * database:
  30. * dsn: 'uzivatel:heslo@mysql:host=mysql-server:3306;dbname=databaze'
  31. *
  32. */
  33. $neon = new \Nette\Neon\Neon();
  34.  
  35. if (file_exists($configFile = __DIR__ . '/app/config/config.local.neon')) {
  36. $file = file_get_contents($configFile);
  37. } else {
  38. throw new Nette\Neon\Exception('File \'config.local.neon\' not found in ' . $configFile . '.');
  39. }
  40.  
  41. $decoded = $neon->decode($file);
  42.  
  43. $database = isset($decoded['nette']['database']) ? $decoded['nette']['database'] : ['user' => '', 'password' => '', 'dsn' => 'mysql:host=localhost;dbname=database'];
  44.  
  45. preg_match(DSN_REGEX, $database['dsn'], $dsn);
  46.  
  47. return [
  48. 'paths' => [
  49. 'migrations' => 'migrations'
  50. ],
  51. 'environments' => [
  52. 'default_migration_table' => '_phinx_log',
  53. 'default_database' => 'production',
  54. 'production' => [
  55. 'adapter' => !empty($dsn['adapter']) ? $dsn['adapter'] : 'mysql',
  56. 'host' => $dsn['host'],
  57. 'name' => $dsn['database'],
  58. 'user' => !empty($dsn['user']) ? $dsn['user'] : $database['user'],
  59. 'pass' => !empty($dsn['password']) ? $dsn['password'] : $database['password']
  60. ],
  61. ]
  62. ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement