-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Engine\Common; | ||
|
||
use WP_Filesystem_Direct; | ||
|
||
abstract class AbstractFileSystem { | ||
|
||
/** | ||
* WP Filesystem instance. | ||
* | ||
* @var WP_Filesystem_Direct | ||
*/ | ||
protected $filesystem; | ||
|
||
/** | ||
* Constructor method. | ||
* Initializes a new instance of the Controller class. | ||
* | ||
* @param WP_Filesystem_Direct $filesystem Filesystem class. | ||
*/ | ||
public function __construct( $filesystem = null ) { | ||
$this->filesystem = $filesystem ?? rocket_direct_filesystem(); | ||
} | ||
|
||
/** | ||
* Checks if a given path exists in the filesystem. | ||
* | ||
* @param string $path The path to check. | ||
* @return bool True if the path exists, false otherwise. | ||
*/ | ||
public function exists( string $path ): bool { | ||
return $this->filesystem->exists( $path ); | ||
} | ||
|
||
/** | ||
* Retrieves the contents of a file at the given path. | ||
* | ||
* @param string $path The path to the file. | ||
* @return string|false The file contents on success, false on failure. | ||
*/ | ||
public function get_contents( string $path ) { | ||
return $this->filesystem->get_contents( $path ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Engine\Media\Fonts\Controller; | ||
|
||
use WP_Rocket\Engine\Common\AbstractFileSystem; | ||
use WP_Rocket\Logger\Logger; | ||
use WP_Filesystem_Direct; | ||
|
||
class Filesystem extends AbstractFileSystem { | ||
|
||
/** | ||
* Path to the fonts storage | ||
* | ||
* @var string | ||
*/ | ||
private $path; | ||
|
||
/** | ||
* Version of the fonts. | ||
* | ||
* @var int | ||
*/ | ||
private $version; | ||
|
||
/** | ||
* Instantiate the class | ||
* | ||
* @param string $base_path Base path to the fonts storage. | ||
* @param WP_Filesystem_Direct $filesystem WP Filesystem instance. | ||
*/ | ||
public function __construct( $base_path, $filesystem = null ) { | ||
parent::__construct( is_null( $filesystem ) ? rocket_direct_filesystem() : $filesystem ); | ||
|
||
$this->path = $base_path . get_current_blog_id() . '/'; | ||
} | ||
|
||
/** | ||
* Hash the url | ||
* | ||
* @param string $font_url Font url. | ||
* | ||
* @return string | ||
*/ | ||
private function hash_url( string $font_url ): string { | ||
return md5( $font_url ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
namespace WP_Rocket\Engine\Media\Fonts\Frontend; | ||
|
||
use WP_Rocket\Engine\Media\Fonts\Context\Context; | ||
use WP_Rocket\Engine\Media\Fonts\Controller\Filesystem; | ||
use WP_Rocket\Engine\Optimization\RegexTrait; | ||
use WP_Rocket\Logger\Logger; | ||
use WP_Filesystem_Direct; | ||
|
@@ -29,7 +30,7 @@ class Controller { | |
/** | ||
* WordPress filesystem. | ||
* | ||
* @var WP_Filesystem_Direct | ||
* @var WP_Rocket\Engine\Media\Fonts\Controller\Filesystem; | ||
Check failure on line 33 in inc/Engine/Media/Fonts/Frontend/Controller.php
|
||
*/ | ||
private $filesystem; | ||
|
||
|
@@ -43,10 +44,10 @@ class Controller { | |
/** | ||
* Constructor. | ||
* | ||
* @param Context $context Context instance. | ||
* @param WP_Filesystem_Direct|null $filesystem WordPress filesystem. | ||
* @param Context $context Context instance. | ||
* @param WP_Rocket\Engine\Media\Fonts\Controller\Filesystem|null $filesystem WordPress filesystem. | ||
*/ | ||
public function __construct( Context $context, ?WP_Filesystem_Direct $filesystem ) { | ||
public function __construct( Context $context, ?Filesystem $filesystem ) { | ||
Check failure on line 50 in inc/Engine/Media/Fonts/Frontend/Controller.php
|
||
$this->context = $context; | ||
$this->base_path = rocket_get_constant( 'WP_ROCKET_CACHE_ROOT_PATH', '' ) . 'fonts/' . get_current_blog_id() . '/'; | ||
$this->base_url = rocket_get_constant( 'WP_ROCKET_CACHE_ROOT_URL', '' ) . 'fonts/' . get_current_blog_id() . '/'; | ||
|
@@ -130,7 +131,7 @@ protected function get_optimized_markup( string $hash, string $original_url ): s | |
* | ||
* @param bool $enable Tells if we are enabling or not the inline css output. | ||
*/ | ||
$inline_fonts_css = wpm_apply_filters_typed( 'boolean', 'rocket_host_fonts_locally_inline_css', false ); | ||
$inline_fonts_css = wpm_apply_filters_typed( 'boolean', 'rocket_host_fonts_locally_inline_css', true ); | ||
if ( $inline_fonts_css ) { | ||
$raw_path = $this->base_path . $path . '.css'; | ||
$inline_css = $this->get_font_inline_css( $gf_parameters, $raw_path ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters