|
Server : LiteSpeed System : Linux srv104790275 5.15.0-161-generic #171-Ubuntu SMP Sat Oct 11 08:17:01 UTC 2025 x86_64 User : dewac4139 ( 1077) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /home/mentaribetslot.com/public_html/wp-content/plugins/amp/src/Cli/ |
Upload File : |
<?php
/**
* Class OptimizerCommand.
*
* Commands that deal with the AMP optimizer.
*
* @package AmpProject\AmpWP
*/
namespace AmpProject\AmpWP\Cli;
use AmpProject\AmpWP\Infrastructure\CliCommand;
use AmpProject\AmpWP\Infrastructure\Service;
use AmpProject\AmpWP\Optimizer\OptimizerService;
use AmpProject\Optimizer\Error;
use AmpProject\Optimizer\ErrorCollection;
use WP_CLI;
/**
* Commands that deal with the AMP optimizer. (EXPERIMENTAL)
*
* Note: The Optimizer CLI commands are to be considered experimental, as
* the output they produce is currently not guaranteed to be consistent
* with the corresponding output from the web server code path.
*
* @since 2.1.0
* @internal
*/
final class OptimizerCommand implements Service, CliCommand {
/**
* Optimizer service instance to use.
*
* @var OptimizerService
*/
private $optimizer_service;
/**
* Get the name under which to register the CLI command.
*
* @return string The name under which to register the CLI command.
*/
public static function get_command_name() {
return 'amp optimizer';
}
/**
* OptimizerCommand constructor.
*
* @param OptimizerService $optimizer_service Optimizer service instance to use.
*/
public function __construct( OptimizerService $optimizer_service ) {
$this->optimizer_service = $optimizer_service;
}
/**
* Run a file through the AMP Optimizer. (EXPERIMENTAL)
*
* Note: The Optimizer CLI commands are to be considered experimental, as
* the output they produce is currently not guaranteed to be consistent
* with the corresponding output from the web server code path.
*
* ## OPTIONS
*
* [<file>]
* : Input file to run through the AMP Optimizer. Omit or use '-' to read from STDIN.
*
* ## EXAMPLES
*
* # Test <amp-img> SSR transformations and store them in a new file named 'output.html'.
* $ echo '<amp-img src="image.jpg" width="500" height="500">' | wp amp optimizer optimize > output.html
*
* @param array $args Array of positional arguments.
* @param array $assoc_args Associative array of associative arguments.
* @throws WP_CLI\ExitException If the requested file could not be read.
*/
public function optimize( $args, /** @noinspection PhpUnusedParameterInspection */ $assoc_args ) {
$file = '-';
if ( count( $args ) > 0 ) {
$file = array_shift( $args );
}
if (
'-' !== $file
&&
(
! is_file( $file )
||
! is_readable( $file )
)
) {
WP_CLI::error( "Could not read file: '{$file}'." );
}
if ( '-' === $file ) {
$file = 'php://stdin';
}
$html = file_get_contents( $file );
$errors = new ErrorCollection();
$optimized_html = $this->optimizer_service->optimizeHtml( $html, $errors );
WP_CLI::line( $optimized_html );
/** @var Error $error */
foreach ( $errors as $error ) {
WP_CLI::warning( "[{$error->getCode()}] {$error->getMessage()}" );
}
}
}