public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context) { $connection = $this->connector->getConnection($configuration->get('connection')); if ($connection instanceof Pheanstalk) { $writer = new Writer\Json(); $body = $writer->write($request->getBody()); $connection->useTube($configuration->get('queue'))->put($body); return $this->response->build(200, [], ['success' => true, 'message' => 'Push was successful']); } else { throw new ConfigurationException('Given connection must be an Beanstalk connection'); } }
public function handle(Request $request, Parameters $configuration, Context $context) { $connection = $this->connector->getConnection($configuration->get('connection')); if ($connection instanceof AMQPStreamConnection) { $writer = new Writer\Json(); $body = $writer->write($request->getBody()); $message = new AMQPMessage($body, array('content_type' => $writer->getContentType(), 'delivery_mode' => 2)); $channel = $connection->channel(); $channel->basic_publish($message, '', $configuration->get('queue')); return new Response(200, [], array('success' => true, 'message' => 'Push was successful')); } else { throw new ConfigurationException('Given connection must be an AMQP connection'); } }
public function __invoke($value) { $writer = new Writer\Json(); if (is_array($value)) { $value = Record::fromArray($value); } elseif ($value instanceof \stdClass) { $value = Record::fromArray((array) $value); } if ($value instanceof RecordInterface) { return $writer->write($value); } else { return '{}'; } }
public function generate(SchemaInterface $schema) { $record = $this->generateType($schema->getDefinition(), $this->data); switch ($this->format) { case self::FORMAT_XML: $writer = new Writer\Xml(); break; case self::FORMAT_JSON: default: $writer = new Writer\Json(); break; } return $writer->write($record); }
public function generate(Resource $resource) { $declaration = new Declaration($this->apiVersion); $declaration->setBasePath($this->basePath); $declaration->setApis($this->getApis($resource)); $declaration->setModels($this->getModels($resource)); $declaration->setResourcePath(ApiGeneration::transformRoutePlaceholder($resource->getPath())); $writer = new JsonWriter(); $swagger = $writer->write($declaration); // since swagger does not fully support the json schema spec we must // remove the $ref fragments $swagger = str_replace('#\\/definitions\\/', '', $swagger); return $swagger; }
public function write(RecordInterface $record) { $callbackName = $this->getCallbackName(); if (!empty($callbackName)) { return $callbackName . '(' . parent::write($record) . ')'; } else { return parent::write($record); } }
protected function getWriterResponse(RecordInterface $record) { $writer = new Writer\Json(); $content = $writer->write($record); return $content; }
public function testGetContentType() { $writer = new Json(); $this->assertEquals('application/json', $writer->getContentType()); }