This package is abandoned and no longer maintained. No replacement package was suggested.

DSN (Data Source Name) Parser

0.2.2 2023-08-11 09:33 UTC

This package is not auto-updated.

Last update: 2024-03-03 02:28:35 UTC


README

Latest Stable Version Build Status Downloads codecov Deps License M score PHP 7 ready

A DSN Parser for 12 factor apps

Getting started

Prerequisites

  • Composer

Supported

  • MySQL DSN
  • PostgreSQL DSN
  • Redis DSN
  • FTP and SFTP DSN

Installing

composer require andreyors/dsn

Usage

<?php

if (!isset($_ENV['APP_ENV'])) { // Production must have env vars provided via /etc/environment
    (new Symfony\Component\Dotenv\Dotenv())
        ->load(__DIR__ . '/.env');
}

$dsn = \AndreyOrs\Dsn::parse($_ENV['SYNCAPP_URL']);

return [
    'migration_dirs' => [
        'migrations' => __DIR__.'/config/db/migrations',
    ],
    'environments' => [
        'local' => [
            'adapter' => $dsn['adapter'] ?: '',
            'host' => $dsn['host'] ?: '',
            'username' => $dsn['user'] ?: '',
            'password' => $dsn['pass'] ?: '',
            'db_name' => $dsn['name'] ?: '',
            'charset' => 'utf8mb4',
        ],
    ],
];

Tests

composer test

License

This library is released under the MIT license.

More resources