Enqueue is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and our customers. If you'd like to join them, please consider:
The enqueue/dsn tool helps to parse DSN\URI string. The tool is used by Enqueue transports to parse DSNs.
composer req enqueue/dsn 0.9.x
Basic usage:
<?php
use Enqueue\Dsn\Dsn;
$dsn = new Dsn('mysql+pdo://user:password@localhost:3306/database?connection_timeout=123');
$dsn->getSchemeProtocol(); // 'mysql'
$dsn->getScheme(); // 'mysql+pdo'
$dsn->getSchemeExtensions(); // ['pdo']
$dsn->getUser(); // 'user'
$dsn->getPassword(); // 'password'
$dsn->getHost(); // 'localhost'
$dsn->getPort(); // 3306
$dsn->getQueryString(); // 'connection_timeout=123'
$dsn->getQuery(); // ['connection_timeout' => '123']
$dsn->getQueryParameter('connection_timeout'); // '123'
$dsn->getInt('connection_timeout'); // 123
Some parts could be omitted:
<?php
use Enqueue\Dsn\Dsn;
$dsn = new Dsn('sqs:?key=aKey&secret=aSecret&token=aToken');
$dsn->getSchemeProtocol(); // 'sqs'
$dsn->getScheme(); // 'sqs'
$dsn->getSchemeExtensions(); // []
$dsn->getUser(); // null
$dsn->getPassword(); // null
$dsn->getHost(); // null
$dsn->getPort(); // null
$dsn->getQueryParameter('key'); // 'aKey'
$dsn->getQueryParameter('secret'); // 'aSecret'
Throws exception if DSN not valid:
<?php
use Enqueue\Dsn\Dsn;
$dsn = new Dsn('foo'); // throws exception here
Throws exception if cannot cast query parameter:
<?php
use Enqueue\Dsn\Dsn;
$dsn = new Dsn('mysql:?connection_timeout=notInt');
$dsn->getInt('connection_timeout'); // throws exception here