Scalr\Stats\CostAnalytics\Prices::get PHP Method

get() public method

Gets price
public get ( Scalr\Stats\CostAnalytics\Entity\PriceHistoryEntity | string $price ) : Scalr\Stats\CostAnalytics\Entity\PriceHistoryEntity | boolean
$price Scalr\Stats\CostAnalytics\Entity\PriceHistoryEntity | string The identifier of the price or PriceHistoryEntity object. If you provide with object either priceId or both platform and cloudLocation properties must be set for it. Identifier must be provided as UUID without hyphens.
return Scalr\Stats\CostAnalytics\Entity\PriceHistoryEntity | boolean Returns price history entity that contains current prices on success or false if nothing found.
    public function get($price)
    {
        if (!$price instanceof PriceHistoryEntity) {
            $obj = new PriceHistoryEntity();
            $obj->priceId = (string) $price;
            $price = $obj;
        }
        if ($price->priceId) {
            $ret = PriceHistoryEntity::findPk($price->priceId);
        } else {
            if ($price->platform !== null && $price->cloudLocation !== null) {
                if ($price->url === null) {
                    $price->url = '';
                }
                if ($price->applied === null) {
                    $price->applied = new \DateTime('now', new \DateTimeZone('UTC'));
                } else {
                    if (!$price->applied instanceof \DateTime) {
                        $price->applied = new \DateTime((string) $price->applied, new \DateTimeZone('UTC'));
                    }
                }
                if ($price->accountId === null) {
                    $price->accountId = 0;
                }
                $ret = PriceHistoryEntity::findOne([['platform' => $price->platform], ['url' => $price->url], ['cloudLocation' => $price->cloudLocation], ['accountId' => $price->accountId], ['applied' => ['$lte' => $price->applied->format('Y-m-d')]]], null, ['applied' => false]);
            } else {
                throw new \InvalidArgumentException(sprintf("Either priceId or both platform and cloudLocation properties must be set for PriceHistoryEntity."));
            }
        }
        if (isset($ret)) {
            foreach (get_object_vars($ret) as $k => $v) {
                $price->{$k} = $v;
            }
            return $price;
        }
        return false;
    }