Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src
File: loader.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO;
[2] Fix | Delete
[3] Fix | Delete
use WP_CLI;
[4] Fix | Delete
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Class that manages loading integrations if and only if all their conditionals are met.
[8] Fix | Delete
*/
[9] Fix | Delete
class Loader {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* The registered integrations.
[13] Fix | Delete
*
[14] Fix | Delete
* @var string[]
[15] Fix | Delete
*/
[16] Fix | Delete
protected $integrations = [];
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* The registered integrations.
[20] Fix | Delete
*
[21] Fix | Delete
* @var string[]
[22] Fix | Delete
*/
[23] Fix | Delete
protected $initializers = [];
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* The registered routes.
[27] Fix | Delete
*
[28] Fix | Delete
* @var string[]
[29] Fix | Delete
*/
[30] Fix | Delete
protected $routes = [];
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* The registered commands.
[34] Fix | Delete
*
[35] Fix | Delete
* @var string[]
[36] Fix | Delete
*/
[37] Fix | Delete
protected $commands = [];
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* The registered migrations.
[41] Fix | Delete
*
[42] Fix | Delete
* @var string[]
[43] Fix | Delete
*/
[44] Fix | Delete
protected $migrations = [];
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* The dependency injection container.
[48] Fix | Delete
*
[49] Fix | Delete
* @var ContainerInterface
[50] Fix | Delete
*/
[51] Fix | Delete
protected $container;
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Loader constructor.
[55] Fix | Delete
*
[56] Fix | Delete
* @param ContainerInterface $container The dependency injection container.
[57] Fix | Delete
*/
[58] Fix | Delete
public function __construct( ContainerInterface $container ) {
[59] Fix | Delete
$this->container = $container;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Registers an integration.
[64] Fix | Delete
*
[65] Fix | Delete
* @param string $class The class name of the integration to be loaded.
[66] Fix | Delete
*
[67] Fix | Delete
* @return void
[68] Fix | Delete
*/
[69] Fix | Delete
public function register_integration( $class ) {
[70] Fix | Delete
$this->integrations[] = $class;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Registers an initializer.
[75] Fix | Delete
*
[76] Fix | Delete
* @param string $class The class name of the initializer to be loaded.
[77] Fix | Delete
*
[78] Fix | Delete
* @return void
[79] Fix | Delete
*/
[80] Fix | Delete
public function register_initializer( $class ) {
[81] Fix | Delete
$this->initializers[] = $class;
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Registers a route.
[86] Fix | Delete
*
[87] Fix | Delete
* @param string $class The class name of the route to be loaded.
[88] Fix | Delete
*
[89] Fix | Delete
* @return void
[90] Fix | Delete
*/
[91] Fix | Delete
public function register_route( $class ) {
[92] Fix | Delete
$this->routes[] = $class;
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Registers a command.
[97] Fix | Delete
*
[98] Fix | Delete
* @param string $class The class name of the command to be loaded.
[99] Fix | Delete
*
[100] Fix | Delete
* @return void
[101] Fix | Delete
*/
[102] Fix | Delete
public function register_command( $class ) {
[103] Fix | Delete
$this->commands[] = $class;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
/**
[107] Fix | Delete
* Registers a migration.
[108] Fix | Delete
*
[109] Fix | Delete
* @param string $plugin The plugin the migration belongs to.
[110] Fix | Delete
* @param string $version The version of the migration.
[111] Fix | Delete
* @param string $class The class name of the migration to be loaded.
[112] Fix | Delete
*
[113] Fix | Delete
* @return void
[114] Fix | Delete
*/
[115] Fix | Delete
public function register_migration( $plugin, $version, $class ) {
[116] Fix | Delete
if ( ! \array_key_exists( $plugin, $this->migrations ) ) {
[117] Fix | Delete
$this->migrations[ $plugin ] = [];
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
$this->migrations[ $plugin ][ $version ] = $class;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* Loads all registered classes if their conditionals are met.
[125] Fix | Delete
*
[126] Fix | Delete
* @return void
[127] Fix | Delete
*/
[128] Fix | Delete
public function load() {
[129] Fix | Delete
$this->load_initializers();
[130] Fix | Delete
[131] Fix | Delete
if ( ! \did_action( 'init' ) ) {
[132] Fix | Delete
\add_action( 'init', [ $this, 'load_integrations' ] );
[133] Fix | Delete
}
[134] Fix | Delete
else {
[135] Fix | Delete
$this->load_integrations();
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
\add_action( 'rest_api_init', [ $this, 'load_routes' ] );
[139] Fix | Delete
[140] Fix | Delete
if ( \defined( 'WP_CLI' ) && \WP_CLI ) {
[141] Fix | Delete
$this->load_commands();
[142] Fix | Delete
}
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Returns all registered migrations.
[147] Fix | Delete
*
[148] Fix | Delete
* @param string $plugin The plugin to get the migrations for.
[149] Fix | Delete
*
[150] Fix | Delete
* @return string[]|false The registered migrations. False if no migrations were registered.
[151] Fix | Delete
*/
[152] Fix | Delete
public function get_migrations( $plugin ) {
[153] Fix | Delete
if ( ! \array_key_exists( $plugin, $this->migrations ) ) {
[154] Fix | Delete
return false;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
return $this->migrations[ $plugin ];
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
/**
[161] Fix | Delete
* Loads all registered commands.
[162] Fix | Delete
*
[163] Fix | Delete
* @return void
[164] Fix | Delete
*/
[165] Fix | Delete
protected function load_commands() {
[166] Fix | Delete
foreach ( $this->commands as $class ) {
[167] Fix | Delete
$command = $this->container->get( $class );
[168] Fix | Delete
[169] Fix | Delete
WP_CLI::add_command( $class::get_namespace(), $command );
[170] Fix | Delete
}
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* Loads all registered initializers if their conditionals are met.
[175] Fix | Delete
*
[176] Fix | Delete
* @return void
[177] Fix | Delete
*/
[178] Fix | Delete
protected function load_initializers() {
[179] Fix | Delete
foreach ( $this->initializers as $class ) {
[180] Fix | Delete
if ( ! $this->conditionals_are_met( $class ) ) {
[181] Fix | Delete
continue;
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
$this->container->get( $class )->initialize();
[185] Fix | Delete
}
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* Loads all registered integrations if their conditionals are met.
[190] Fix | Delete
*
[191] Fix | Delete
* @return void
[192] Fix | Delete
*/
[193] Fix | Delete
public function load_integrations() {
[194] Fix | Delete
foreach ( $this->integrations as $class ) {
[195] Fix | Delete
if ( ! $this->conditionals_are_met( $class ) ) {
[196] Fix | Delete
continue;
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
$this->container->get( $class )->register_hooks();
[200] Fix | Delete
}
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* Loads all registered routes if their conditionals are met.
[205] Fix | Delete
*
[206] Fix | Delete
* @return void
[207] Fix | Delete
*/
[208] Fix | Delete
public function load_routes() {
[209] Fix | Delete
foreach ( $this->routes as $class ) {
[210] Fix | Delete
if ( ! $this->conditionals_are_met( $class ) ) {
[211] Fix | Delete
continue;
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
$this->container->get( $class )->register_routes();
[215] Fix | Delete
}
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Checks if all conditionals of a given integration are met.
[220] Fix | Delete
*
[221] Fix | Delete
* @param Loadable_Interface $class The class name of the integration.
[222] Fix | Delete
*
[223] Fix | Delete
* @return bool Whether or not all conditionals of the integration are met.
[224] Fix | Delete
*/
[225] Fix | Delete
protected function conditionals_are_met( $class ) {
[226] Fix | Delete
$conditionals = $class::get_conditionals();
[227] Fix | Delete
foreach ( $conditionals as $conditional ) {
[228] Fix | Delete
if ( ! $this->container->get( $conditional )->is_met() ) {
[229] Fix | Delete
return false;
[230] Fix | Delete
}
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
return true;
[234] Fix | Delete
}
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function