public function write(RecordInterface $record) { $visitor = new Visitor\StdClassSerializeVisitor(); $graph = new GraphTraverser(); $graph->traverse($record, $visitor); return JsonParser::encode($visitor->getObject(), JSON_PRETTY_PRINT); }
protected function sendSignedRequest($type, RecordInterface $record = null) { $url = new Url($this->getEndpoint()); $body = $record !== null ? Json::encode($record->getFields()) : null; $header = array('Content-Type' => 'application/json', 'Accept' => 'application/json'); return $this->signedRequest($type, $url, $header, $body); }
public function generate(Resource $resource) { $methods = $resource->getMethods(); $definitions = array(); $properties = array(); foreach ($methods as $method) { $request = $method->getRequest(); if ($request instanceof SchemaInterface) { list($defs, $props) = $this->getJsonSchema($request); $key = strtolower($method->getName()) . 'Request'; $definitions = array_merge($definitions, $defs); if (isset($props['properties'])) { $properties[$key] = $props; } } $response = $this->getSuccessfulResponse($method); if ($response instanceof SchemaInterface) { list($defs, $props) = $this->getJsonSchema($response); $key = strtolower($method->getName()) . 'Response'; $definitions = array_merge($definitions, $defs); if (isset($props['properties'])) { $properties[$key] = $props; } } } $result = array('$schema' => JsonSchemaGenerator::SCHEMA, 'id' => $this->targetNamespace, 'type' => 'object', 'definitions' => $definitions, 'properties' => $properties); return Json::encode($result, JSON_PRETTY_PRINT); }
/** * Returns this signature in the JWS JSON Serialization format * * @see http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-39#section-3.2 * @param string $key * @return string */ public function getJson($key) { $signature = array(); $signature['protected'] = self::base64Encode(Json::encode($this->headers)); $signature['payload'] = self::base64Encode($this->claim); $signature['signature'] = $this->getEncodedSignature($key); return Json::encode($signature); }
public function notify($type, TableInterface $table, RecordInterface $record) { $message = Json::encode($record->getData()); $headers = array('amun-table' => $table->getName(), 'amun-type' => $type, 'amun-user-id' => $this->user->id); $stomp = new Stomp($this->registry['stomp.broker'], $this->registry['stomp.user'], $this->registry['stomp.pw']); $stomp->send($this->registry['stomp.destination'], $message, $headers); unset($stomp); }
/** * Returns whether the given identity needs an password or not * * @httpMethod GET * @path / * @nickname needPassword * @parameter query identity string * @responseClass PSX_Data_Message */ public function needPassword() { $identity = $this->get->identity('string'); $handles = array_map('trim', explode(',', $this->registry['login.provider'])); $result = array(); foreach ($handles as $key) { $handler = HandlerFactory::factory($key, $this->container); if ($handler instanceof HandlerAbstract && $handler->isValid($identity)) { $result = array('handler' => $key, 'icon' => $this->config['psx_url'] . '/img/icons/login/' . $key . '.png', 'needPassword' => $handler->hasPassword()); break; } } echo Json::encode($result); }
protected function serializeData($data) { return base64_encode(Json::encode($data)); }
public function generate(SchemaInterface $schema) { return Json::encode($this->generateRootElement($schema->getDefinition()), JSON_PRETTY_PRINT); }
public function toJson() { return Json::encode($this); }
protected function submitData(InstructionAbstract $instruction, $endpoint) { $header = ['User-Agent' => 'Fusio-Installer v' . Base::getVersion(), 'Authorization' => 'Bearer ' . $this->getAccessToken()]; $body = Json::encode($this->substituteParameters($instruction->getPayload())); $request = new PostRequest(new Url('http://127.0.0.1/' . $endpoint), $header, $body); $response = new Response(); $response->setBody(new TempStream(fopen('php://memory', 'r+'))); $this->dispatch->route($request, $response); $body = (string) $response->getBody(); $data = Json::decode($body, false); if (isset($data->success) && $data->success === true) { // installation successful $message = isset($data->message) ? $data->message : 'Insert ' . $instruction->getName() . ' successful'; $this->logger->notice($message); } else { $message = isset($data->message) ? $data->message : 'Unknown error occured'; throw new RuntimeException($message); } }
public function route(RequestInterface $request, ResponseInterface $response, Context $context = null) { $this->eventDispatcher->dispatch(Event::REQUEST_INCOMING, new RequestIncomingEvent($request)); // load controller $context = $context ?: new Context(); try { $this->loader->load($request, $response, $context); } catch (StatusCode\NotModifiedException $e) { $response->setStatus($e->getStatusCode()); $response->setBody(new StringStream()); } catch (StatusCode\RedirectionException $e) { $response->setStatus($e->getStatusCode()); $response->setHeader('Location', $e->getLocation()); $response->setBody(new StringStream()); } catch (\Exception $e) { $this->eventDispatcher->dispatch(Event::EXCEPTION_THROWN, new ExceptionThrownEvent($e, new ControllerContext($request, $response))); $this->handleException($e, $response); try { $context->set(Context::KEY_EXCEPTION, $e); $class = isset($this->config['psx_error_controller']) ? $this->config['psx_error_controller'] : 'PSX\\Controller\\ErrorController'; $controller = $this->factory->getController($class, $request, $response, $context); $this->loader->executeController($controller, $request, $response); } catch (\Exception $e) { // in this case the error controller has thrown an exception. // This can happen i.e. if we can not represent the error in an // fitting media type. In this case we send json to the client $this->handleException($e, $response); $record = $this->exceptionConverter->convert($e); $response->setHeader('Content-Type', 'application/json'); $response->setBody(new StringStream(Json::encode($record->getRecordInfo()->getData(), JSON_PRETTY_PRINT))); } } $this->eventDispatcher->dispatch(Event::RESPONSE_SEND, new ResponseSendEvent($response)); // send response $this->sender->send($response); }