PHPackages                             jc-it/yii2-secrets - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jc-it/yii2-secrets

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jc-it/yii2-secrets
==================

Secrets storage and extractor for Yii2

v1.0.0(4y ago)040MITPHPPHP &gt;=8.0

Since Jan 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/JC-IT/yii2-secrets)[ Packagist](https://packagist.org/packages/jc-it/yii2-secrets)[ RSS](/packages/jc-it-yii2-secrets/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (12)Versions (2)Used By (0)

Secrets storage and extractor
=============================

[](#secrets-storage-and-extractor)

[![codecov](https://camo.githubusercontent.com/920a12bc2327cc39177b3496c1e729c44fd72f0e9ba3e5f3cc508cd2c3fb7bf3/68747470733a2f2f636f6465636f762e696f2f67682f6a632d69742f796969322d736563726574732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/jc-it/yii2-secrets)[![Continous integration](https://github.com/jc-it/yii2-secrets/actions/workflows/ci.yaml/badge.svg)](https://github.com/jc-it/yii2-secrets/actions/workflows/ci.yaml)[![Packagist Total Downloads](https://camo.githubusercontent.com/f06a31c13cd65441fa41a2cce2508d9fab809443a7dd5b37a47d530aaca303f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a632d69742f796969322d73656372657473)](https://camo.githubusercontent.com/f06a31c13cd65441fa41a2cce2508d9fab809443a7dd5b37a47d530aaca303f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a632d69742f796969322d73656372657473)[![Packagist Monthly Downloads](https://camo.githubusercontent.com/9898dddd5db41dd2eaf606afee43a29097c777a152c497e076c5be344a473248/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a632d69742f796969322d73656372657473)](https://camo.githubusercontent.com/9898dddd5db41dd2eaf606afee43a29097c777a152c497e076c5be344a473248/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a632d69742f796969322d73656372657473)[![GitHub tag (latest by date)](https://camo.githubusercontent.com/4e11cfdc00f98f11165afd60499b35d31eebc485a01fe51419d5cbb9ea7afc53/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6a632d69742f796969322d73656372657473)](https://camo.githubusercontent.com/4e11cfdc00f98f11165afd60499b35d31eebc485a01fe51419d5cbb9ea7afc53/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6a632d69742f796969322d73656372657473)[![Packagist Version](https://camo.githubusercontent.com/6e70b19c5556278420fc54f113eec4d8d4800bab70ffac9cf0936cc6f0942826/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a632d69742f796969322d73656372657473)](https://camo.githubusercontent.com/6e70b19c5556278420fc54f113eec4d8d4800bab70ffac9cf0936cc6f0942826/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a632d69742f796969322d73656372657473)

This extension provides secret storage and extractor for Yii2.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ composer require jc-it/yii2-secrets
```

or add

```
"jc-it/yii2-secrets": "^"

```

to the `require` section of your `composer.json` file.

Configuration
-------------

[](#configuration)

### Secrets

[](#secrets)

It is recommended to use this package only in configuration files before your application is loaded, this way they won't be dumped by your application on chrashes or something unexpected.

```
$secrets = new \JCIT\secrets\SecretsService(
    new \JCIT\secrets\storages\Chained(
        new \JCIT\secrets\storages\Cache(getenv()),
        new \JCIT\secrets\storages\Json('/run/env.json'),
        new \JCIT\secrets\storages\Filesystem(__DIR__ . '/secrets'),
    )
);
```

Note that the order in the `Chained` storage does matter, wherever a secret is found first that value will be returned.

### Secret extraction

[](#secret-extraction)

When deploying a new environment it can be a hassle finding out what all secrets are to be configured. This package contains a console command to extract the secret usages.

- Create an action in a console controller ```
      class SecretsController extends Controller
      {
          public function actions(): array
          {
              return [
                  'extract' => [
                      'class' => Extract::class,
                      'calls' => ['$secrets->get', '$secrets->getAndThrowOnNull'],
                      'sourcePath' => '@app/',
                  ],
              ];
          }
      }
    ```
- In dependency injection add the storage (which should only be used for the extract command) ```
    ...
    'container' => [
        'definitions' => [
            \JCIT\secrets\interfaces\StorageInterface::class => function() {
                return new \JCIT\secrets\storages\Filesystem(__DIR__ . '/../../../secrets')
            }
        ]
    ],
    ```

Credits
-------

[](#credits)

- [Joey Claessen](https://github.com/joester89)
- [Yii2 Framework](https://github.com/yiisoft/yii2/blob/master/framework/console/controllers/MessageController.php) for the extraction part

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1580d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/88359ebe0456645a614e563dfbf0dd025b69ef57221050cb9eb31e3eef4dd0f9?d=identicon)[joester89](/maintainers/joester89)

---

Top Contributors

[![joester89](https://avatars.githubusercontent.com/u/9624366?v=4)](https://github.com/joester89 "joester89 (7 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jc-it-yii2-secrets/health.svg)

```
[![Health](https://phpackages.com/badges/jc-it-yii2-secrets/health.svg)](https://phpackages.com/packages/jc-it-yii2-secrets)
```

###  Alternatives

[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
