File tree Expand file tree Collapse file tree 3 files changed +72
-6
lines changed
tests/DependencyInjection/Compiler Expand file tree Collapse file tree 3 files changed +72
-6
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Netgen \Bundle \OpenGraphBundle \Handler \Literal ;
4+
5+ use eZ \Publish \Core \Base \Exceptions \InvalidArgumentException ;
6+ use Netgen \Bundle \OpenGraphBundle \Handler \HandlerInterface ;
7+ use Netgen \Bundle \OpenGraphBundle \MetaTag \Item ;
8+ use Symfony \Component \HttpFoundation \Request ;
9+ use Symfony \Component \HttpFoundation \RequestStack ;
10+
11+ class Url implements HandlerInterface
12+ {
13+ /**
14+ * @var \Symfony\Component\HttpFoundation\RequestStack
15+ */
16+ protected $ requestStack ;
17+
18+ public function __construct (RequestStack $ requestStack )
19+ {
20+ $ this ->requestStack = $ requestStack ;
21+ }
22+
23+ /**
24+ * Returns the array of meta tags.
25+ *
26+ * @param string $tagName
27+ * @param array $params
28+ *
29+ * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If number of params is incorrect
30+ *
31+ * @return \Netgen\Bundle\OpenGraphBundle\MetaTag\Item[]
32+ */
33+ public function getMetaTags ($ tagName , array $ params = array ())
34+ {
35+ if (!isset ($ params [0 ])) {
36+ throw new InvalidArgumentException (
37+ '$params[0] ' ,
38+ 'Literal URL handler requires the path to output. '
39+ );
40+ }
41+
42+ $ path = $ params [0 ];
43+ $ request = $ this ->requestStack ->getCurrentRequest ();
44+
45+ if (!preg_match ('/^https?:\/\// ' , $ path ) && $ request instanceof Request) {
46+ $ path = $ request ->getUriForPath ('/ ' . ltrim ($ path , '/ ' ));
47+ }
48+
49+ return array (
50+ new Item (
51+ $ tagName ,
52+ $ path
53+ ),
54+ );
55+ }
56+ }
Original file line number Diff line number Diff line change @@ -19,6 +19,16 @@ services:
1919 tags :
2020 - { name: netgen_open_graph.meta_tag_handler, alias: literal/text }
2121
22+ netgen_open_graph.handler.literal.url :
23+ class : Netgen\Bundle\OpenGraphBundle\Handler\Literal\Url
24+ public : false
25+ parent : netgen_open_graph.handler.abstract
26+ lazy : true
27+ arguments :
28+ - " @request_stack"
29+ tags :
30+ - { name: netgen_open_graph.meta_tag_handler, alias: literal/url }
31+
2232 netgen_open_graph.handler.field_type.text_line :
2333 class : Netgen\Bundle\OpenGraphBundle\Handler\FieldType\TextLine
2434 public : false
Original file line number Diff line number Diff line change 33namespace Netgen \Bundle \OpenGraphBundle \Tests \DependencyInjection \Compiler ;
44
55use Matthias \SymfonyDependencyInjectionTest \PhpUnit \AbstractCompilerPassTestCase ;
6+ use Netgen \Bundle \OpenGraphBundle \DependencyInjection \Compiler \TwigRuntimePass ;
67use Symfony \Component \DependencyInjection \ContainerBuilder ;
78use Symfony \Component \DependencyInjection \Definition ;
89use Symfony \Component \DependencyInjection \Reference ;
9- use Netgen \Bundle \OpenGraphBundle \DependencyInjection \Compiler \TwigRuntimePass ;
1010
1111class TwigRuntimePassTest extends AbstractCompilerPassTestCase
1212{
13- protected function registerCompilerPass (ContainerBuilder $ container )
14- {
15- $ container ->addCompilerPass (new TwigRuntimePass ());
16- }
17-
1813 public function testCompilerPassCollectsValidServices ()
1914 {
2015 $ twig = new Definition ();
@@ -38,4 +33,9 @@ public function testCompilerPassWithTwigRuntimeLoaderService()
3833
3934 $ this ->compile ();
4035 }
36+
37+ protected function registerCompilerPass (ContainerBuilder $ container )
38+ {
39+ $ container ->addCompilerPass (new TwigRuntimePass ());
40+ }
4141}
You can’t perform that action at this time.
0 commit comments