PHPackages                             metarush/getter - 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. metarush/getter

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

metarush/getter
===============

Generate a class with getter methods from a yaml or env file

v3.4.1(5mo ago)11541MITPHPPHP &gt;=7.1

Since Jun 2Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/metarush/getter)[ Packagist](https://packagist.org/packages/metarush/getter)[ RSS](/packages/metarush-getter/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (3)Versions (19)Used By (1)

metarush/getter
===============

[](#metarushgetter)

Generate a class with getter methods from a `yaml` or `env` file. This is useful if you want to access variables in `yaml`/`env` files as PHP getter methods.

Install
-------

[](#install)

Install via composer as `metarush/getter`

Sample usage
------------

[](#sample-usage)

The following will generate a class named `MyNewClass` from contents of `foo/sample.yaml` using `yaml` adapter. The generated class will be saved in `foo/` folder.

### via CLI

[](#via-cli)

`vendor/metarush/getter/bin/generate -a yaml -c MyNewClass -s tests/unit/samples/sample.yaml -l foo/`

### via PHP script

[](#via-php-script)

```
(new \MetaRush\Getter\Generator)
    ->setAdapter('yaml')
    ->setClassName('MyNewClass')
    ->setSourceFile('foo/sample.yaml')
    ->setLocation('foo/')
    ->generate();
```

### Sample `yaml` content

[](#sample-yaml-content)

E.g., located in `foo/sample.yaml`

```
stringVar: 'foo'
intVar: 9
floatVar: 2.1
boolVar: true
arrayVar:
  - foo
  - 1.3

```

### Sample generated class

[](#sample-generated-class)

E.g., located in `foo/MyNewClass.php`

```
