sweetchuck / env-var-storage
@todo project description
1.x-dev
2024-11-06 21:22 UTC
Requires
- php: >=7.4
Requires (Dev)
- ext-json: *
- codeception/codeception: ^4.1
- codeception/module-asserts: ^2.0
- consolidation/robo: ^3.0
- nuvoleweb/robo-config: 3.x-dev
- squizlabs/php_codesniffer: ^3.6
- sweetchuck/git-hooks: 2.x-dev
- sweetchuck/robo-git: 2.x-dev
- sweetchuck/robo-phpcs: 2.x-dev
- sweetchuck/robo-phpmd: 2.x-dev
- symfony/error-handler: ^5.3 || ^6.0
- symfony/filesystem: ^5.0 || ^6.0
This package is auto-updated.
Last update: 2024-11-06 21:22:23 UTC
README
This library provides a wrapper around the \getenv() and \putenv() functions.
Interface
Implementation - real
EnvVarStorage uses the real \getenv() and \putenv() functions to get/set environment variables.
Implementation - dummy
ArrayStorage uses an \ArrayObject instance to store „environment” variables. Use this one for testing purposes.
Service definition
services: env_var_storage: shared: true class: 'Sweetchuck\EnvVarStorage\EnvVarStorage'
Usage
<?php use Sweetchuck\EnvVarStorage\EnvVarStorageInterface; class Foo { protected EnvVarStorageInterface $envVarStorage; public function __construct(EnvVarStorageInterface $envVarStorage) { $this->envVarStorage = $envVarStorage; } public function doSomething(): string { return $this->envVarStorage->get('PATH'); } }
Usage in tests
<?php class FooTest extends \PHPUnit\Framework\TestCase { public function testDoSomething() { $envVarStorage = new \Sweetchuck\EnvVarStorage\ArrayStorage(new \ArrayObject(['PATH' => '/a:/b'])) $foo = new \Foo($envVarStorage); $this->assertSame('/a:/b', $foo->doSomething()); } }