PHP code example of utopia-php / config

1. Go to this page and download the library: Download utopia-php/config 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/ */

    

utopia-php / config example snippets




topia\Config\Parser\JSON;
use Utopia\Config\Attribute\Key;
use Utopia\Config\Config;
use Utopia\Config\Exception\Load;
use Utopia\Config\Exception\Parse;
use Utopia\Config\Source\File;
use Utopia\Validator\ArrayList;
use Utopia\Validator\Integer;
use Utopia\Validator\JSON as JSONValidator;
use Utopia\Validator\Nullable;
use Utopia\Validator\Text;

class DatabaseConfig
{
    #[Key('db.host', new Text(length: 1024),    * @var array<string, mixed> $config
     */
    #[Key('db.config', new Nullable(new JSONValidator),  $err->getMessage());
}

\var_dump($config);
// $config->host
// $config->port
// $config->username
// ...




opia\Config\Attribute\Key;
use Utopia\Config\Config;
use Utopia\Config\Source\Variable;
use Utopia\Config\Parser\None;
use Utopia\Validator\Whitelist;

class FirewallConfig
{
    #[Key('security-level', new Whitelist('high', 'low'), 


class FirewallConfig
{
    /**
     * @var array<string> $allowIps
     */
    #[Key('ALLOW_IPS', new ArrayList(new Text(length: 100), length: 100), tialsConfig
{
    #[Key('DATABASE_PASSWORD', new Text(length: 1024), : true)]
    public int $abuseHits;
    
    #[Key('RATE_LIMIT_SECONDS', new Integer(loose: true), rewall.json'), new JSON(), FirewallConfig::class),
    'credentials' => Config::load(new File('credentials.yml'), new YAML(), CredentialsConfig::class),
    'environment' => Config::load(new File('.env'), new Dotenv(), EnvironmentConfig::class),
  ]),
  new None(),
  AppConfig::class
);

\var_dump($config);
// $config->firewall->allowIps
// $config->credentials->dbPass
// $config->environment->abuseHits



use Utopia\Config\Config;
use Utopia\Config\Source\Environment;
use Utopia\Config\Parser\None;

class CredentialsConfig
{
    #[Key('DATABASE_PASSWORD', new Text(length: 1024), e(), CredentialsConfig::class);

\var_dump($config);
// $config->dbPass
// $config->$cachePass