| 1 |
<?php |
| 2 |
|
| 3 |
namespace FlyWP\StaticSite\Engine\Discovery; |
| 4 |
|
| 5 |
/** |
| 6 |
* Files that pages do not always link: robots.txt, favicon.ico, the site icon and the theme style.css. |
| 7 |
* |
| 8 |
* - WordPress serves robots.txt and favicon.ico through rewrite rules under the home path, also in a subdirectory install. |
| 9 |
* - Multisite is out of scope. The engine builds one site: the site of the current home URL. |
| 10 |
* - No directory scan. Only style.css of the theme and the parent theme. |
| 11 |
* |
| 12 |
* @since 1.8.0 |
| 13 |
*/ |
| 14 |
class SiteFileSource implements UrlSource { |
| 15 |
|
| 16 |
/** |
| 17 |
* @var WordPressGateway |
| 18 |
*/ |
| 19 |
private $wp; |
| 20 |
|
| 21 |
/** |
| 22 |
* @param WordPressGateway $wp Gateway. |
| 23 |
*/ |
| 24 |
public function __construct( WordPressGateway $wp ) { |
| 25 |
$this->wp = $wp; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* {@inheritdoc} |
| 30 |
*/ |
| 31 |
public function urls() { |
| 32 |
$home = $this->wp->home_url(); |
| 33 |
|
| 34 |
if ( '' !== (string) $this->wp->option( 'permalink_structure' ) ) { |
| 35 |
yield new DiscoveredUrl( $home . 'robots.txt', 'file' ); |
| 36 |
yield new DiscoveredUrl( $home . 'favicon.ico', 'file' ); |
| 37 |
} |
| 38 |
|
| 39 |
foreach ( array_merge( $this->wp->site_icon_urls(), $this->wp->theme_stylesheet_urls() ) as $url ) { |
| 40 |
yield new DiscoveredUrl( $url, 'asset' ); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|