forked from php-embed/Embed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.php
More file actions
36 lines (29 loc) · 874 Bytes
/
Code.php
File metadata and controls
36 lines (29 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Gist\Detectors;
use Embed\Adapters\Gist\Extractor;
use Embed\Detectors\Code as Detector;
use Embed\EmbedCode;
use function Embed\html;
class Code extends Detector
{
public function detect(): ?EmbedCode
{
$parentResult = parent::detect();
return $parentResult !== null ? $parentResult : $this->fallback();
}
private function fallback(): ?EmbedCode
{
/** @var Extractor $extractor */
$extractor = $this->extractor;
$api = $extractor->getApi();
$code = $api->html('div');
$stylesheet = $api->str('stylesheet');
if ($code !== null && $stylesheet !== null) {
return new EmbedCode(
html('link', ['rel' => 'stylesheet', 'href' => $stylesheet]).$code
);
}
return null;
}
}