示例#1
0
 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');
     }
 }
示例#2
0
 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');
     }
 }
示例#3
0
文件: Json.php 项目: uqiauto/fusio
 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 '{}';
     }
 }
示例#4
0
文件: Sample.php 项目: seytar/psx
 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);
 }
示例#5
0
文件: Swagger.php 项目: seytar/psx
 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;
 }
示例#6
0
文件: Jsonp.php 项目: seytar/psx
 public function write(RecordInterface $record)
 {
     $callbackName = $this->getCallbackName();
     if (!empty($callbackName)) {
         return $callbackName . '(' . parent::write($record) . ')';
     } else {
         return parent::write($record);
     }
 }
示例#7
0
 protected function getWriterResponse(RecordInterface $record)
 {
     $writer = new Writer\Json();
     $content = $writer->write($record);
     return $content;
 }
示例#8
0
文件: JsonTest.php 项目: seytar/psx
 public function testGetContentType()
 {
     $writer = new Json();
     $this->assertEquals('application/json', $writer->getContentType());
 }