Skip to content

Latest commit

 

History

History
110 lines (78 loc) · 2.67 KB

environment-transformers.md

File metadata and controls

110 lines (78 loc) · 2.67 KB

Environment Transformers

This Transformer can be used to pass an incoming branch unmodified through the environment resolving step and use it as asset environment. The input value passed to transform will be immediately returned without further modification.

Configuration

{
    "transformer": "passthrough"
}

Example

$transformer = new \CPSIT\FrontendAssetHandler\Asset\Environment\Transformer\PassthroughTransformer();
$environment = $transformer->transform('foo');

// $environment = 'foo'

Use this Transformer if you need to slugify the incoming branch. This is especially useful if branches contain characters that need to be URL-encoded.

Configuration

{
    "transformer": "slug",
    "options": {
        "pattern": "fe-{slug}"
    }
}

Example 1 (default pattern)

$transformer = new \CPSIT\FrontendAssetHandler\Asset\Environment\Transformer\SlugTransformer();
$environment = $transformer->transform('feature/some-cool-modifications');

// $environment = 'feature-some-cool-modifications'

Example 2 (custom pattern)

$transformer = new \CPSIT\FrontendAssetHandler\Asset\Environment\Transformer\SlugTransformer('fe-{slug}');
$environment = $transformer->transform('feature/some-cool-modifications');

// $environment = 'fe-feature-some-cool-modifications'

Sometimes environments are fixed to a static value, e.g. latest or stable. In this case you can use this Transformer and provide the static value which is always returned when calling the transform() method.

Configuration

{
    "transformer": "static",
    "options": {
        "value": "latest"
    }
}

Example

$transformer = new \CPSIT\FrontendAssetHandler\Asset\Environment\Transformer\StaticTransformer('latest');
$environment = $transformer->transform('foo');

// $environment = 'latest'

This Transformer offers a similar behavior as the StaticTransformer. It accepts a version and returns it when calling transform().

Configuration

{
    "transformer": "version",
    "options": {
        "version": "1.0.0"
    }
}

Example

$transformer = new \CPSIT\FrontendAssetHandler\Asset\Environment\Transformer\VersionTransformer('1.0.0');
$environment = $transformer->transform('foo');

// $environment = '1.0.0'