2017 © Pedro Peláez
 

library dsn

A utility for parsing and generating service DSNs

image

ad7six/dsn

A utility for parsing and generating service DSNs

  • Saturday, March 28, 2015
  • by AD7six
  • Repository
  • 2 Watchers
  • 15 Stars
  • 109,090 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 8 Forks
  • 6 Open issues
  • 8 Versions
  • 11 % Grown

The README.md

PHP DSN #ARCHIVED

A utility for parsing and generating service DSNs, (*1)

What is a DSN?

A data source name (DSN) is a string which defines how to connect to a service. Since it's a string, it's portable, not language or implementation dependent and anything capable of parsing it can know how to connect to the service it points at., (*2)

What does this repo do?

This repo only provides a means of converting a DSN string into an array and vice versa., (*3)

Wrapper classes?

When using a wrapper class, this repo provides an array in the format expected by a particular consumer. So for example, the CakePHP wrapper classes provide arrays in the format the framework understands for a given DSN string., (*4)

Basic usage

The main dsn class implements a parse function which returns a dsn instance:, (*5)

use \AD7six\Dsn\Dsn;

$url = $_ENV['SOME_SERVICE_URL'];
$dsn = Dsn::parse($url);

The class of the returned object is dependent upon the scheme of the service url, for example:, (*6)

// $dsn is an instance of \AD7six\Dsn\Db\MysqlDsn;
$dsn = Dsn::parse('mysql://host/dbname');

// $dsn is an instance of \AD7six\Dsn\Db\SqliteDsn;
$dsn = Dsn::parse('sqlite:///path/to/name.db');

For unknown schemes - the an instance of the called class is returned. This also means that a more specific instance can be obtained by using a less-generic class where appropriate:, (*7)

// $dsn is an instance of \AD7six\Dsn\Dsn;
$dsn = Dsn::parse('newdb://host/dbname');

// $dsn is an instance of \AD7six\Dsn\DbDsn;
$dsn = DbDsn::parse('newdb://host/dbname');

In all of the above cases, the returned instance is the "raw" dsn data:, (*8)

// $dsn is an instance of \AD7six\Dsn\Db\MysqlDsn;
$dsn = Dsn::parse('mysql://host/dbname');

$dsn->toArray();
[
    'scheme' => 'mysql',
    'host' => 'host',
    'port' => 3306,
    'database' => 'dbname'
]

If the behavior of the raw dsn needs to be modified - use a wrapper implementation, (*9)

References

[12 factor applications][1], (*10)

The Versions

28/03 2015

0.4.0

0.4.0.0

A utility for parsing and generating service DSNs

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

26/03 2015

dev-master

9999999-dev

A utility for parsing and generating service DSNs

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

31/05 2014

0.3.1

0.3.1.0

A utility for parsing and generating service DSNs

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

26/03 2014

0.3.0

0.3.0.0

A utility for parsing and generating service DSNs

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

15/03 2014

0.2.1

0.2.1.0

A utility for parsing and generating service DSNs

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

15/03 2014

0.2.0

0.2.0.0

A utility for parsing and generating service DSNs

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

14/03 2014

dev-feature/versioned-wrappers

dev-feature/versioned-wrappers

A utility for parsing and generating service DSNs

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

04/02 2014

0.1.0

0.1.0.0

A utility for parsing and generating service DSNs

  Sources   Download

MIT

The Requires

  • php >=5.4.0