Parser helps to filter resource attributes at the moment of their creation. ^^^^ This is 'sparse' JSON API feature and 'fields set' feature (for attributes) Parser does not decide if particular resource or its relationships are actually added to final JSON document. Parsing reply interpreter does this job. Parser interpreter might not include some intermediate resources that parser has found while reaching targets. ^^^^ This is 'sparse' JSON API feature again and 'fields set' feature (for relationships) The final JSON view of an element is chosen by document which uses settings to decide if 'self', 'meta', and other members should be rendered. ^^^^ This is generic JSON API features Once again, it basically works this way: - Parser finds all targeted relationships and outputs them with all intermediate results (looks like a tree). Resource attributes are already filtered. - Reply interpreter filters intermediate results and resource relationships and then send it to document. - The document is just a renderer which saves the input data in one of a few variations depending on settings. - When all data are parsed the document converts collected data to json.
Inheritance: implements Neomerx\JsonApi\Contracts\Encoder\Parser\ParserInterface
Esempio n. 1
0
 /**
  * Overridden so sensible schema handling can be used for:
  * Pivot objects and Eloquent Collections. Anything else
  * can be handled normally.
  *
  * @return array
  */
 protected function analyzeCurrentData()
 {
     $relationship = $this->stack->end()->getRelationship();
     $data = $relationship->isShowData() === true ? $relationship->getData() : null;
     if ($data instanceof Collection) {
         $firstItem = null;
         $isEmpty = count($data) === 0;
         $traversableData = $data;
         if ($isEmpty === false) {
             $firstItem = $data->first();
         }
         if ($firstItem === null) {
             $traversableData = [];
         }
         return [$isEmpty, true, $traversableData];
     } elseif ($data instanceof Pivot) {
         return [true, false, []];
     }
     return parent::analyzeCurrentData();
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function createParser(ContainerInterface $container, ParserManagerInterface $manager)
 {
     $parser = new Parser($this, $this, $this, $container, $manager);
     $parser->setLogger($this->logger);
     return $parser;
 }