Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src/memoizer...
File: presentation-memoizer.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Memoizers;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Context\Meta_Tags_Context;
[4] Fix | Delete
use Yoast\WP\SEO\Models\Indexable;
[5] Fix | Delete
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
[6] Fix | Delete
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* The presentation memoizer.
[10] Fix | Delete
*/
[11] Fix | Delete
class Presentation_Memoizer {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* The service container.
[15] Fix | Delete
*
[16] Fix | Delete
* @var ContainerInterface
[17] Fix | Delete
*/
[18] Fix | Delete
protected $container;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Cache with indexable presentations.
[22] Fix | Delete
*
[23] Fix | Delete
* @var Indexable_Presentation[]
[24] Fix | Delete
*/
[25] Fix | Delete
protected $cache = [];
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Presentation_Memoizer constructor.
[29] Fix | Delete
*
[30] Fix | Delete
* @param ContainerInterface $service_container The service container.
[31] Fix | Delete
*/
[32] Fix | Delete
public function __construct( ContainerInterface $service_container ) {
[33] Fix | Delete
$this->container = $service_container;
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Gets the presentation of an indexable for a specific page type.
[38] Fix | Delete
* This function is memoized by the indexable so every call with the same indexable will yield the same result.
[39] Fix | Delete
*
[40] Fix | Delete
* @param Indexable $indexable The indexable to get a presentation of.
[41] Fix | Delete
* @param Meta_Tags_Context $context The current meta tags context.
[42] Fix | Delete
* @param string $page_type The page type.
[43] Fix | Delete
*
[44] Fix | Delete
* @return Indexable_Presentation The indexable presentation.
[45] Fix | Delete
*/
[46] Fix | Delete
public function get( Indexable $indexable, Meta_Tags_Context $context, $page_type ) {
[47] Fix | Delete
if ( ! isset( $this->cache[ $indexable->id ] ) ) {
[48] Fix | Delete
$presentation = $this->container->get( "Yoast\WP\SEO\Presentations\Indexable_{$page_type}_Presentation", ContainerInterface::NULL_ON_INVALID_REFERENCE );
[49] Fix | Delete
[50] Fix | Delete
if ( ! $presentation ) {
[51] Fix | Delete
$presentation = $this->container->get( Indexable_Presentation::class );
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
$context->presentation = $presentation->of(
[55] Fix | Delete
[
[56] Fix | Delete
'model' => $indexable,
[57] Fix | Delete
'context' => $context,
[58] Fix | Delete
]
[59] Fix | Delete
);
[60] Fix | Delete
[61] Fix | Delete
$this->cache[ $indexable->id ] = $context->presentation;
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
return $this->cache[ $indexable->id ];
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Clears the memoization of either a specific indexable or all indexables.
[69] Fix | Delete
*
[70] Fix | Delete
* @param Indexable|int|null $indexable Optional. The indexable or indexable id to clear the memoization of.
[71] Fix | Delete
*/
[72] Fix | Delete
public function clear( $indexable = null ) {
[73] Fix | Delete
if ( $indexable instanceof Indexable ) {
[74] Fix | Delete
unset( $this->cache[ $indexable->id ] );
[75] Fix | Delete
return;
[76] Fix | Delete
}
[77] Fix | Delete
if ( \is_int( $indexable ) ) {
[78] Fix | Delete
unset( $this->cache[ $indexable ] );
[79] Fix | Delete
return;
[80] Fix | Delete
}
[81] Fix | Delete
if ( $indexable === null ) {
[82] Fix | Delete
$this->cache = [];
[83] Fix | Delete
}
[84] Fix | Delete
}
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function