Exemplo n.º 1
0
 /**
  * @return \Contentful\Delivery\Space
  *
  * @api
  */
 public function getSpace()
 {
     if ($this->instanceCache->hasSpace()) {
         return $this->instanceCache->getSpace();
     }
     return $this->requestAndBuild('GET', '');
 }
 /**
  * @param  object $data
  *
  * @return Space|null
  *
  * @throws SpaceMismatchException When attempting to build a different Space than the one this ResourceBuilder is configured to handle.
  */
 private function buildSpace($data)
 {
     if ($data->sys->id !== $this->spaceId) {
         throw new SpaceMismatchException('This ResourceBuilder is responsible for the space "' . $this->spaceId . '" but was asked to build a resource for the space "' . $data->sys->id . '"."');
     }
     if ($this->instanceCache->hasSpace()) {
         return $this->instanceCache->getSpace();
     }
     $locales = [];
     foreach ($data->locales as $locale) {
         $locales[] = new Locale($locale->code, $locale->name, $locale->default);
     }
     $sys = $this->buildSystemProperties($data->sys);
     $space = new Space($data->name, $locales, $sys);
     $this->instanceCache->setSpace($space);
     return $space;
 }