Valuation

The value service is a powerful class that determines the value of a target based on a predictable procedure of processing.

While you may not use this service on your own much it's important to understand as it's used heavily in the Streams Platform specifically where UI is concerned.

Basic Usage

To get started you will need to include the \Anomaly\Streams\Platform\Support\Value class in your own.

Value::make()

The make method makes the model value from the target value definition. Below are the steps taken in order from first to last:

  1. Checks for view in the parameters and returns it with the entry if found.
  2. Checks for template in the parameters and parses it with theentry` if found.
  3. Checks if the entry is an instance of EntryInterface and has a field field with slug value.
    • If the value is a field it returns the field value.
    • If the value is a relation it returns the relations title_column.
  4. Decorate the entry.
  5. Checks if the value is like {term}.* and renders the string like: {{ {value}|raw }}
  6. Evaluates the value with \Anomaly\Streams\Platform\Support\Evaluator.
  7. If the entry is Arrayable then run toArray on it.
  8. Wraps the value in the wrapper parameter. By default this is simply {value}. Note the value can be an array here
  9. If the value is a string. Parse it with the entry again.
  10. If the value is *.*.*::* then try translating it.
  11. If the value is parsable then try parsing it.
  12. Purifies the output unless is_safe parameter is true.

As you can see this flow and built in manipulation can allow for very powerful values with only an array. Compound this with resolvers and evaluators and you can start deferring logic for values or parts of the value to closures and handlers.. pretty cool right?

Returns: mixed
Arguments
Key Required Type Default Description
$paramters true string|array none The value definition. If a string the parameters become the value string.
$entry true string|array none The subject model.
$term false string entry The term to use in valuation strings.
$payload false array null Additional payload to pass along during the process.
Example
// A simple example
$value->make('name', $entry); // Ryan Thompson

// A more complex example
$value = [
    'wrapper'     => '
            <strong>{value.file}</strong>
            <br>
            <small class="text-muted">{value.disk}://{value.folder}/{value.file}</small>
            <br>
            <span>{value.size} {value.keywords}</span>',
    'value'       => [
        'file'     => 'entry.name',
        'folder'   => 'entry.folder.slug',
        'keywords' => 'entry.keywords.labels|join',
        'disk'     => 'entry.folder.disk.slug',
        'size'     => 'entry.size_label',
    ],
];

$value->make($value, compact('entry'));