Esempio n. 1
0
 /**
  * @param array|\stdClass $functions
  * @param array $params ['attr' => $attributesArray, ...]
  * @param Builder $builder
  * @return array
  */
 public static function build($functions, array $params = [], Builder $builder = null)
 {
     if (is_null($builder)) {
         $builder = new Builder();
     }
     $functions = (array) Utils::arrayToObject($functions);
     try {
         array_walk($functions, function (&$value, $key) use($params, $builder) {
             $value = !is_object($value) ? $value : $builder->run($value, $params);
         });
     } catch (UserScriptException $e) {
         throw new UserException('User script error: ' . $e->getMessage());
     }
     return $functions;
 }
Esempio n. 2
0
 /**
  * @param RestClient $client
  */
 public function authenticateClient(RestClient $client)
 {
     $sub = new UrlSignature();
     // Create array of objects instead of arrays from YML
     $q = (array) Utils::arrayToObject($this->query);
     $sub->setSignatureGenerator(function (array $requestInfo = []) use($q) {
         $params = array_merge($requestInfo, ['attr' => $this->attrs]);
         $query = [];
         try {
             foreach ($q as $key => $value) {
                 $query[$key] = is_scalar($value) ? $value : $this->builder->run($value, $params);
             }
         } catch (UserScriptException $e) {
             throw new UserException("Error in query authentication script: " . $e->getMessage());
         }
         return $query;
     });
     $client->getClient()->getEmitter()->attach($sub);
 }
Esempio n. 3
0
 /**
  * @param array|object $definitions
  */
 protected function addGenerator($subscriber, $definitions, $authorization)
 {
     // Create array of objects instead of arrays from YML
     $q = (array) Utils::arrayToObject($definitions);
     $subscriber->setSignatureGenerator(function (array $requestInfo = []) use($q, $authorization) {
         $params = array_merge($requestInfo, ['authorization' => $authorization]);
         $result = [];
         try {
             foreach ($q as $key => $value) {
                 $result[$key] = is_scalar($value) ? $value : $this->builder->run($value, $params);
             }
         } catch (UserScriptException $e) {
             throw new UserException("Error in OAuth authentication script: " . $e->getMessage());
         }
         return $result;
     });
 }
Esempio n. 4
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];
 }