当前位置: 首页>>代码示例>>PHP>>正文


PHP Error::is_error方法代码示例

本文整理汇总了PHP中Error::is_error方法的典型用法代码示例。如果您正苦于以下问题:PHP Error::is_error方法的具体用法?PHP Error::is_error怎么用?PHP Error::is_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Error的用法示例。


在下文中一共展示了Error::is_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fetch

 public function fetch()
 {
     $remote_archive = new RemoteRequest($this->url);
     if (Error::is_error($remote_archive->execute())) {
         throw new Exception('Could not fetch archive at ' . $this->url);
     }
     // we should also check content-disposition for filename and the url as fallbacks.
     // some crazy people like to send application/octet-stream, weirdos!
     foreach (split("\n", $remote_archive->get_response_headers()) as $line) {
         if (substr_compare($line, 'Content-Type', 0, 12, true) == 0) {
             $content_type = $line;
             break;
         }
     }
     /* Get the MIME type and character set */
     preg_match('@Content-Type:\\s+([\\w/\\-+]+)(;\\s+charset=(\\S+))?@i', $content_type, $matches);
     if (isset($matches[1])) {
         $mime = $matches[1];
     } else {
         throw new Exception('Could not determine archive type');
     }
     $file = HabariPackages::tempnam();
     if (!file_put_contents($file, $remote_archive->get_response_body(), LOCK_EX)) {
         throw new Exception('Please make the directory ' . dirname($file) . ' writeable by the server');
     }
     $this->md5 = md5_file($file);
     $this->set_archive_reader($mime, $file);
     unset($remote_archive);
 }
开发者ID:habari-extras,项目名称:hpm,代码行数:29,代码来源:packagearchive.php

示例2: get_incoming_links

 private function get_incoming_links()
 {
     $links = array();
     try {
         $search = new RemoteRequest('http://blogsearch.google.com/blogsearch_feeds?scoring=d&num=10&output=atom&q=link:' . Site::get_url('habari'));
         $search->set_timeout(5);
         $result = $search->execute();
         if (Error::is_error($result)) {
             throw $result;
         }
         $response = $search->get_response_body();
         if (mb_detect_encoding($response, 'UTF-8', true)) {
             $xml = new SimpleXMLElement($response);
             foreach ($xml->entry as $entry) {
                 //<!-- need favicon discovery and caching here: img class="favicon" src="http://skippy.net/blog/favicon.ico" alt="favicon" / -->
                 $links[] = array('href' => (string) $entry->link['href'], 'title' => (string) $entry->title);
             }
         } else {
             EventLog::log(_t('The response had non-UTF-8 characters'), 'err', 'plugin');
         }
     } catch (Exception $e) {
         $links['error'] = $e->getMessage();
     }
     return $links;
 }
开发者ID:habari-extras,项目名称:incoming_links,代码行数:25,代码来源:incoming_links.plugin.php

示例3: favorites

 /**
  * Return a user's favorited video feed
  *
  * @param string YouTube username
  *
  * @return ??
  *
  */
 public static function favorites($user)
 {
     $url = self::YOUTUBE_BASE . 'users/' . $user . '/favorites';
     $call = new RemoteRequest($url);
     $call->set_timeout(5);
     $result = $call->execute();
     if (Error::is_error($result)) {
         throw $result;
     }
     $response = $call->get_response_body();
     try {
         $xml = new SimpleXMLElement($response);
         $videos = array();
         foreach ($xml->entry as $entry) {
             $video = array();
             $video['id'] = $entry->id;
             $video['url'] = self::flash_url($entry);
             $video['thumbnail_url'] = self::thumbnail_url($entry);
             $video['title'] = self::title($entry);
             $videos[] = $video;
         }
         return new YouTube($videos);
     } catch (Exception $e) {
         Session::error('Currently unable to connect to YouTube.', 'YouTube API');
         //				Utils::debug($url, $response);
         return false;
     }
 }
开发者ID:habari-extras,项目名称:youtubesilo,代码行数:36,代码来源:youtubesilo.plugin.php

