Skip to content

Commit

Permalink
simplified API
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Dec 6, 2021
1 parent f392d6e commit 8eef162
Show file tree
Hide file tree
Showing 18 changed files with 573 additions and 2,305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package WordPress
* @subpackage WebFonts
* @since 5.9.0
* @since 6.0.0
*/

/**
Expand All @@ -16,21 +16,21 @@
*
* When enqueued styles are rendered, the Controller passes its
* 'local' webfonts {@see WP_Webfonts_Provider::set_setfonts()}
* and then triggers {@see WP_Webfonts_Local_Provider::get_css()}
* and then triggers {@see WP_Webfonts_Provider_Local::get_css()}
* the processing to transform them into `@font-face` styles.
*
* All know-how (business logic) for how to interact with and
* generate styles from locally-hosted font files is contained
* in this provider.
*
* @since 5.9.0
* @since 6.0.0
*/
class WP_Webfonts_Local_Provider extends WP_Webfonts_Provider {
class WP_Webfonts_Provider_Local extends WP_Webfonts_Provider {

/**
* The provider's unique ID.
*
* @since 5.9.0
* @since 6.0.0
*
* @var string
*/
Expand Down Expand Up @@ -82,7 +82,7 @@ class WP_Webfonts_Local_Provider extends WP_Webfonts_Provider {
* }
* </code>
*
* @since 5.9.0
* @since 6.0.0
*
* @return string The `@font-face` CSS.
*/
Expand All @@ -103,7 +103,7 @@ public function get_css() {
/**
* Order `src` items to optimize for browser support.
*
* @since 5.9.0
* @since 6.0.0
*
* @param array $webfont Webfont to process.
* @return array
Expand Down Expand Up @@ -176,7 +176,7 @@ private function order_src( array $webfont ) {
/**
* Builds the font-family's CSS.
*
* @since 5.9.0
* @since 6.0.0
*
* @param array $webfont Webfont to process.
* @return string This font-family's CSS.
Expand Down Expand Up @@ -221,7 +221,7 @@ private function build_font_face_css( array $webfont ) {
/**
* Compiles the `src` into valid CSS.
*
* @since 5.9.0
* @since 6.0.0
*
* @param string $font_family Font family.
* @param array $value Value to process.
Expand All @@ -246,7 +246,7 @@ private function compile_src( $font_family, array $value ) {
/**
* Compiles the font variation settings.
*
* @since 5.9.0
* @since 6.0.0
*
* @param array $font_variation_settings Array of font variation settings.
* @return string The CSS.
Expand Down
68 changes: 68 additions & 0 deletions lib/class-wp-webfonts-provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Webfonts API: Provider abstract class.
*
* Individual webfonts providers should extend this class and implement.
*
* @package WordPress
* @subpackage WebFonts
* @since 6.0.0
*/

/**
* Abstract class for Webfonts API providers.
*
* The starting point to building a webfont service provider.
*
* What is a Provider?
*
* A provider contains the know-how (business logic) for how to
* process its specific font service (i.e. local or remote)
* and how to generate the `@font-face` styles for its service.
*
* It receives a collection of webfonts from the Controller
* {@see WP_Webfonts_Provider::set_setfonts()}, and when requested
* {@see WP_Webfonts_Provider::get_css()}, it transforms them
* into styles (in a performant way for the provider service
* it manages).
*
* @since 6.0.0
*/
abstract class WP_Webfonts_Provider {

/**
* Webfonts to be processed.
*
* @since 6.0.0
*
* @var array[]
*/
protected $webfonts = array();

/**
* Sets this provider's webfonts property.
*
* The API's Controller passes this provider's webfonts
* for processing here in the provider.
*
* @since 6.0.0
*
* @param array[] $webfonts Registered webfonts.
*/
public function set_webfonts( array $webfonts ) {
$this->webfonts = $webfonts;
}

/**
* Gets the `@font-face` CSS for the provider's webfonts.
*
* This method is where the provider does it processing to build the
* needed `@font-face` CSS for all of its webfonts. Specifics of how
* this processing is done is contained in each provider.
*
* @since 6.0.0
*
* @return string The `@font-face` CSS.
*/
abstract public function get_css();
}
Loading

0 comments on commit 8eef162

Please sign in to comment.