setObjectDecoding() 공개 메소드

By default, JSON objects are decoded as instances of {@link \stdClass}.
public setObjectDecoding ( integer $decoding )
$decoding integer One of the constants {@link JSON_OBJECT} and {@link ASSOC_ARRAY}
 /**
  * @return array
  * @throws \Exception
  * @throws \Webmozart\Json\ValidationFailedException
  */
 protected function fetchRepositories()
 {
     $client = new Client();
     $request = $client->get(static::REPOSITORIES_URL);
     $response = $request->send();
     $responseBody = $response->getBody(true);
     $jsonDecoder = new JsonDecoder();
     $jsonDecoder->setObjectDecoding(JsonDecoder::ASSOC_ARRAY);
     $json = $jsonDecoder->decode($responseBody);
     if (null !== $json['meta']) {
         throw new \Exception($json['meta']['error']);
     }
     $repositories = array();
     if (is_array($json['data'])) {
         foreach ($json['data'] as $extKey => $extData) {
             $repositories[] = array('type' => 'vcs', 'url' => $extData['repository_clone_url']);
         }
     }
     return $repositories;
 }
예제 #2
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testSchemaNotSupportedForArrays()
 {
     $this->decoder->setObjectDecoding(JsonDecoder::ASSOC_ARRAY);
     $this->decoder->decode('{ "name": "Bernhard" }', $this->schemaObject);
 }
예제 #3
0
 /**
  * Loads the JSON file.
  */
 private function load()
 {
     $decoder = new JsonDecoder();
     $decoder->setObjectDecoding(JsonDecoder::ASSOC_ARRAY);
     $this->json = file_exists($this->path) ? $decoder->decodeFile($this->path) : array();
 }
예제 #4
0
 /**
  * Loads the JSON file.
  */
 private function load()
 {
     $decoder = new JsonDecoder();
     $decoder->setObjectDecoding(JsonDecoder::ASSOC_ARRAY);
     $this->json = file_exists($this->path) ? $decoder->decodeFile($this->path) : array();
     if (!isset($this->json['keysByTypeName'])) {
         $this->json['keysByTypeName'] = array();
         $this->json['keysByUuid'] = array();
         $this->json['typesByKey'] = array();
         $this->json['bindingsByKey'] = array();
         $this->json['nextKey'] = 0;
     }
 }
예제 #5
0
 /**
  * @param string $directory
  */
 public function __construct($directory)
 {
     parent::__construct($directory, 'json');
     $this->decoder = new JsonDecoder();
     $this->decoder->setObjectDecoding(JsonDecoder::ASSOC_ARRAY);
 }
예제 #6
0
 public function __construct($path, $flags = 0)
 {
     Assert::string($path, 'The path must be a string. Got: %s');
     Assert::notEmpty($path, 'The path must not be empty.');
     Assert::integer($flags, 'The flags must be an integer. Got: %s');
     $this->path = $path;
     $this->flags = $flags;
     $this->encoder = new JsonEncoder();
     $this->encoder->setEscapeGtLt($this->flags & self::ESCAPE_GT_LT);
     $this->encoder->setEscapeAmpersand($this->flags & self::ESCAPE_AMPERSAND);
     $this->encoder->setEscapeSingleQuote($this->flags & self::ESCAPE_SINGLE_QUOTE);
     $this->encoder->setEscapeDoubleQuote($this->flags & self::ESCAPE_DOUBLE_QUOTE);
     $this->encoder->setEscapeSlash(!($this->flags & self::NO_ESCAPE_SLASH));
     $this->encoder->setEscapeUnicode(!($this->flags & self::NO_ESCAPE_UNICODE));
     $this->encoder->setPrettyPrinting($this->flags & self::PRETTY_PRINT);
     $this->encoder->setTerminateWithLineFeed($this->flags & self::TERMINATE_WITH_LINE_FEED);
     $this->decoder = new JsonDecoder();
     $this->decoder->setObjectDecoding(JsonDecoder::ASSOC_ARRAY);
 }