| 1 |
<?php |
| 2 |
/** |
| 3 |
* Registers DOM related functionality in the container. |
| 4 |
* |
| 5 |
* @package SolidWP\Performance |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Dom; |
| 11 |
|
| 12 |
use SolidWP\Performance\Contracts\Service_Provider; |
| 13 |
use SolidWP\Performance\Dom\Modifiers\Image_Transformation_Modifier; |
| 14 |
use SolidWP\Performance\Dom\Modifiers\Lazy_Load_Modifier; |
| 15 |
use SolidWP\Performance\StellarWP\Pipeline\Pipeline; |
| 16 |
|
| 17 |
/** |
| 18 |
* Registers DOM related functionality in the container. |
| 19 |
* |
| 20 |
* @package SolidWP\Performance |
| 21 |
*/ |
| 22 |
final class Provider extends Service_Provider { |
| 23 |
|
| 24 |
public const PIPELINE = 'solid_performance.dom.modifier_pipeline'; |
| 25 |
|
| 26 |
/** |
| 27 |
* @inheritDoc |
| 28 |
*/ |
| 29 |
public function register(): void { |
| 30 |
$this->register_dom_modifier_pipeline(); |
| 31 |
|
| 32 |
// Run the HTML through the pipeline before being rendered. |
| 33 |
add_filter( |
| 34 |
'solidwp/performance/cache/html', |
| 35 |
$this->container->callback( Modifier::class, 'modify' ), |
| 36 |
10, |
| 37 |
1 |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Register the dom modifier pipeline steps. |
| 43 |
* |
| 44 |
* @return void |
| 45 |
*/ |
| 46 |
private function register_dom_modifier_pipeline(): void { |
| 47 |
$this->container->singleton( |
| 48 |
self::PIPELINE, |
| 49 |
fn(): Pipeline => ( new Pipeline( $this->container ) )->through( |
| 50 |
// Register any dom modifier pipeline stages here. |
| 51 |
[ |
| 52 |
Image_Transformation_Modifier::class, |
| 53 |
Lazy_Load_Modifier::class, |
| 54 |
] |
| 55 |
) |
| 56 |
); |
| 57 |
|
| 58 |
$this->container->when( Modifier::class ) |
| 59 |
->needs( Pipeline::class ) |
| 60 |
->give( static fn( $c ) => $c->get( self::PIPELINE ) ); |
| 61 |
} |
| 62 |
} |
| 63 |
|