PHP code example of marvin255 / data-getter-helper
1. Go to this page and download the library: Download marvin255/data-getter-helper 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/ */
marvin255 / data-getter-helper example snippets
use Marvin255\DataGetterHelper\DataGetterHelper;
$data = [
'user' => [
'name' => 'John Doe',
'email' => '[email protected]',
],
];
// Extract with default value
$name = DataGetterHelper::string('user.name', $data); // 'John Doe'
$phone = DataGetterHelper::string('user.phone', $data, ''); // ''
// Require the value (throws exception if not found)
$email = DataGetterHelper::
use Marvin255\DataGetterHelper\DataGetterHelper;
class User {
public function __construct(public string $name) {}
}
$user = new User('John');
$data = ['current_user' => $user];
// Extract object of specific class
$currentUser = DataGetterHelper::objectOf('current_user', $data, User::class);
use Marvin255\DataGetterHelper\DataGetterHelper;
$data = [
'config' => [
'settings' => [
'theme' => 'dark',
'version' => 2,
],
],
];
// Get any value
$theme = DataGetterHelper::get('config.settings.theme', $data); // 'dark'
$unknown = DataGetterHelper::get('config.unknown', $data, 'fallback'); // 'fallback'
use Marvin255\DataGetterHelper\DataGetterHelper;
class Config {
public array $database = ['host' => 'localhost'];
}
$config = new Config();
$host = DataGetterHelper::string('database.host', $config); // 'localhost'
use Marvin255\DataGetterHelper\DataGetterHelper;
use Marvin255\DataGetterHelper\DataGetterException;
try {
$value = DataGetterHelper::
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.