示例4: update_packages

 /**
  * @todo the server should return all versions and let hpm decide which version to take
  */
 public static function update_packages($repo)
 {
     $client = new RemoteRequest($repo, 'GET');
     if (Error::is_error($client->execute())) {
         return false;
     }
     try {
         $packages = $client->get_response_body();
         //Utils::debug( $packages );
         $packages = new SimpleXMLElement($packages);
         $package_list = array();
         foreach ($packages->package as $package) {
             if (!$package['guid'] || !$package->versions) {
                 continue;
             }
             $new_package = (array) $package->attributes();
             $new_package = $new_package['@attributes'];
             $new_package['description'] = strval($package->description);
             $versions = array();
             //Utils::debug($package->versions);
             foreach ($package->versions->version as $version) {
                 $version = (array) $version->attributes();
                 $version = $version['@attributes'];
                 if (isset($version['habari_version']) && self::is_compatible($version['habari_version'])) {
                     $versions[$version['version']] = $version;
                 }
             }
             //Utils::debug( $new_package, $versions );
             uksort($versions, create_function('$a,$b', 'return version_compare($b,$a);'));
             $version = current($versions);
             if ($version) {
                 $new_package = array_merge($version, $new_package);
                 if ($old_package = HabariPackage::get($new_package['guid'])) {
                     if (isset($new_package['version']) && version_compare($new_package['version'], $old_package->version, '>')) {
                         if ($old_package->status == 'installed') {
                             $new_package['status'] = 'upgrade';
                         }
                         DB::update(DB::table('packages'), $new_package, array('guid' => $new_package['guid']));
                         $package_list[] = $old_package->id;
                     } else {
                         $package_list[] = $old_package->id;
                     }
                 } else {
                     DB::insert(DB::table('packages'), $new_package);
                     $package_list[] = DB::last_insert_id();
                 }
             }
         }
         Options::set('hpm__repo_version', Version::get_habariversion());
         return $package_list;
     } catch (Exception $e) {
         Utils::debug($e);
         return false;
     }
 }
开发者ID:habari-extras,项目名称:hpm,代码行数:58,代码来源:habaripackages.php

示例5: get_external_content

 private static function get_external_content($url)
 {
     // Get PHP serialized object from Flickr
     $call = new RemoteRequest($url);
     $call->set_timeout(5);
     $result = $call->execute();
     if (Error::is_error($result)) {
         throw Error::raise(_t('Unable to contact Flickr.', 'flickrfeed'));
     }
     return $call->get_response_body();
 }
开发者ID:habari-extras,项目名称:flickrfeed,代码行数:11,代码来源:flickrfeed.plugin.php

示例6: get_external_content

 private static function get_external_content($url)
 {
     // Get JSON content via Delicious API
     $call = new RemoteRequest($url);
     $call->set_timeout(5);
     $result = $call->execute();
     if (Error::is_error($result)) {
         throw new Exception(_t('Unable to contact Delicious.', 'deliciousfeed'));
     }
     return $call->get_response_body();
 }
开发者ID:habari-extras,项目名称:deliciousfeed,代码行数:11,代码来源:deliciousfeed.plugin.php

示例7: execute

 public function execute($method, $url, $headers, $body, $timeout)
 {
     $result = $this->_request($method, $url, $headers, $body, $timeout);
     if ($result && !Error::is_error($result)) {
         list($response_headers, $response_body) = $result;
         $this->response_headers = $response_headers;
         $this->response_body = $response_body;
         $this->executed = TRUE;
         return TRUE;
     } else {
         return $result;
     }
 }
开发者ID:anupom,项目名称:my-blog,代码行数:13,代码来源:socketrequestprocessor.php

示例8: shrink

function shrink($url)
{
    $service = 'http://tinyurl.com/api-create.php?url=';
    $request = new RemoteRequest($service . urlencode($url), 'GET');
    $result = $request->execute();
    if (Error::is_error($result)) {
        throw $result;
    }
    $data = $request->get_response_body();
    if (Error::is_error($data)) {
        throw $data;
    }
    return $data;
}
开发者ID:habari-extras,项目名称:lilliputian,代码行数:14,代码来源:tinyurl.helper.php

