Exemple #1
0
 /**
  * @param string $placeholder
  * @param string|object $field Path or a function with a path
  * @reutrn array ['placeholder', 'field', 'value']
  */
 protected function getPlaceholder($placeholder, $field, $parentResults)
 {
     // TODO allow using a descriptive ID(level) by storing the result by `task(job) id` in $parentResults
     $level = strpos($placeholder, ':') === false ? 0 : strtok($placeholder, ':') - 1;
     if (!is_scalar($field)) {
         if (empty($field['path'])) {
             throw new UserException("The path for placeholder '{$placeholder}' must be a string value or an object containing 'path' and 'function'.");
         }
         $fn = Utils::arrayToObject($field);
         $field = $field['path'];
         unset($fn->path);
     }
     $value = $this->getPlaceholderValue($field, $parentResults, $level, $placeholder);
     if (isset($fn)) {
         $builder = new Builder();
         $builder->allowFunction('urlencode');
         $value = $builder->run($fn, ['placeholder' => ['value' => $value]]);
     }
     return ['placeholder' => $placeholder, 'field' => $field, 'value' => $value];
 }