1. Go to this page and download the library: Download platformsh/config-reader 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/ */
platformsh / config-reader example snippets
use Platformsh\ConfigReader\Config;
$config = new Config();
if (!$config->isValidPlatform()) {
die("Not in a Platform.sh Environment.");
}
$credentials = $config->credentials('database');
$conn = new \PDO($config->formattedCredentials('database', 'pdo_mysql'), $credentials['username'], $credentials['password'], [
// Always use Exception error mode with PDO, as it's more reliable.
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
// So we don't have to mess around with cursors and unbuffered queries by default.
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE,
// Make sure MySQL returns all matched rows on update queries including
// rows that actually didn't have to be updated because the values didn't
// change. This matches common behavior among other database systems.
\PDO::MYSQL_ATTR_FOUND_ROWS => TRUE,
]);
// Do stuff with the $conn here.
use Platformsh\ConfigReader\Config;
$config = new Config();
if ($config->hasRelationship('database')) {
$creds = $config->credentials('database');
// ...
}
function formatMyService(array $credentials) string
{
return "some string based on $credentials";
}
// Call this in setup.
$config->registerFormatter("my_service", 'formatMyService');
// Then call this method to get the formatted version
$formatted = $config->FormattedCredentials("database", "my_service");
$config->variables();
$config->variable("foo", "default");
$config->getRoute("main");
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.