Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Like class is single, specify DIRECTIVE seems not be mandatory
- */
- class Single extends ObjectivePHP\Config\SingleValueDirective {}
- $config->import(new Single('x'))
- ->import(new Single('y'));
- $config->get(Single::class) == "y";
- /* ************************************************ */
- class DbConf extends ObjectivePHP\Config\ObjectValueDirectiveGroup
- {
- const host = 'string';
- const port = 'int';
- const username = 'string';
- const password = 'string';
- const dbname = 'string';
- public function toDsn()
- {
- return 'pgsql:host=' . $this->host
- . ';port=' . $this->port
- . ';dbname=' . $this->dbname
- . ';user=' . $this->username
- . ';password=' . $this->password
- ;
- }
- }
- $config->import(new DbConf('dev', 'host', 'localhost'));
- ->import(new DbConf('dev', 'port', 5432));
- ->import(new DbConf('dev', 'dbname', 'myDb'));
- ->import(new DbConf('dev', 'user', 'foo'));
- ->import(new DbConf('dev', 'password', 'bar'));
- $config->get(DbConf::class . '.dev', 'host') === 'localhost';
- $dbConfDev = $config->subset(DbConf::class . '.dev')->toObject();
- $dbConfDev->host === 'localhost';
- $dbConfDev->port === 5432;
- $dbConfDev->toDsn() === 'pgsql:host=localhost;port=5432;dbname=myDb;user=foo;password=bar';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement