Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
/ dsn Public archive

DSN Parser for 12 factor apps

License

Notifications You must be signed in to change notification settings

andreyors/dsn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dsn (data source name)

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