PHP code example of re2bit / yii2-secrets

1. Go to this page and download the library: Download re2bit/yii2-secrets 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/ */

    

re2bit / yii2-secrets example snippets


      'components' => [
          'cache' => [
              'class' => 'yii\caching\FileCache',
          ],
          'vault' => [
              'class' => 'Re2bit\Yii2Secrets\Vault',
          ],
      ],
      'container' => [
          'definitions' => [
              'Re2bit\Yii2Secrets\Vault' => [
                  'keysDir' => '@app/config/secrets', // adjust the path as needed
              ],
          ],
      ],
      

      $vault = new Vault(['keysDir' => __DIR__ . '/config/secrets']);
      $configDecryptAdapter = new ConfigDecryptAdapter($vault);
      $configDecryptAdapter->parse($config);
      

$config = [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=mydatabase',
            'username' => '%vault(DB_USERNAME)%',
            'password' => '%vault(DB_PASSWORD)%',
        ],
    ],
];