New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

ngabor84/laravel-dbconnstring-parser

Small service to parse database connection string into parts
3,147 1
Install
composer require ngabor84/laravel-dbconnstring-parser
Latest Version:2.0.0
PHP:^8.0
Laravel:10
Older releases:5 · 6 · 8 · 9
License:MIT
Last Updated:Jun 9, 2023
Links: GitHub  ·  Packagist
Maintainer: ngabor84

GitHub license

Database Connection String Parser

Small service to parse database connection string into parts.

About

This package allows you to parse database connection string into parts.

Installation

Require the ngabor84/laravel-dbconnstring-parser package in your composer.json and update your dependencies:

composer require ngabor84/laravel-dbconnstring-parser

Usage with Laravel

Add the service provider to the providers array in the config/app.php config file as follows:

'providers' => [
    ...
    \Service\Database\ConnectionStringParser\Providers\ServiceProvider::class,
]

In your database config file you can use it like this:

$connection = ConnectionStringParser::parse(env('DATABASE_URL'));

return [
    'default' => 'pgsql',
    'connections' => [
        'pgsql' => [
            'driver' => 'pgsql',
            'host' => $connection->getHost(),
            'username' => $connection->getUserName(),
            'password' => $connection->getPassword(),
            'port' => $connection->getPort(),
            'database' => $connection->getDatabase(),
            'charset' => 'utf8',
            'options' => array(
                PDO::ATTR_PERSISTENT => true
            )
        ]
    ]
];

Usage with Lumen

Add the following snippet to the bootstrap/app.php file under the providers section as follows:

// uncomment this line to enable Facades
$app->withFacades();
...
$app->register(\Service\Database\ConnectionStringParser\Providers\ServiceProvider::class);

In your database config file you can use it like this:

$connection = ConnectionStringParser::parse(env('DATABASE_URL'));

return [
    'default' => 'pgsql',
    'connections' => [
        'pgsql' => [
            'driver' => 'pgsql',
            'host' => $connection->getHost(),
            'username' => $connection->getUserName(),
            'password' => $connection->getPassword(),
            'port' => $connection->getPort(),
            'database' => $connection->getDatabase(),
            'charset' => 'utf8',
            'options' => array(
                PDO::ATTR_PERSISTENT => true
            )
        ]
    ]
];

Related Packages

rlacerda83/query-parser

Query parser for lumem

5,008 20
shiftonelabs/laravel-db-events

Add extra database events.

9,317 2
shangjinglong/dictionary

A toolkit that generates a database dictionary package for the Laravel and Lumen...

58 2
phabloraylan/lumen-middleware-trim-or-convert-strings

Dealing with Spaces in Form Inputs using Middleware in Lumen.

51,461 4
butschster/cycle-orm

Cycle ORM integration for the Laravel Framework

64 34

Version History

Version Released PHP Laravel License
2.0.0 ^8.0 ^v10.13 MIT
1.0.0 ^8.0 ^v9.11 MIT
0.3.1 ^7.3|^8.0 ^v8.36 MIT
0.3.0 ^7.3|^8.0 ^v8.36 MIT
0.2.1 ^7.3 ^6.6 MIT