data = $data; $this->api = $api; } /** * @inheritDoc */ public function __get(string $name) { return $this->data[$name]; } /** * @inheritDoc */ public function __isset(string $name):bool { return isset($this->data[$name]); } /** * Returns a sorted representation of the complete Document Data * @return array */ public function getData(): array { $this->recursiveSortArray($this->data); return $this->data; } /** * Returns a Document in the type regarding to the API used. * May be a Child of "Document" e.g.: FoodDocument or ProductDocument * @param string $apiIdentifier * @param array $data * @return Document */ public static function createSpecificDocument(string $apiIdentifier, array $data): Document { if ($apiIdentifier === '') { return new Document($data, $apiIdentifier); } $className = "OpenFoodFacts\Document\\" . ucfirst($apiIdentifier) . 'Document'; if (class_exists($className) && is_subclass_of($className, Document::class)) { return new $className($data, $apiIdentifier); } return new Document($data, $apiIdentifier); } }