示例9: check

 /**
  * Perform a check of all beaconids.
  * Notifies update_check plugin hooks when checking so that they can add their beaconids to the list.
  * @return array An array of update beacon information for components that have updates
  */
 public static function check()
 {
     try {
         $instance = self::instance();
         if (count($instance->beacons) == 0) {
             Update::add('Habari', '7a0313be-d8e3-11db-8314-0800200c9a66', Version::get_habariversion());
             Plugins::act('update_check');
         }
         $request = new RemoteRequest(UPDATE_URL, 'POST');
         $request->set_params(array_map(create_function('$a', 'return $a["version"];'), $instance->beacons));
         $request->set_timeout(10);
         $result = $request->execute();
         if (Error::is_error($result)) {
             throw $result;
         }
         $updatedata = $request->get_response_body();
         if (Error::is_error($updatedata)) {
             throw $updatedata;
         }
         $instance->update = new SimpleXMLElement($updatedata);
         foreach ($instance->update as $beacon) {
             $beaconid = (string) $beacon['id'];
             foreach ($beacon->update as $update) {
                 // Do we have this beacon?  If not, don't process it.
                 if (empty($instance->beacons[$beaconid])) {
                     continue;
                 }
                 // If the remote update info version is newer...
                 if (version_compare($update['version'], $instance->beacons[$beaconid]['version']) > 0) {
                     // If this version is more recent than all other newer versions...
                     if (empty($instance->beacons[$beaconid]['latest_version']) || version_compare((string) $update['version'], $instance->beacons[$beaconid]['latest_version']) > 0) {
                         $instance->beacons[$beaconid]['latest_version'] = (string) $update['version'];
                     }
                     if (isset($instance->beacons[$beaconid]['severity'])) {
                         $instance->beacons[$beaconid]['severity'][] = (string) $update['severity'];
                         array_unique($instance->beacons[$beaconid]['severity']);
                     } else {
                         $instance->beacons[$beaconid]['severity'] = array((string) $update['severity']);
                     }
                     $instance->beacons[$beaconid]['url'] = (string) $beacon['url'];
                     $instance->beacons[$beaconid]['changes'][(string) $update['version']] = (string) $update;
                 }
             }
         }
         return array_filter($instance->beacons, array('Update', 'filter_unchanged'));
     } catch (Exception $e) {
         return $e;
     }
 }
开发者ID:anupom,项目名称:my-blog,代码行数:54,代码来源:update.php

示例10: shorten

 public function shorten($url)
 {
     $params = array('login' => $this->username, 'apiKey' => $this->apiKey, 'format' => $this->format, 'longUrl' => $url);
     $reqUrl = $this->endpoint . '/shorten?' . http_build_query($params);
     $call = new RemoteRequest($reqUrl);
     $call->set_timeout(5);
     $result = $call->execute();
     if (Error::is_error($result)) {
         throw $result;
     }
     $response = $call->get_response_body();
     $data = json_decode($response);
     if ($data === null) {
         throw new Exception("Could not communicate with bit.ly API");
     }
     return $data;
 }
开发者ID:habari-extras,项目名称:bitly,代码行数:17,代码来源:bitly.plugin.php

