Skip to content

Latest commit

 

History

History
70 lines (58 loc) · 1.44 KB

overridable.md

File metadata and controls

70 lines (58 loc) · 1.44 KB

Overridable values

Configurator part

Since version 4.1, is possible to define some rules able to override some values in specific conditions

use Sensorario\Resources\Configurator;
use Sensorario\Resources\Container;

$configurator = new Configurator(
   'foo',
   new Container([
       'resources' => [
           'foo' => [
               'rewrite' => [
                    'width' => [
                        'set' => [
                            'equals_to' => 'height',
                        ],
                        'when' => [
                            'greater_than' => 'height',
                        ],
                    ],
               ],
               'constraints' => [
                   'allowed' => [
                       'width',
                       'height',
                   ],
               ],
           ], 
       ],
   ])
);

Usages

This override rule, rewrite width when is greater than height. In this case, with must be equals to height. Here, we try to create a box with width and height defined. But the rule, override the Resource. …

use Sensorario\Resources\Resource;

$properties = [
    'width'  => 3000,
    'height' => 400,
];

$box = Resource::box(
    $properties,
    $configurator
);

Will generate same resource of this code.

$properties = [
    'width'  => 400,
    'height' => 400,
];

$box = Resource::box(
    $properties,
    $configurator
);