public static function getInstance($type, array $attributes, array $relationships = [], $id = null) { $documentData = ['data' => ['id' => empty($id) ? Models\Base::EMPTY_ID_VALUE : $id, 'type' => $type, 'attributes' => $attributes]]; if (!empty($relationships)) { $documentData['data']['relationships'] = $relationships; } $manager = \ArkonEvent\ApiClient\JsonApi\ApiManagerFactory::getInstance(); $document = $manager->parse(json_encode($documentData)); if ($document->has('errors')) { throw new \ArkonEvent\ApiClient\Exceptions\Base($document->get('errors')); } return self::getInstanceFromDocument($type, $document); }
/** * @param CommandInterface $command * * @return RequestInterface */ public function commandToRequestTransformer(CommandInterface $command) { $name = $command->getName(); if (!isset($this->api[$name])) { throw new CommandException('Command not found', $command); } $action = $this->api[$name]; $prefix = ''; if (isset($action['public']) && $command->hasParam('public')) { $prefix = '/public'; } $prefixes = ['system' => '/systems/{system}', 'issuer' => '/issuers/{issuer}', 'program' => '/programs/{program}']; if (isset($action['admin_contexts'])) { $prefix .= implode('', array_intersect_key($prefixes, array_flip($action['admin_contexts']), array_merge($command->toArray(), $this->adminContext))); } $path = GuzzleHttp\uri_template($prefix . $action['path'], array_merge($command->toArray(), $this->adminContext)); $headers = []; $body = null; if ($command->hasParam('body')) { $headers = ['Content-Type' => 'application/json']; $body = GuzzleHttp\json_encode($command['body']); } if ($command->hasParam('query')) { $path .= '?' . Psr7\build_query($command['query']); } return new Psr7\Request($action['method'], $path, $headers, $body); }
/** * Return json representation of data object the model represents * * @return string */ public function asJson() { return json_encode($this->asArray()); }
public function asJson() { return json_encode($this->jsonString); }