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


PHP WP_CLI::get_cache方法代码示例

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


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

示例1: download

 /**
  * Download core WordPress files.
  *
  * ## OPTIONS
  *
  * [--path=<path>]
  * : Specify the path in which to install WordPress.
  *
  * [--locale=<locale>]
  * : Select which language you want to download.
  *
  * [--version=<version>]
  * : Select which version you want to download.
  *
  * [--force]
  * : Overwrites existing files, if present.
  *
  * ## EXAMPLES
  *
  *     wp core download --version=3.3
  *
  * @when before_wp_load
  */
 public function download($args, $assoc_args)
 {
     if (!isset($assoc_args['force']) && is_readable(ABSPATH . 'wp-load.php')) {
         WP_CLI::error('WordPress files seem to already be present here.');
     }
     if (!is_dir(ABSPATH)) {
         WP_CLI::log(sprintf('Creating directory %s', ABSPATH));
         WP_CLI::launch(Utils\esc_cmd('mkdir -p %s', ABSPATH));
     }
     $locale = isset($assoc_args['locale']) ? $assoc_args['locale'] : 'en_US';
     if (isset($assoc_args['version'])) {
         $version = $assoc_args['version'];
         if ('en_US' === $locale) {
             $download_url = 'https://wordpress.org/wordpress-' . $version . '.tar.gz';
         } else {
             $download_url = sprintf('https://%s.wordpress.org/wordpress-%s-%s.tar.gz', substr($assoc_args['locale'], 0, 2), $version, $locale);
         }
     } else {
         $offer = $this->get_download_offer($locale);
         $version = $offer['current'];
         $download_url = str_replace('.zip', '.tar.gz', $offer['download']);
     }
     WP_CLI::log(sprintf('Downloading WordPress %s (%s)...', $version, $locale));
     $cache = WP_CLI::get_cache();
     $cache_key = "core/{$locale}-{$version}.tar.gz";
     $cache_file = $cache->has($cache_key);
     if ($cache_file) {
         WP_CLI::log("Using cached file '{$cache_file}'...");
         self::_extract($cache_file, ABSPATH);
     } else {
         // We need to use a temporary file because piping from cURL to tar is flaky
         // on MinGW (and probably in other environments too).
         $temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz';
         $headers = array('Accept' => 'application/json');
         $options = array('timeout' => 600, 'filename' => $temp);
         self::_request('GET', $download_url, $headers, $options);
         self::_extract($temp, ABSPATH);
         $cache->import($cache_key, $temp);
         unlink($temp);
     }
     WP_CLI::success('WordPress downloaded.');
 }
开发者ID:nb,项目名称:wp-cli,代码行数:65,代码来源:core.php

示例2: download

 /**
  * Download core WordPress files.
  *
  * ## OPTIONS
  *
  * [--path=<path>]
  * : Specify the path in which to install WordPress.
  *
  * [--locale=<locale>]
  * : Select which language you want to download.
  *
  * [--version=<version>]
  * : Select which version you want to download.
  *
  * [--force]
  * : Overwrites existing files, if present.
  *
  * ## EXAMPLES
  *
  *     wp core download --locale=nl_NL
  *
  * @when before_wp_load
  */
 public function download($args, $assoc_args)
 {
     if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'force') && is_readable(ABSPATH . 'wp-load.php')) {
         WP_CLI::error('WordPress files seem to already be present here.');
     }
     if (!is_dir(ABSPATH)) {
         WP_CLI::log(sprintf('Creating directory %s', ABSPATH));
         $mkdir = \WP_CLI\Utils\is_windows() ? 'mkdir %s' : 'mkdir -p %s';
         WP_CLI::launch(Utils\esc_cmd($mkdir, ABSPATH));
     }
     $locale = \WP_CLI\Utils\get_flag_value($assoc_args, 'locale', 'en_US');
     if (isset($assoc_args['version'])) {
         $version = $assoc_args['version'];
         $download_url = $this->get_download_url($version, $locale, 'tar.gz');
     } else {
         $offer = $this->get_download_offer($locale);
         if (!$offer) {
             WP_CLI::error("The requested locale ({$locale}) was not found.");
         }
         $version = $offer['current'];
         $download_url = str_replace('.zip', '.tar.gz', $offer['download']);
     }
     WP_CLI::log(sprintf('Downloading WordPress %s (%s)...', $version, $locale));
     $cache = WP_CLI::get_cache();
     $cache_key = "core/wordpress-{$version}-{$locale}.tar.gz";
     $cache_file = $cache->has($cache_key);
     $bad_cache = false;
     if ($cache_file) {
         WP_CLI::log("Using cached file '{$cache_file}'...");
         try {
             self::_extract($cache_file, ABSPATH);
         } catch (Exception $e) {
             WP_CLI::warning("Extraction failed, downloading a new copy...");
             $bad_cache = true;
         }
     }
     if (!$cache_file || $bad_cache) {
         // We need to use a temporary file because piping from cURL to tar is flaky
         // on MinGW (and probably in other environments too).
         $temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz';
         $headers = array('Accept' => 'application/json');
         $options = array('timeout' => 600, 'filename' => $temp);
         $response = Utils\http_request('GET', $download_url, null, $headers, $options);
         if (404 == $response->status_code) {
             WP_CLI::error("Release not found. Double-check locale or version.");
         } else {
             if (20 != substr($response->status_code, 0, 2)) {
                 WP_CLI::error("Couldn't access download URL (HTTP code {$response->status_code})");
             }
         }
         try {
             self::_extract($temp, ABSPATH);
         } catch (Exception $e) {
             WP_CLI::error("Couldn't extract WordPress archive. " . $e->getMessage());
         }
         $cache->import($cache_key, $temp);
         unlink($temp);
     }
     WP_CLI::success('WordPress downloaded.');
 }
