Skip to content

Commit 3dad255

Browse files
committed
simplified API
1 parent 71e9a30 commit 3dad255

18 files changed

+573
-2305
lines changed

lib/webfonts-api/providers/class-wp-webfonts-local-provider.php renamed to lib/class-wp-webfonts-provider-local.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @package WordPress
66
* @subpackage WebFonts
7-
* @since 5.9.0
7+
* @since 6.0.0
88
*/
99

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

3030
/**
3131
* The provider's unique ID.
3232
*
33-
* @since 5.9.0
33+
* @since 6.0.0
3434
*
3535
* @var string
3636
*/
@@ -82,7 +82,7 @@ class WP_Webfonts_Local_Provider extends WP_Webfonts_Provider {
8282
* }
8383
* </code>
8484
*
85-
* @since 5.9.0
85+
* @since 6.0.0
8686
*
8787
* @return string The `@font-face` CSS.
8888
*/
@@ -103,7 +103,7 @@ public function get_css() {
103103
/**
104104
* Order `src` items to optimize for browser support.
105105
*
106-
* @since 5.9.0
106+
* @since 6.0.0
107107
*
108108
* @param array $webfont Webfont to process.
109109
* @return array
@@ -176,7 +176,7 @@ private function order_src( array $webfont ) {
176176
/**
177177
* Builds the font-family's CSS.
178178
*
179-
* @since 5.9.0
179+
* @since 6.0.0
180180
*
181181
* @param array $webfont Webfont to process.
182182
* @return string This font-family's CSS.
@@ -221,7 +221,7 @@ private function build_font_face_css( array $webfont ) {
221221
/**
222222
* Compiles the `src` into valid CSS.
223223
*
224-
* @since 5.9.0
224+
* @since 6.0.0
225225
*
226226
* @param string $font_family Font family.
227227
* @param array $value Value to process.
@@ -246,7 +246,7 @@ private function compile_src( $font_family, array $value ) {
246246
/**
247247
* Compiles the font variation settings.
248248
*
249-
* @since 5.9.0
249+
* @since 6.0.0
250250
*
251251
* @param array $font_variation_settings Array of font variation settings.
252252
* @return string The CSS.

lib/class-wp-webfonts-provider.php

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

0 commit comments

Comments
 (0)