PHPackages                             new-inventor/property-bag - 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. new-inventor/property-bag

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

new-inventor/property-bag
=========================

Property bag with automatic value normalizing and formatting

3.6.4(8y ago)0372MITPHPPHP ^7.1

Since Sep 18Pushed 8y ago1 watchersCompare

[ Source](https://github.com/new-inventor/property-bag)[ Packagist](https://packagist.org/packages/new-inventor/property-bag)[ RSS](/packages/new-inventor-property-bag/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (5)Versions (53)Used By (0)

Property bag
============

[](#property-bag)

This utility provide to you:

- base property bag class
- property bab interface
- configuration for property bag
- metadata classes for property bag
- generator command to generate classes from configuration

#### Installation

[](#installation)

composer require new-inventor/property-bag

PropertyBag usage
-----------------

[](#propertybag-usage)

### Property bag creation

[](#property-bag-creation)

1. Create property bag configuration.
2. run `php bin/console generate:bag   [--base-namespace="Base\Namespase"] [-f(to force rewrite destination files)]`
3. check if file exist in destination folder
4. if you want, you can write some code between comments `CustomCodeBegin` and `CustomCodeEnd`

### Stand alone object with no configuration

[](#stand-alone-object-with-no-configuration)

```
$propertyBag = new PropertyBag();
$propertyBag->add('time', new \DateTime());
$propertyBag->add('value');
$propertyBag->get('time');
$propertyBag->set('value', 123);
$propertyBag->get('value');
```

### Object with configuration

[](#object-with-configuration)

#### Configuration file

[](#configuration-file)

```
parent: Some1\Some2\Some3\Parent
abstract: true
validation:
  constraints:
    - Callback: ['TestsDataStructure\TestStatic', 'GetTrue']
  getters:
    prop1:
      - GreaterThan:
          value: 0
          message: "Field 'prop1' must be greater than {{ compared_value }}"
  properties:
    prop0:
      - GreaterThan: 0
properties:
  prop1: NewInventor\Transformers\Transformer\ToInt
  prop2:
    transformers:
      - ToInt: ~
    validation:
      - GreaterThan:
          value: 5
          message: "Field 'prop2' must be > {{ compared_value }}"
      - LessThanOrEqual:
          value: 1000
          message: "Field 'prop2' must be
