Scalr\Api\Service\User\V1beta0\Controller\Events::getEvent PHP Метод

getEvent() публичный Метод

Gets event from database using User's Account
public getEvent ( string $eventId, boolean $restrictToCurrentScope = false ) : EventDefinition | null
$eventId string The identifier of the Event
$restrictToCurrentScope boolean optional Whether it should additionally check that event corresponds to current scope
Результат Scalr\Model\Entity\EventDefinition | null Returns Event Definition entity on success or NULL otherwise
    public function getEvent($eventId, $restrictToCurrentScope = false)
    {
        $criteria = $this->getDefaultCriteria();
        $criteria[] = ['name' => $eventId];
        /* @var $event Entity\EventDefinition */
        $event = Entity\EventDefinition::findOne($criteria);
        $scopeName = ucfirst($this->getScope());
        if (!$event) {
            throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, sprintf("The Event either does not exist or isn't in scope for the current %s.", $scopeName));
        }
        //To be over-suspicious check READ access to Event object
        $this->checkPermissions($event);
        if ($restrictToCurrentScope && ($event->getScope() !== $this->getScope() || $event->accountId !== $this->getUser()->accountId || $this->getEnvironment() && $event->envId !== $this->getEnvironment()->id)) {
            throw new ApiErrorException(403, ErrorMessage::ERR_SCOPE_VIOLATION, sprintf("The Event is not either from the %s scope or owned by your %s.", $scopeName, $scopeName));
        }
        return $event;
    }