PHP code example of mcrm / laravel-connection-storage
1. Go to this page and download the library: Download mcrm/laravel-connection-storage library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mcrm / laravel-connection-storage example snippets
use Mcrm\LaravelConnectionStorage\Interfaces\ConnectionDataProviderInterface;
class DatabaseConnectionManager
{
public function __construct(
private ConnectionDataProviderInterface $connectionProvider
) {}
public function getConnection(string $boxName): ?array
{
$connectionData = $this->connectionProvider->getConnectionData($boxName);
if ($connectionData === null) {
return null;
}
return $connectionData->getConnectionConfig('db');
}
}
interface ConnectionDataProviderInterface
{
public function getConnectionData(string $identifier): ?BaseConnectionDataDTO;
public function cacheConnectionData(string $identifier, BaseConnectionDataDTO $connectionData): bool;
}
interface ConnectionCacheServiceInterface
{
public function getConnectionData(string $url): ?BaseConnectionDataDTO;
public function getRawConnectionData(string $url): ?array;
public function cacheConnectionData(string $url, BaseConnectionDataDTO $connectionData): bool;
public function set(string $url, BaseConnectionDataDTO $connectionData, ?int $ttl = null): bool;
public function forget(string $url): bool;
public function remember(string $url, callable $callback, ?int $ttl = null): ?BaseConnectionDataDTO;
}