示例#1
0
 /**
  * @param  string $id
  *
  * @return Asset
  *
  * @api
  */
 public function getAsset($id)
 {
     if ($this->instanceCache->hasAsset($id)) {
         return $this->instanceCache->getAsset($id);
     }
     return $this->requestAndBuild('GET', 'assets/' . $id, ['query' => ['locale' => '*']]);
 }
 /**
  * When an instance of the target already exists, it is returned. If not, a Link is created as placeholder.
  *
  * @param  object $data
  *
  * @return Asset|DynamicEntry|Link
  *
  * @throws \InvalidArgumentException When encountering an unexpected link type. Only links to assets and entries are currently handled.
  */
 private function buildLink($data)
 {
     $id = $data->sys->id;
     $type = $data->sys->linkType;
     if ($type === 'Asset') {
         if ($this->instanceCache->hasAsset($id)) {
             return $this->instanceCache->getAsset($id);
         }
         return new Link($id, $type);
     }
     if ($type === 'Entry') {
         if ($this->instanceCache->hasEntry($id)) {
             return $this->instanceCache->getEntry($id);
         }
         return new Link($id, $type);
     }
     throw new \InvalidArgumentException('Encountered unexpected resource type "' . $type . '"" while constructing link.');
 }