| 1 |
<?php |
| 2 |
/** |
| 3 |
* Webfonts API: Provider abstract class. |
| 4 |
* |
| 5 |
* Individual webfonts providers should extend this class and implement. |
| 6 |
* |
| 7 |
* @package WordPress |
| 8 |
* @subpackage WebFonts |
| 9 |
* @since 6.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( class_exists( 'WP_Webfonts_Provider' ) ) { |
| 13 |
return; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Abstract class for Webfonts API providers. |
| 18 |
* |
| 19 |
* The starting point to building a webfont service provider. |
| 20 |
* |
| 21 |
* What is a Provider? |
| 22 |
* |
| 23 |
* A provider contains the know-how (business logic) for how to |
| 24 |
* process its specific font service (i.e. local or remote) |
| 25 |
* and how to generate the `@font-face` styles for its service. |
| 26 |
* |
| 27 |
* It receives a collection of webfonts from the Controller |
| 28 |
* {@see WP_Webfonts_Provider::set_setfonts()}, and when requested |
| 29 |
* {@see WP_Webfonts_Provider::get_css()}, it transforms them |
| 30 |
* into styles (in a performant way for the provider service |
| 31 |
* it manages). |
| 32 |
* |
| 33 |
* @since 6.0.0 |
| 34 |
*/ |
| 35 |
abstract class WP_Webfonts_Provider { |
| 36 |
|
| 37 |
/** |
| 38 |
* Webfonts to be processed. |
| 39 |
* |
| 40 |
* @since 6.0.0 |
| 41 |
* |
| 42 |
* @var array[] |
| 43 |
*/ |
| 44 |
protected $webfonts = array(); |
| 45 |
|
| 46 |
/** |
| 47 |
* Sets this provider's webfonts property. |
| 48 |
* |
| 49 |
* The API's Controller passes this provider's webfonts |
| 50 |
* for processing here in the provider. |
| 51 |
* |
| 52 |
* @since 6.0.0 |
| 53 |
* |
| 54 |
* @param array[] $webfonts Registered webfonts. |
| 55 |
*/ |
| 56 |
public function set_webfonts( array $webfonts ) { |
| 57 |
$this->webfonts = $webfonts; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Gets the `@font-face` CSS for the provider's webfonts. |
| 62 |
* |
| 63 |
* This method is where the provider does it processing to build the |
| 64 |
* needed `@font-face` CSS for all of its webfonts. Specifics of how |
| 65 |
* this processing is done is contained in each provider. |
| 66 |
* |
| 67 |
* @since 6.0.0 |
| 68 |
* |
| 69 |
* @return string The `@font-face` CSS. |
| 70 |
*/ |
| 71 |
abstract public function get_css(); |
| 72 |
} |
| 73 |
|