Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
parserchain.php
1
<?php
2
3
namespace
Bitrix\Main\UrlPreview
;
4
5
use
Bitrix\Main\ArgumentException
;
6
use
Bitrix\Main\Web\Uri
;
7
8
class
ParserChain
9
{
11
protected
static
$metadataParsers
= array(
12
'Bitrix\Main\UrlPreview\Parser\OpenGraph'
,
13
'Bitrix\Main\UrlPreview\Parser\SchemaOrg'
,
14
'Bitrix\Main\UrlPreview\Parser\Oembed'
,
15
'Bitrix\Main\UrlPreview\Parser\Common'
16
);
17
21
protected
static
$metadataParsersByHost
= [
22
'vk.com'
=>
'Bitrix\Main\UrlPreview\Parser\Vk'
,
23
'www.facebook.com'
=>
'Bitrix\Main\UrlPreview\Parser\Facebook'
,
24
'www.instagram.com'
=>
'Bitrix\Main\UrlPreview\Parser\Instagram'
,
25
'maps.apple.com'
=>
'Bitrix\Main\UrlPreview\Parser\AppleMaps'
,
26
'rutube.ru'
=>
'Bitrix\Main\UrlPreview\Parser\RuTube'
,
27
];
28
33
protected
static
function
getParserChain
(
Uri
$uri)
34
{
35
$result = array();
36
if
(isset(static::$metadataParsersByHost[$uri->
getHost
()]))
37
{
38
$result[] = static::$metadataParsersByHost[$uri->
getHost
()];
39
}
40
41
$result = array_merge($result, static::$metadataParsers);
42
43
return
$result;
44
}
45
51
public
static
function
extractMetadata(
HtmlDocument
$document)
52
{
53
foreach
(static::getParserChain($document->
getUri
()) as $parserClassName)
54
{
56
if
(class_exists($parserClassName))
57
{
58
$parser =
new
$parserClassName();
59
if
($parser instanceof
Parser
)
60
{
61
$parser->handle($document);
62
}
63
}
64
if
($document->
checkMetadata
())
65
{
66
break
;
67
}
68
}
69
}
70
78
public
static
function
registerMetadataParser
($host, $parserClassName)
79
{
80
if
(!class_exists($parserClassName) || !is_subclass_of($parserClassName,
'\Bitrix\Main\UrlPreview\Parser'
))
81
{
82
throw
new
ArgumentException
(
'Parser class must extend \Bitrix\Main\UrlPreview\Parser'
,
'parserClassName'
);
83
}
84
85
static::$metadataParsersByHost[$host] = $parserClassName;
86
}
87
}
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\PhoneNumber\Parser
Definition
parser.php:10
Bitrix\Main\UrlPreview\HtmlDocument
Definition
htmldocument.php:13
Bitrix\Main\UrlPreview\HtmlDocument\getUri
getUri()
Definition
htmldocument.php:61
Bitrix\Main\UrlPreview\HtmlDocument\checkMetadata
checkMetadata()
Definition
htmldocument.php:81
Bitrix\Main\UrlPreview\ParserChain
Definition
parserchain.php:9
Bitrix\Main\UrlPreview\ParserChain\registerMetadataParser
static registerMetadataParser($host, $parserClassName)
Definition
parserchain.php:78
Bitrix\Main\UrlPreview\ParserChain\$metadataParsers
static $metadataParsers
Definition
parserchain.php:11
Bitrix\Main\UrlPreview\ParserChain\$metadataParsersByHost
static $metadataParsersByHost
Definition
parserchain.php:21
Bitrix\Main\UrlPreview\ParserChain\getParserChain
static getParserChain(Uri $uri)
Definition
parserchain.php:33
Bitrix\Main\Web\Uri
Definition
uri.php:17
Bitrix\Main\Web\Uri\getHost
getHost()
Definition
uri.php:114
Bitrix\Main\UrlPreview
Definition
htmldocument.php:3
modules
main
lib
urlpreview
parserchain.php
Создано системой
1.10.0