SocialShare\SocialShare::getShares PHP Method

getShares() public method

Gets the number of share of the given URL on the given provider.
public getShares ( string $providerName, string $url, boolean $delayUpdate = false ) : integer
$providerName string
$url string
$delayUpdate boolean
return integer
    public function getShares($providerName, $url, $delayUpdate = false)
    {
        $this->checkProvider($providerName);
        $id = $this->getId($providerName, $url);
        $lifeTime = $this->providers[$providerName]['lifeTime'];
        $now = new \DateTime();
        $dataFromCache = $this->cache->fetch($id);
        $shares = isset($dataFromCache[0]) ? $dataFromCache[0] : false;
        $expired = isset($dataFromCache[1]) && $dataFromCache[1]->add($lifeTime) < $now;
        if (!$delayUpdate && (false === $shares || $expired)) {
            $shares = $this->providers[$providerName]['provider']->getShares($url);
            $this->cache->save($id, array($shares, $now));
        } else {
            if ($delayUpdate && (false === $shares || $expired)) {
                $this->toUpdate[$providerName][] = $url;
            }
            $shares = intval($shares);
        }
        return $shares;
    }

Usage Example

 /**
  * @param string $provider
  * @param string $url
  *
  * @return int
  * @throws \RuntimeException             If requested provider is undefined
  * @throws UnsupportedOperationException If called for an uncompatible provider
  */
 public function getShareCount($provider, $url)
 {
     return $this->socialShare->getShares($provider, $url);
 }
All Usage Examples Of SocialShare\SocialShare::getShares