示例11: commit

 /**
  * Commit all of the changed info options to the database.
  * If this function is not called, then the options will not be written.
  *
  * @param mixed $metadata_key (optional) Key to use when writing info data.
  * @return bool True if the commit succeeded.
  */
 public function commit($metadata_key = null)
 {
     if (isset($metadata_key)) {
         $this->_key_value = $metadata_key;
     }
     // If the info is not already loaded, and the key value is empty,
     // then we don't have enough info to do the commit
     if (!$this->_loaded && empty($this->_key_value)) {
         return false;
     }
     // If there were no changes, do nothing and succeed.  Yay!
     if (!$this->_dirty) {
         return true;
     }
     foreach ((array) $this->__inforecord_array as $name => $record) {
         if (isset($record['changed']) && $record['changed']) {
             $value = $record['value'];
             if (is_array($value) || is_object($value)) {
                 $result = DB::update($this->_table_name, array($this->_key_name => $this->_key_value, 'name' => $name, 'value' => serialize($value), 'type' => 1), array('name' => $name, $this->_key_name => $this->_key_value));
             } else {
                 $result = DB::update($this->_table_name, array($this->_key_name => $this->_key_value, 'name' => $name, 'value' => $value, 'type' => 0), array('name' => $name, $this->_key_name => $this->_key_value));
             }
             if (Error::is_error($result)) {
                 $result->out();
             }
             $this->__inforecord_array[$name] = array('value' => $value);
         }
     }
     $this->_dirty = false;
     return true;
 }
开发者ID:habari,项目名称:system,代码行数:38,代码来源:inforecords.php

示例12: execute

 /**
  * Actually execute the request.
  * On success, returns TRUE and populates the response_body and response_headers fields.
  * On failure, throws error.
  */
 public function execute()
 {
     $this->prepare();
     $result = $this->processor->execute($this->method, $this->url, $this->headers, $this->body, $this->timeout);
     if ($result && !Error::is_error($result)) {
         // XXX exceptions?
         $this->response_headers = $this->processor->get_response_headers();
         $this->response_body = $this->processor->get_response_body();
         $this->executed = TRUE;
         return TRUE;
     } else {
         // actually, processor->execute should throw an Error which would bubble up
         // we need a new Error class and error handler for that, though
         $this->executed = FALSE;
         return $result;
     }
 }
开发者ID:anupom,项目名称:my-blog,代码行数:22,代码来源:remoterequest.php

示例13: SMTP

 /**
  * Connect to the SMTP server by instantiating a SMTP object.
  *
  * @return mixed Returns a reference to the SMTP object on success, or
  *			   a Error containing a descriptive error message on
  *			   failure.
  *
  * @since  1.2.0
  * @access public
  */
 public function &getSMTPObject()
 {
     if (is_object($this->_smtp) !== false) {
         return $this->_smtp;
     }
     $this->_smtp = new SMTP($this->host, $this->port, $this->localhost);
     /* If we still don't have an SMTP object at this point, fail. */
     if (is_object($this->_smtp) === false) {
         throw Error::raise('Failed to create a SMTP object', self::ERROR_CREATE);
     }
     /* Configure the SMTP connection. */
     if ($this->debug) {
         $this->_smtp->setDebug(true);
     }
     /* Attempt to connect to the configured SMTP server. */
     if (Error::is_error($res = $this->_smtp->connect($this->timeout))) {
         $error = $this->_error('Failed to connect to ' . $this->host . ':' . $this->port, $res);
         throw Error::raise($error, self::ERROR_CONNECT);
     }
     /* Attempt to authenticate if authentication has been enabled. */
     if ($this->auth) {
         $method = is_string($this->auth) ? $this->auth : '';
         if (Error::is_error($res = $this->_smtp->auth($this->username, $this->password, $method))) {
             $error = $this->_error("{$method} authentication failure", $res);
             $this->_smtp->rset();
             throw Error::raise($error, self::ERROR_AUTH);
         }
     }
     return $this->_smtp;
 }
开发者ID:habari-extras,项目名称:mail_smtp,代码行数:40,代码来源:mail.php

示例14: get_dashboard

 /**
  * Handles get requests for the dashboard
  * @todo update check should probably be cron'd and cached, not re-checked every load
  */
 public function get_dashboard()
 {
     // Not sure how best to determine this yet, maybe set an option on install, maybe do this:
     $firstpostdate = DB::get_value('SELECT min(pubdate) FROM {posts} WHERE status = ?', array(Post::status('published')));
     if (intval($firstpostdate) !== 0) {
         $firstpostdate = time() - $firstpostdate;
     }
     $this->theme->active_time = array('years' => floor($firstpostdate / 31556736), 'months' => floor($firstpostdate % 31556736 / 2629728), 'days' => round($firstpostdate % 2629728 / 86400));
     // get the active theme, so we can check it
     $active_theme = Themes::get_active();
     $active_theme = $active_theme->name . ':' . $active_theme->version;
     // if the active plugin list has changed, expire the updates cache
     if (Cache::has('dashboard_updates') && Cache::get('dashboard_updates_plugins') != Options::get('active_plugins')) {
         Cache::expire('dashboard_updates');
     }
     // if the theme version has changed, expire the updates cache
     if (Cache::has('dashboard_updates') && Cache::get('dashboard_updates_theme') != $active_theme) {
         Cache::expire('dashboard_updates');
     }
     /*
      * Check for updates to core and any hooked plugins
      * cache the output so we don't make a request every load but can still display updates
      */
     if (Cache::has('dashboard_updates')) {
         $this->theme->updates = Cache::get('dashboard_updates');
     } else {
         $updates = Update::check();
         if (!Error::is_error($updates)) {
             Cache::set('dashboard_updates', $updates);
             $this->theme->updates = $updates;
             // cache the set of plugins we just used to check for
             Cache::set('dashboard_updates_plugins', Options::get('active_plugins'));
             // cache the active theme we just used to check for
             Cache::set('dashboard_updates_theme', $active_theme);
         } else {
             $this->theme->updates = array();
         }
     }
     $this->theme->stats = array('author_count' => Users::get(array('count' => 1)), 'page_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('published'))), 'entry_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('published'))), 'comment_count' => Comments::count_total(Comment::STATUS_APPROVED, FALSE), 'tag_count' => Tags::count_total(), 'page_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'entry_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'unapproved_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_UNAPPROVED, FALSE) : Comments::count_by_author(User::identify()->id, Comment::STATUS_UNAPPROVED), 'spam_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_SPAM, FALSE) : Comments::count_by_author(User::identify()->id, Comment::STATUS_SPAM), 'user_entry_scheduled_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('scheduled'), 'user_id' => User::identify()->id)));
     $this->fetch_dashboard_modules();
     // check for first run
     $u = User::identify();
     if (!isset($u->info->experience_level)) {
         $this->theme->first_run = true;
         $u->info->experience_level = 'user';
         $u->info->commit();
     } else {
         $this->theme->first_run = false;
     }
     $this->display('dashboard');
 }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:55,代码来源:adminhandler.php

示例15: load_feeds

 private function load_feeds($params = array())
 {
     $cache_name = $this->class_name . '__' . md5(serialize($params));
     if (Cache::has($cache_name)) {
         // Read from cache
         return Cache::get($cache_name);
     } else {
         $url = 'http://feeds.delicious.com/v2/json/' . $params['user_id'];
         if ($params['tags']) {
             $url .= '/' . urlencode($params['tags']);
         }
         $url .= '?count=' . $params['num_item'];
         try {
             // Get JSON content via Delicious API
             $call = new RemoteRequest($url);
             $call->set_timeout(5);
             $result = $call->execute();
             if (Error::is_error($result)) {
                 throw Error::raise(_t('Unable to contact Delicious.', $this->class_name));
             }
             $response = $call->get_response_body();
             // Decode JSON
             $deliciousfeed = json_decode($response);
             if (!is_array($deliciousfeed)) {
                 // Response is not JSON
                 throw Error::raise(_t('Response is not correct, maybe Delicious server is down or API is changed.', $this->class_name));
             } else {
                 // Transform to DeliciousPost objects
                 $serial = serialize($deliciousfeed);
                 $serial = str_replace('O:8:"stdClass":', 'O:13:"DeliciousPost":', $serial);
                 $deliciousfeed = unserialize($serial);
             }
             // Do cache
             Cache::set($cache_name, $deliciousfeed, $params['cache_expiry']);
             return $deliciousfeed;
         } catch (Exception $e) {
             return $e->getMessage();
         }
     }
 }
开发者ID:anupom,项目名称:my-blog,代码行数:40,代码来源:deliciousfeed.plugin.php


注:本文中的Error::is_error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。