These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Sylius package. |
||
5 | * |
||
6 | * (c) Paweł Jędrzejewski |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace Sylius\Behat\Service\Resolver; |
||
15 | |||
16 | use Behat\Mink\Session; |
||
17 | use Sylius\Behat\Page\SymfonyPageInterface; |
||
18 | use Symfony\Component\Routing\Matcher\UrlMatcherInterface; |
||
19 | use Webmozart\Assert\Assert; |
||
20 | |||
21 | /** |
||
22 | * @author Łukasz Chruściel <[email protected]> |
||
23 | */ |
||
24 | final class CurrentPageResolver implements CurrentPageResolverInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var Session |
||
28 | */ |
||
29 | private $session; |
||
30 | |||
31 | /** |
||
32 | * @var UrlMatcherInterface |
||
33 | */ |
||
34 | private $urlMatcher; |
||
35 | |||
36 | /** |
||
37 | * @param Session $session |
||
38 | * @param UrlMatcherInterface $urlMatcher |
||
39 | */ |
||
40 | public function __construct(Session $session, UrlMatcherInterface $urlMatcher) |
||
41 | { |
||
42 | $this->session = $session; |
||
43 | $this->urlMatcher = $urlMatcher; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | * |
||
49 | * @throws \LogicException |
||
50 | */ |
||
51 | public function getCurrentPageWithForm(array $pages) |
||
52 | { |
||
53 | $routeParameters = $this->urlMatcher->match(parse_url($this->session->getCurrentUrl(), PHP_URL_PATH)); |
||
0 ignored issues
–
show
Security
Bug
introduced
by
Loading history...
|
|||
54 | |||
55 | Assert::allIsInstanceOf($pages, SymfonyPageInterface::class); |
||
56 | |||
57 | foreach ($pages as $page) { |
||
58 | if ($routeParameters['_route'] === $page->getRouteName()) { |
||
59 | return $page; |
||
60 | } |
||
61 | } |
||
62 | |||
63 | throw new \LogicException('Route name could not be matched to provided pages.'); |
||
64 | } |
||
65 | } |
||
66 |