开发者ID:staylor,项目名称:wp-cli,代码行数:83,代码来源:core.php

示例3: download

 /**
  * Download core WordPress files.
  *
  * ## OPTIONS
  *
  * [--path=<path>]
  * : Specify the path in which to install WordPress.
  *
  * [--locale=<locale>]
  * : Select which language you want to download.
  *
  * [--version=<version>]
  * : Select which version you want to download.
  *
  * [--force]
  * : Overwrites existing files, if present.
  *
  * ## EXAMPLES
  *
  *     wp core download --locale=nl_NL
  *
  * @when before_wp_load
  */
 public function download($args, $assoc_args)
 {
     $download_dir = !empty($assoc_args['path']) ? $assoc_args['path'] : ABSPATH;
     $wordpress_present = is_readable($download_dir . 'wp-load.php');
     if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'force') && $wordpress_present) {
         WP_CLI::error('WordPress files seem to already be present here.');
     }
     if (!is_dir($download_dir)) {
         if (!is_writable(dirname($download_dir))) {
             WP_CLI::error(sprintf("Insufficient permission to create directory %s", $download_dir));
         }
         WP_CLI::log(sprintf('Creating directory %s', $download_dir));
         $mkdir = \WP_CLI\Utils\is_windows() ? 'mkdir %s' : 'mkdir -p %s';
         WP_CLI::launch(Utils\esc_cmd($mkdir, $download_dir));
     }
     if (!is_writable($download_dir)) {
         WP_CLI::error(sprintf("%s is not writable by current user", $download_dir));
     }
     $locale = \WP_CLI\Utils\get_flag_value($assoc_args, 'locale', 'en_US');
     if (isset($assoc_args['version'])) {
         $version = $assoc_args['version'];
         $download_url = $this->get_download_url($version, $locale, 'tar.gz');
     } else {
         $offer = $this->get_download_offer($locale);
         if (!$offer) {
             WP_CLI::error("The requested locale ({$locale}) was not found.");
         }
         $version = $offer['current'];
         $download_url = str_replace('.zip', '.tar.gz', $offer['download']);
     }
     $from_version = '';
     if (file_exists($download_dir . 'wp-includes/version.php')) {
         global $wp_version;
         require_once $download_dir . 'wp-includes/version.php';
         $from_version = $wp_version;
     }
     WP_CLI::log(sprintf('Downloading WordPress %s (%s)...', $version, $locale));
     $cache = WP_CLI::get_cache();
     $cache_key = "core/wordpress-{$version}-{$locale}.tar.gz";
     $cache_file = $cache->has($cache_key);
     $bad_cache = false;
     if ($cache_file) {
         WP_CLI::log("Using cached file '{$cache_file}'...");
         try {
             self::_extract($cache_file, $download_dir);
         } catch (Exception $e) {
             WP_CLI::warning("Extraction failed, downloading a new copy...");
             $bad_cache = true;
         }
     }
     if (!$cache_file || $bad_cache) {
         // We need to use a temporary file because piping from cURL to tar is flaky
         // on MinGW (and probably in other environments too).
         $temp = \WP_CLI\Utils\get_temp_dir() . uniqid('wp_') . '.tar.gz';
         $headers = array('Accept' => 'application/json');
         $options = array('timeout' => 600, 'filename' => $temp);
         $response = Utils\http_request('GET', $download_url, null, $headers, $options);
         if (404 == $response->status_code) {
             WP_CLI::error("Release not found. Double-check locale or version.");
         } else {
             if (20 != substr($response->status_code, 0, 2)) {
                 WP_CLI::error("Couldn't access download URL (HTTP code {$response->status_code})");
             }
         }
         $md5_response = Utils\http_request('GET', $download_url . '.md5');
         if (20 != substr($md5_response->status_code, 0, 2)) {
             WP_CLI::error("Couldn't access md5 hash for release (HTTP code {$response->status_code})");
         }
         $md5_file = md5_file($temp);
         if ($md5_file === $md5_response->body) {
             WP_CLI::log('md5 hash verified: ' . $md5_file);
         } else {
             WP_CLI::error("md5 hash for download ({$md5_file}) is different than the release hash ({$md5_response->body})");
         }
         try {
             self::_extract($temp, $download_dir);
         } catch (Exception $e) {
//.........这里部分代码省略.........
开发者ID:anver,项目名称:wp-cli,代码行数:101,代码来源:core.php


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