Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Like class is single, specify DIRECTIVE seems not be mandatory
  5. */
  6. class Single extends ObjectivePHP\Config\SingleValueDirective {}
  7.  
  8. $config->import(new Single('x'))
  9. ->import(new Single('y'));
  10. $config->get(Single::class) == "y";
  11.  
  12.  
  13. /* ************************************************ */
  14.  
  15. class DbConf extends ObjectivePHP\Config\ObjectValueDirectiveGroup
  16. {
  17. const host = 'string';
  18. const port = 'int';
  19. const username = 'string';
  20. const password = 'string';
  21. const dbname = 'string';
  22.  
  23. public function toDsn()
  24. {
  25. return 'pgsql:host=' . $this->host
  26. . ';port=' . $this->port
  27. . ';dbname=' . $this->dbname
  28. . ';user=' . $this->username
  29. . ';password=' . $this->password
  30. ;
  31. }
  32. }
  33.  
  34. $config->import(new DbConf('dev', 'host', 'localhost'));
  35. ->import(new DbConf('dev', 'port', 5432));
  36. ->import(new DbConf('dev', 'dbname', 'myDb'));
  37. ->import(new DbConf('dev', 'user', 'foo'));
  38. ->import(new DbConf('dev', 'password', 'bar'));
  39.  
  40. $config->get(DbConf::class . '.dev', 'host') === 'localhost';
  41.  
  42. $dbConfDev = $config->subset(DbConf::class . '.dev')->toObject();
  43. $dbConfDev->host === 'localhost';
  44. $dbConfDev->port === 5432;
  45. $dbConfDev->toDsn() === 'pgsql:host=localhost;port=5432;dbname=myDb;user=foo;password=bar';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement