Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do

namespace VendorDuplicator\GuzzleHttp; /** * Debug function used to describe the provided value type and class. * * @param mixed $input Any type of variable to describe the type of. This * parameter misses a typehint because of that. * * @return string Returns a string containing the type of the variable and * if a class is provided, the class name. * * @deprecated describe_type will be removed in guzzlehttp/guzzle:8.0. Use Utils::describeType instead. */ function describe_type($input): string { return Utils::describeType($input); } /** * Parses an array of header lines into an associative array of headers. * * @param iterable $lines Header lines array of strings in the following * format: "Name: Value" * * @deprecated headers_from_lines will be removed in guzzlehttp/guzzle:8.0. Use Utils::headersFromLines instead. */ function headers_from_lines(iterable $lines): array { return Utils::headersFromLines($lines); } /** * Returns a debug stream based on the provided variable. * * @param mixed $value Optional value * * @return resource * * @deprecated debug_resource will be removed in guzzlehttp/guzzle:8.0. Use Utils::debugResource instead. */ function debug_resource($value = null) { return Utils::debugResource($value); } /** * Chooses and creates a default handler to use based on the environment. * * The returned handler is not wrapped by any default middlewares. * * @return callable(\Psr\Http\Message\RequestInterface, array): Promise\PromiseInterface Returns the best handler for the given system. * * @throws \RuntimeException if no viable Handler is available. * * @deprecated choose_handler will be removed in guzzlehttp/guzzle:8.0. Use Utils::chooseHandler instead. */ function choose_handler(): callable { return Utils::chooseHandler(); } /** * Get the default User-Agent string to use with Guzzle. * * @deprecated default_user_agent will be removed in guzzlehttp/guzzle:8.0. Use Utils::defaultUserAgent instead. */ function default_user_agent(): string { return Utils::defaultUserAgent(); } /** * Returns the default cacert bundle for the current system. * * First, the openssl.cafile and curl.cainfo php.ini settings are checked. * If those settings are not configured, then the common locations for * bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X * and Windows are checked. If any of these file locations are found on * disk, they will be utilized. * * Note: the result of this function is cached for subsequent calls. * * @throws \RuntimeException if no bundle can be found. * * @deprecated default_ca_bundle will be removed in guzzlehttp/guzzle:8.0. This function is not needed in PHP 5.6+. */ function default_ca_bundle(): string { return Utils::defaultCaBundle(); } /** * Creates an associative array of lowercase header names to the actual * header casing. * * @deprecated normalize_header_keys will be removed in guzzlehttp/guzzle:8.0. Use Utils::normalizeHeaderKeys instead. */ function normalize_header_keys(array $headers): array { return Utils::normalizeHeaderKeys($headers); } /** * Returns true if the provided host matches any of the no proxy areas. * * This method will strip a port from the host if it is present. Each pattern * can be matched with an exact match (e.g., "foo.com" == "foo.com") or a * partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" == * "baz.foo.com", but ".foo.com" != "foo.com"). * * Areas are matched in the following cases: * 1. "*" (without quotes) always matches any hosts. * 2. An exact match. * 3. The area starts with "." and the area is the last part of the host. e.g. * '.mit.edu' will match any host that ends with '.mit.edu'. * * @param string $host Host to check against the patterns. * @param string[] $noProxyArray An array of host patterns. * * @throws Exception\InvalidArgumentException * * @deprecated is_host_in_noproxy will be removed in guzzlehttp/guzzle:8.0. Use Utils::isHostInNoProxy instead. */ function is_host_in_noproxy(string $host, array $noProxyArray): bool { return Utils::isHostInNoProxy($host, $noProxyArray); } /** * Wrapper for json_decode that throws when an error occurs. * * @param string $json JSON data to parse * @param bool $assoc When true, returned objects will be converted * into associative arrays. * @param int $depth User specified recursion depth. * @param int $options Bitmask of JSON decode options. * * @return object|array|string|int|float|bool|null * * @throws Exception\InvalidArgumentException if the JSON cannot be decoded. * * @see https://www.php.net/manual/en/function.json-decode.php * @deprecated json_decode will be removed in guzzlehttp/guzzle:8.0. Use Utils::jsonDecode instead. */ function json_decode(string $json, bool $assoc = \false, int $depth = 512, int $options = 0) { return Utils::jsonDecode($json, $assoc, $depth, $options); } /** * Wrapper for JSON encoding that throws when an error occurs. * * @param mixed $value The value being encoded * @param int $options JSON encode option bitmask * @param int $depth Set the maximum depth. Must be greater than zero. * * @throws Exception\InvalidArgumentException if the JSON cannot be encoded. * * @see https://www.php.net/manual/en/function.json-encode.php * @deprecated json_encode will be removed in guzzlehttp/guzzle:8.0. Use Utils::jsonEncode instead. */ function json_encode($value, int $options = 0, int $depth = 512): string { return Utils::jsonEncode($value, $options, $depth); } namespace VendorDuplicator\Aws; use VendorDuplicator\GuzzleHttp\Client; use VendorDuplicator\Psr\Http\Message\RequestInterface; use VendorDuplicator\GuzzleHttp\ClientInterface; use VendorDuplicator\GuzzleHttp\Promise\FulfilledPromise; //----------------------------------------------------------------------------- // Functional functions //----------------------------------------------------------------------------- /** * Returns a function that always returns the same value; * * @param mixed $value Value to return. * * @return callable */ function constantly($value) { return function () use ($value) { return $value; }; } /** * Filters values that do not satisfy the predicate function $pred. * * @param mixed $iterable Iterable sequence of data. * @param callable $pred Function that accepts a value and returns true/false * * @return \Generator */ function filter($iterable, callable $pred) { foreach ($iterable as $value) { if ($pred($value)) { yield $value; } } } /** * Applies a map function $f to each value in a collection. * * @param mixed $iterable Iterable sequence of data. * @param callable $f Map function to apply. * * @return \Generator */ function map($iterable, callable $f) { foreach ($iterable as $value) { yield $f($value); } } /** * Creates a generator that iterates over a sequence, then iterates over each * value in the sequence and yields the application of the map function to each * value. * * @param mixed $iterable Iterable sequence of data. * @param callable $f Map function to apply. * * @return \Generator */ function flatmap($iterable, callable $f) { foreach (map($iterable, $f) as $outer) { foreach ($outer as $inner) { yield $inner; } } } /** * Partitions the input sequence into partitions of the specified size. * * @param mixed $iterable Iterable sequence of data. * @param int $size Size to make each partition (except possibly the last chunk) * * @return \Generator */ function partition($iterable, $size) { $buffer = []; foreach ($iterable as $value) { $buffer[] = $value; if (count($buffer) === $size) { yield $buffer; $buffer = []; } } if ($buffer) { yield $buffer; } } /** * Returns a function that invokes the provided variadic functions one * after the other until one of the functions returns a non-null value. * The return function will call each passed function with any arguments it * is provided. * * $a = function ($x, $y) { return null; }; * $b = function ($x, $y) { return $x + $y; }; * $fn = \Aws\or_chain($a, $b); * echo $fn(1, 2); // 3 * * @return callable */ function or_chain() { $fns = func_get_args(); return function () use ($fns) { $args = func_get_args(); foreach ($fns as $fn) { $result = $args ? call_user_func_array($fn, $args) : $fn(); if ($result) { return $result; } } return null; }; } //----------------------------------------------------------------------------- // JSON compiler and loading functions //----------------------------------------------------------------------------- /** * Loads a compiled JSON file from a PHP file. * * If the JSON file has not been cached to disk as a PHP file, it will be loaded * from the JSON source file and returned. * * @param string $path Path to the JSON file on disk * * @return mixed Returns the JSON decoded data. Note that JSON objects are * decoded as associative arrays. */ function load_compiled_json($path) { static $compiledList = []; $compiledFilepath = "{$path}.php"; if (!isset($compiledList[$compiledFilepath])) { if (is_readable($compiledFilepath)) { $compiledList[$compiledFilepath] = include $compiledFilepath; } } if (isset($compiledList[$compiledFilepath])) { return $compiledList[$compiledFilepath]; } if (!file_exists($path)) { throw new \InvalidArgumentException(sprintf("File not found: %s", $path)); } return json_decode(file_get_contents($path), \true); } /** * No-op */ function clear_compiled_json() { // pass } //----------------------------------------------------------------------------- // Directory iterator functions. //----------------------------------------------------------------------------- /** * Iterates over the files in a directory and works with custom wrappers. * * @param string $path Path to open (e.g., "s3://foo/bar"). * @param resource $context Stream wrapper context. * * @return \Generator Yields relative filename strings. */ function dir_iterator($path, $context = null) { $dh = $context ? opendir($path, $context) : opendir($path); if (!$dh) { throw new \InvalidArgumentException('File not found: ' . $path); } while (($file = readdir($dh)) !== \false) { yield $file; } closedir($dh); } /** * Returns a recursive directory iterator that yields absolute filenames. * * This iterator is not broken like PHP's built-in DirectoryIterator (which * will read the first file from a stream wrapper, then rewind, then read * it again). * * @param string $path Path to traverse (e.g., s3://bucket/key, /tmp) * @param resource $context Stream context options. * * @return \Generator Yields absolute filenames. */ function recursive_dir_iterator($path, $context = null) { $invalid = ['.' => \true, '..' => \true]; $pathLen = strlen($path) + 1; $iterator = dir_iterator($path, $context); $queue = []; do { while ($iterator->valid()) { $file = $iterator->current(); $iterator->next(); if (isset($invalid[basename($file)])) { continue; } $fullPath = "{$path}/{$file}"; yield $fullPath; if (is_dir($fullPath)) { $queue[] = $iterator; $iterator = map(dir_iterator($fullPath, $context), function ($file) use ($fullPath, $pathLen) { return substr("{$fullPath}/{$file}", $pathLen); }); continue; } } $iterator = array_pop($queue); } while ($iterator); } //----------------------------------------------------------------------------- // Misc. functions. //----------------------------------------------------------------------------- /** * Debug function used to describe the provided value type and class. * * @param mixed $input * * @return string Returns a string containing the type of the variable and * if a class is provided, the class name. */ function describe_type($input) { switch (gettype($input)) { case 'object': return 'object(' . get_class($input) . ')'; case 'array': return 'array(' . count($input) . ')'; default: ob_start(); var_dump($input); // normalize float vs double return str_replace('double(', 'float(', rtrim(ob_get_clean())); } } /** * Creates a default HTTP handler based on the available clients. * * @return callable */ function default_http_handler() { $version = guzzle_major_version(); // If Guzzle 6 or 7 installed if ($version === 6 || $version === 7) { return new \VendorDuplicator\Aws\Handler\GuzzleV6\GuzzleHandler(); } // If Guzzle 5 installed if ($version === 5) { return new \VendorDuplicator\Aws\Handler\GuzzleV5\GuzzleHandler(); } throw new \RuntimeException('Unknown Guzzle version: ' . $version); } /** * Gets the default user agent string depending on the Guzzle version * * @return string */ function default_user_agent() { $version = guzzle_major_version(); // If Guzzle 6 or 7 installed if ($version === 6 || $version === 7) { return \VendorDuplicator\GuzzleHttp\default_user_agent(); } // If Guzzle 5 installed if ($version === 5) { return \VendorDuplicator\GuzzleHttp\Client::getDefaultUserAgent(); } throw new \RuntimeException('Unknown Guzzle version: ' . $version); } /** * Get the major version of guzzle that is installed. * * @internal This function is internal and should not be used outside aws/aws-sdk-php. * @return int * @throws \RuntimeException */ function guzzle_major_version() { static $cache = null; if (null !== $cache) { return $cache; } if (defined('VendorDuplicator\GuzzleHttp\ClientInterface::VERSION')) { $version = (string) ClientInterface::VERSION; if ($version[0] === '6') { return $cache = 6; } if ($version[0] === '5') { return $cache = 5; } } elseif (defined('VendorDuplicator\GuzzleHttp\ClientInterface::MAJOR_VERSION')) { return $cache = ClientInterface::MAJOR_VERSION; } throw new \RuntimeException('Unable to determine what Guzzle version is installed.'); } /** * Serialize a request for a command but do not send it. * * Returns a promise that is fulfilled with the serialized request. * * @param CommandInterface $command Command to serialize. * * @return RequestInterface * @throws \RuntimeException */ function serialize(CommandInterface $command) { $request = null; $handlerList = $command->getHandlerList(); // Return a mock result. $handlerList->setHandler(function (CommandInterface $_, RequestInterface $r) use (&$request) { $request = $r; return new FulfilledPromise(new Result([])); }); call_user_func($handlerList->resolve(), $command)->wait(); if (!$request instanceof RequestInterface) { throw new \RuntimeException('Calling handler did not serialize request'); } return $request; } /** * Retrieves data for a service from the SDK's service manifest file. * * Manifest data is stored statically, so it does not need to be loaded more * than once per process. The JSON data is also cached in opcache. * * @param string $service Case-insensitive namespace or endpoint prefix of the * service for which you are retrieving manifest data. * * @return array * @throws \InvalidArgumentException if the service is not supported. */ function manifest($service = null) { // Load the manifest and create aliases for lowercased namespaces static $manifest = []; static $aliases = []; if (empty($manifest)) { $manifest = load_compiled_json(__DIR__ . '/data/manifest.json'); foreach ($manifest as $endpoint => $info) { $alias = strtolower($info['namespace']); if ($alias !== $endpoint) { $aliases[$alias] = $endpoint; } } } // If no service specified, then return the whole manifest. if ($service === null) { return $manifest; } // Look up the service's info in the manifest data. $service = strtolower($service); if (isset($manifest[$service])) { return $manifest[$service] + ['endpoint' => $service]; } if (isset($aliases[$service])) { return manifest($aliases[$service]); } throw new \InvalidArgumentException("The service \"{$service}\" is not provided by the AWS SDK for PHP."); } /** * Checks if supplied parameter is a valid hostname * * @param string $hostname * @return bool */ function is_valid_hostname($hostname) { return preg_match("/^([a-z\\d](-*[a-z\\d])*)(\\.([a-z\\d](-*[a-z\\d])*))*\\.?\$/i", $hostname) && preg_match("/^.{1,253}\$/", $hostname) && preg_match("/^[^\\.]{1,63}(\\.[^\\.]{0,63})*\$/", $hostname); } /** * Checks if supplied parameter is a valid host label * * @param $label * @return bool */ function is_valid_hostlabel($label) { return preg_match("/^(?!-)[a-zA-Z0-9-]{1,63}(?db = DB_Optm::cls(); } /** * List all site domains and ids on the network. */ public function network_list() { if ( !is_multisite() ) { WP_CLI::error('This is not a multisite installation!'); return; } $buf = WP_CLI::colorize("%CThe list of installs:%n\n"); $sites = get_sites(); foreach ( $sites as $site ) { $buf .= WP_CLI::colorize( '%Y' . $site->domain . $site->path . ':%n ID ' . $site->blog_id ) . "\n"; } WP_CLI::line($buf); } /** * Change to blog sent as param. * * @param array $args Description. */ private function change_to_blog( $args ) { if ( !isset( $args[0] ) || 'blog' !== $args[0] ) { return; } $this->current_blog = get_current_blog_id(); $blogid = $args[1]; if ( !is_numeric( $blogid ) ) { $error = WP_CLI::colorize( '%RError: invalid blog id entered.%n' ); WP_CLI::line( $error ); $this->network_list( $args ); return; } $site = get_blog_details( $blogid ); if ( false === $site ) { $error = WP_CLI::colorize( '%RError: invalid blog id entered.%n' ); WP_CLI::line( $error ); $this->network_list( $args ); return; } switch_to_blog( $blogid ); } /** * Change to previous blog. */ private function change_to_default() { // Check if previous blog set. if ( $this->current_blog ) { switch_to_blog( $this->current_blog ); // Switched to previous blog. $this->current_blog = false; } } /** * Show CLI response. * * @param boolean $result Flag if result is success or failure. * @param string $action Action name. */ private function show_response( $result, $action ) { if ($result) { WP_CLI::success( $result ); } else { WP_CLI::error( 'Error running optimization: ' . $action ); } } /** * Clean actions function. * * @param int $args Action arguments. * @param array $types What data to clean. */ private function clean_action( $args, $types ) { $this->change_to_blog( $args ); foreach ( $types as $type ) { $result = $this->db->handler_clean_db_cli( $type ); $this->show_response( $result, $type ); } $this->change_to_default(); } /** * Clear posts data(revisions, orphaned, auto drafts, trashed posts). * # Start clearing posts data. * $ wp litespeed-database clear_posts * $ wp litespeed-database clear_posts blog 2 * * @param string $args Action arguments. */ public function clear_posts( $args ) { $types = array( 'revision', 'orphaned_post_meta', 'auto_draft', 'trash_post', ); $this->clean_action( $args, $types ); } /** * Clear comments(spam and trash comments). * # Start clearing comments. * $ wp litespeed-database clear_comments * $ wp litespeed-database clear_comments blog 2 * * @param string $args Action arguments. */ public function clear_comments( $args ) { $types = array( 'spam_comment', 'trash_comment', ); $this->clean_action( $args, $types ); } /** * Clear trackbacks/pingbacks. * # Start clearing trackbacks/pingbacks. * $ wp litespeed-database clear_trackbacks * $ wp litespeed-database clear_trackbacks blog 2 * * @param string $args Action arguments. */ public function clear_trackbacks( $args ) { $types = array( 'trackback-pingback', ); $this->clean_action( $args, $types ); } /** * Clear transients. * # Start clearing transients. * $ wp litespeed-database clear_transients * $ wp litespeed-database clear_transients blog 2 * * @param string $args Action arguments. */ public function clear_transients( $args ) { $types = array( 'expired_transient', 'all_transients', ); $this->clean_action( $args, $types ); } /** * Optimize tables. * # Start optimizing tables. * $ wp litespeed-database optimize_tables * $ wp litespeed-database optimize_tables blog 2 * * @param string $args Action arguments. */ public function optimize_tables( $args ) { $types = array( 'optimize_tables', ); $this->clean_action( $args, $types ); } /** * Optimize database by running all possible operations. * # Start optimizing all. * $ wp litespeed-database optimize_all * $ wp litespeed-database optimize_all blog 2 * * @param string $args Action arguments. */ public function optimize_all( $args ) { $types = array( 'all', ); $this->clean_action( $args, $types ); } }