# fluent-cart/1.6.4/app/Services/ShortCodeParser/ValueTransformer.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.6.4. 100 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Services/ShortCodeParser/ValueTransformer.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.4/raw/app/Services/ShortCodeParser/ValueTransformer.php
- Modified: 2026-03-13T16:10:00+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Services/ShortCodeParser/ValueTransformer.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Services\ShortCodeParser;

use FluentCart\Framework\Support\Arr;
use FluentCart\Framework\Support\Str;

trait ValueTransformer
{
    public array $callableFunctions = [
        'trim',
        'ucfirst',
        'strtolower',
        'strtoupper',
        'ucwords'
    ];

    public function transform($value, $code, $data)
    {

        $conditions = $this->evaluateCondition($code);

        $transformer = Arr::get($conditions, 'transformer');
        $defaultValue = Arr::get($conditions, 'default_value');

        if (empty($value) && empty($defaultValue)) {
            $value = apply_filters($this->hookPrefix . 'smartcode_fallback', $value, $code, $data, $conditions);
        }

        if (empty($value) && !empty($defaultValue)) {
            $value = $defaultValue;
        }

        if (empty($transformer)) {
            return $value;
        }

        if (in_array($transformer, $this->callableFunctions)) {
            return call_user_func($transformer, $value);
        }

        switch ($transformer) {
            case 'concat_first': // usage: {{contact.first_name||concat_first|Hi
                if ($defaultValue && !empty($value)) {
                    $value = trim($defaultValue . $value);
                }
                return $value;
            case 'concat_last': // usage: {{contact.first_name||concat_last|, => FIRST_NAME,
                if ($defaultValue && !empty($value)) {

                    $value = trim($value . $defaultValue);
                }
                return $value;

            case 'title_case':
                if (empty($value)) {
                    return $value;
                }
                return Str::title($value);

            case 'headline':
                if (empty($value)) {
                    return $value;
                }
                return Str::headline($value);
            case 'show_if': // usage {{contact.first_name||show_if|First name exist
                if (!empty($value)) {
                    $value = $defaultValue;
                } else {
                    $value = '';
                }
                return $value;
            default:
                return $value;
        }
    }


    public function evaluateCondition($smartCode): array
    {
        $conditions = [];
        $parsedCode = explode('|', $smartCode);
        $codeCound = count($parsedCode);
        if ($codeCound >= 3) {
            $conditions = [
                'transformer'   => trim(Arr::get($parsedCode, '2') ?? ''),
                'default_value' => trim(Arr::get($parsedCode, '3') ?? ''),
            ];
        } else if ($codeCound === 2) {
            $conditions = [
                'transformer'   => null,
                'default_value' => trim(Arr::get($parsedCode, '1') ?? ''),
            ];
        }
        $conditions['accessor'] = trim(Arr::get($parsedCode, '0') ?? '');

        return $conditions;
    }
}

```
