| 1 |
<?php |
| 2 |
/** |
| 3 |
* The provider for all core Page caching related functionality. |
| 4 |
* |
| 5 |
* @since 0.1.0 |
| 6 |
* |
| 7 |
* @package SolidWP\Performance |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Page_Cache; |
| 11 |
|
| 12 |
use SolidWP\Performance\Config\Config; |
| 13 |
use SolidWP\Performance\Contracts\Service_Provider; |
| 14 |
use SolidWP\Performance\Page_Cache\Compression\Collection; |
| 15 |
use SolidWP\Performance\Page_Cache\Compression\Strategies\Brotli; |
| 16 |
use SolidWP\Performance\Page_Cache\Compression\Strategies\Deflate; |
| 17 |
use SolidWP\Performance\Page_Cache\Compression\Strategies\Gzip; |
| 18 |
use SolidWP\Performance\Page_Cache\Compression\Strategies\Html; |
| 19 |
use SolidWP\Performance\Page_Cache\Compression\Strategies\Zstd; |
| 20 |
|
| 21 |
if ( ! defined( 'ABSPATH' ) ) { |
| 22 |
exit; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* The provider for all core Page caching related functionality. |
| 27 |
* |
| 28 |
* @since 0.1.0 |
| 29 |
* |
| 30 |
* @package SolidWP\Performance |
| 31 |
*/ |
| 32 |
class Provider extends Service_Provider { |
| 33 |
|
| 34 |
/** |
| 35 |
* {@inheritdoc} |
| 36 |
*/ |
| 37 |
public function register(): void { |
| 38 |
$this->container->when( Expiration::class ) |
| 39 |
->needs( '$seconds' ) |
| 40 |
->give( static fn( $c ): int => $c->get( Config::class )->get( 'page_cache.expiration' ) ); |
| 41 |
|
| 42 |
$this->container->when( WP_Context::class ) |
| 43 |
->needs( '$post_id' ) |
| 44 |
->give( static fn(): int => (int) get_the_ID() ); |
| 45 |
|
| 46 |
$this->container->when( Collection::class ) |
| 47 |
->needs( '$compressors' ) |
| 48 |
->give( |
| 49 |
static fn( $c ): array => [ |
| 50 |
// Different browser compression algorithms for saving and serving cached files. |
| 51 |
$c->get( Brotli::class ), |
| 52 |
$c->get( Zstd::class ), |
| 53 |
$c->get( Gzip::class ), |
| 54 |
$c->get( Deflate::class ), |
| 55 |
$c->get( Html::class ), |
| 56 |
] |
| 57 |
); |
| 58 |
|
| 59 |
$this->container->singleton( Collection::class, Collection::class ); |
| 60 |
} |
| 61 |
} |
| 62 |
|