public function getAttribute($key, $fetch = true) { if ($fetch === false) { return isset($this->_attributes[$key]) ? $this->_attributes[$key] : null; } $attributes = $this->getAttributes(); if (isset($attributes[$key]) || array_key_exists($key, $attributes)) { return $attributes[$key]; } Eyeem_Log::log('Eyeem_Ressource:getAttribute:' . static::$name . ':' . $key); $attributes = $this->getAttributes(true); if (isset($attributes[$key])) { return $attributes[$key]; } }
public function hasMember($member) { $member = $this->getRessourceObject($member); // Optimised version up to LIMIT total likers if ($this->getTotal() <= $this->getLimit()) { // Eyeem_Log::log('Eyeem_Collection:' . $this->name . ':hasMember:optimised'); foreach ($this->getItems() as $item) { if ($item['id'] == $member->getId()) { return true; } } return false; } // Trace Eyeem_Log::log('Eyeem_Collection:' . $this->name . ':hasMember:total:' . $this->getTotal() . ':limit:' . $this->getLimit()); // Direct Version $endpoint = $this->getEndpoint() . '/' . $member->getId(); Eyeem_Log::log('Eyeem_Collection:' . $this->name . ':hasMember:direct'); try { $this->getEyeem()->request($endpoint, 'GET'); return true; } catch (Exception $e) { return false; } }
public static function request($options = array()) { extract($options); if (function_exists('curl_init')) { $ch = curl_init(); // Method if ($method == 'POST') { curl_setopt($ch, CURLOPT_POST, true); } else { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); } // Headers $headers = isset($headers) ? $headers : array(); if (isset($accessToken)) { $headers[] = "Authorization: Bearer {$accessToken}"; } elseif (isset($clientId)) { $headers[] = "X-Client-Id: {$clientId}"; } if (isset($apiVersion)) { $headers[] = "X-Api-Version: {$apiVersion}"; } // Parameters if (!empty($params)) { switch ($method) { case 'GET': $url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($params, null, '&'); break; case 'PUT': case 'DELETE': $params = http_build_query($params, null, '&'); case 'POST': default: curl_setopt($ch, CURLOPT_POSTFIELDS, $params); break; } } else { // Fix 411 HTTP errors if ($method != 'GET') { $headers[] = "Content-Length:0"; } } $time_start = microtime(true); Eyeem_Log::log("Eyeem_Http:{$method}:{$url} start"); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, self::$userAgent . ' (curl)'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$timeout); $body = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $time_end = microtime(true); $time = round($time_end - $time_start, 3); Eyeem_Log::log("Eyeem_Http:{$method}:{$url} completed in {$time}"); } else { throw new Exception('Curl not available.'); /* $httpParams = array( 'method' => $method, 'user_agent' => self::$userAgent . '(php)', 'timeout' => self::$timeout ); $httpContext = stream_context_create(array('http' => $httpParams)); $body = file_get_contents($url, false, $httpContext); */ } return compact('code', 'body'); }
public function hasMember($member) { $member = $this->getRessourceObject($member); Eyeem_Log::log('Eyeem_RessourceIdCollection:' . $this->name . ':hasMember:withIds'); return in_array($member->getId(), $this->getIds()); }