Scalr\Api\Service\User\V1beta0\Controller\Images::getImage PHP Method

getImage() public method

Gets specified Image taking into account both scope and authentication token
public getImage ( string $imageId, boolean $restrictToCurrentScope = false ) : Image
$imageId string The unique identifier of the Image (UUID)
$restrictToCurrentScope boolean optional Whether it should additionally check the Image corresponds to current scope
return Scalr\Model\Entity\Image Returns the Image Entity on success
    public function getImage($imageId, $restrictToCurrentScope = false)
    {
        $criteria = $this->getDefaultCriteria();
        $criteria[] = ['hash' => strtolower($imageId)];
        $image = Entity\Image::findOne($criteria);
        /* @var $image Entity\Image */
        if (!$image) {
            throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Requested Image either does not exist or is not owned by your environment.");
        }
        $this->checkPermissions($image);
        if ($restrictToCurrentScope) {
            if ($image->getScope() !== $this->getScope()) {
                throw new ApiErrorException(403, ErrorMessage::ERR_SCOPE_VIOLATION, "The image is not either from the environment scope or owned by your environment.");
            }
            if ($image->status === Entity\Image::STATUS_DELETE) {
                throw new ApiErrorException(409, ErrorMessage::ERR_UNACCEPTABLE_IMAGE_STATUS, sprintf("You can not use the image %s because it awaiting deletion on the cloud.", $image->name));
            }
        }
        return $image;
    }