Scalr\Api\Service\User\V1beta0\Controller\ScalingMetrics::getScalingMetric PHP Method

getScalingMetric() public method

Gets Scaling Metric from database
public getScalingMetric ( string $metricName, boolean $restrictToCurrentScope = false ) : ScalingMetric
$metricName string Scaling metric's name.
$restrictToCurrentScope boolean optional Whether it should additionally check that role corresponds to current scope
return Scalr\Model\Entity\ScalingMetric
    public function getScalingMetric($metricName, $restrictToCurrentScope = false)
    {
        $criteria = $this->getDefaultCriteria();
        $criteria[] = ['name' => $metricName];
        /* @var $event Entity\ScalingMetric */
        $metric = Entity\scalingMetric::findOne($criteria);
        if (empty($metric)) {
            throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, sprintf("The Scaling Metric either does not exist or isn't in scope for the current %s.", $this->getScope()));
        }
        if ($restrictToCurrentScope && $metric->getScope() !== $this->getScope()) {
            throw new ApiErrorException(403, ErrorMessage::ERR_SCOPE_VIOLATION, "The Scaling Metric is not either from the {$this->getScope()} scope or owned by your {$this->getScope()}.");
        }
        return $metric;
    }