first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace WPML\CLI\Core;
use WPML\CLI\Core\Commands\ClearCacheFactory;
use WPML\CLI\Core\Commands\ICommand;
class BootStrap {
const MAIN_COMMAND = 'wpml';
/**
* @throws \Exception The exception thrown by \WP_CLI::add_command.
*/
public function init() {
$commands_factory = [
ClearCacheFactory::class,
];
foreach ( $commands_factory as $command_factory ) {
$command_factory_obj = new $command_factory();
$command = $command_factory_obj->create();
$this->add_command( $this->getFullCommand( $command ), $command );
}
}
/**
* @param string $command_text The subcommand.
* @param callable $command Command implementation as a class, function or closure.
*
* @throws \Exception The exception thrown by \WP_CLI::add_command.
*/
private function add_command( $command_text, $command ) {
\WP_CLI::add_command( $command_text, $command );
}
/**
* @param ICommand $command Command implementation as a class, function or closure.
*
* @return string The sub command prefixed by the top-level command (all trimmed).
*/
private function getFullCommand( $command ) {
return trim( self::MAIN_COMMAND . ' ' . $command->get_command() );
}
}

View File

@@ -0,0 +1,5 @@
<?php
namespace WPML\CLI\Core\Commands;
interface IWPML_Core extends IWPML_Command_Factory {
}

View File

@@ -0,0 +1,40 @@
<?php
namespace WPML\CLI\Core\Commands;
class ClearCache implements ICommand {
/**
* @var \WPML_Cache_Directory
*/
private $cache_directory;
public function __construct( \WPML_Cache_Directory $cache_directory ) {
$this->cache_directory = $cache_directory;
}
/**
* Clear the WPML cache
*
* ## EXAMPLE
*
* wp wpml clear-cache
*
* @when wpml_loaded
*
* {@inheritDoc}
*/
public function __invoke( $args, $assoc_args ) {
icl_cache_clear();
$this->cache_directory->remove();
\WP_CLI::success( 'WPML cache cleared' );
}
/**
* @return string
*/
public function get_command() {
return 'clear-cache';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace WPML\CLI\Core\Commands;
interface ICommand {
/**
* @param string[] $args
* @param array<string,string> $assoc_args
*
* @return mixed
*/
public function __invoke( $args, $assoc_args );
/**
* @return string
*/
public function get_command();
}

View File

@@ -0,0 +1,15 @@
<?php
namespace WPML\CLI\Core\Commands;
use function WPML\Container\make;
class ClearCacheFactory implements IWPML_Core {
/**
* @return ClearCache
* @throws \WPML\Auryn\InjectionException If it's not possible to create the instance (see \WPML\Auryn\Injector::make).
*/
public function create() {
return make( ClearCache::class );
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace WPML\CLI\Core\Commands;
interface IWPML_Command_Factory {
/**
* @return ICommand
*/
public function create();
}