1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LAG\SmokerBundle\Response\Handler; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
6
|
|
|
use Goutte\Client; |
7
|
|
|
use LAG\SmokerBundle\Exception\Exception; |
8
|
|
|
use LAG\SmokerBundle\Url\Requirements\Mapping\MappingResolverInterface; |
9
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
10
|
|
|
|
11
|
|
|
class HtmlHandler extends AbstractHandler |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var MappingResolverInterface |
15
|
|
|
*/ |
16
|
|
|
private $mappingResolver; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var EntityManagerInterface |
20
|
|
|
*/ |
21
|
|
|
private $entityManager; |
22
|
|
|
|
23
|
|
|
public function __construct( |
24
|
|
|
MappingResolverInterface $mappingResolver, |
25
|
|
|
EntityManagerInterface $entityManager, |
26
|
|
|
array $configuration = [] |
27
|
|
|
) { |
28
|
|
|
parent::__construct($configuration); |
29
|
|
|
|
30
|
|
|
$this->mappingResolver = $mappingResolver; |
31
|
|
|
$this->entityManager = $entityManager; |
32
|
|
|
$this->configuration = $configuration; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function handle(string $routeName, Crawler $crawler, Client $client, array $options = []): void |
36
|
|
|
{ |
37
|
|
|
$configuration = $this->getConfiguration($routeName); |
38
|
|
|
$mapping = $this->mappingResolver->resolve($this->getMappingName($routeName), $routeName); |
|
|
|
|
39
|
|
|
|
40
|
|
|
foreach ($configuration as $selector => $content) { |
41
|
|
|
if ('{{' === substr($content, 0, 2) && '}}' === substr($content, -2)) { |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
// $provider = $this->registry->get('default'); |
45
|
|
|
// $provider->getRequirements($routeName, [ |
46
|
|
|
// 'where' => '', |
47
|
|
|
// ]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (false === strpos($crawler->filter($selector)->text(), $content)) { |
51
|
|
|
throw new Exception(); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Return the unique name of the response handler. |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public function getName(): string |
62
|
|
|
{ |
63
|
|
|
return 'html'; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|