From 28a47605153eb57d200c25036e7f369cfa7da316 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 22 Jul 2013 11:22:11 -0500 Subject: [PATCH] [#4105] Create proxy method `headLink()` - Creates a proxy "headLink" method which allows us usage as described in the manual. Proxies to `__invoke`. --- library/Zend/View/Helper/HeadLink.php | 15 +++++++++++++++ tests/ZendTest/View/Helper/HeadLinkTest.php | 8 ++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/library/Zend/View/Helper/HeadLink.php b/library/Zend/View/Helper/HeadLink.php index f7b872474bc..872cc669e5e 100644 --- a/library/Zend/View/Helper/HeadLink.php +++ b/library/Zend/View/Helper/HeadLink.php @@ -56,6 +56,21 @@ public function __construct() $this->setSeparator(PHP_EOL); } + /** + * Proxy to __invoke() + * + * Allows calling $helper->headLink(), but, more importantly, chaining calls + * like ->appendStylesheet()->headLink(). + * + * @param array $attributes + * @param string $placement + * @return HeadLink + */ + public function headLink(array $attributes = null, $placement = Placeholder\Container\AbstractContainer::APPEND) + { + return call_user_func_array(array($this, '__invoke'), func_get_args()); + } + /** * headLink() - View Helper Method * diff --git a/tests/ZendTest/View/Helper/HeadLinkTest.php b/tests/ZendTest/View/Helper/HeadLinkTest.php index ac49718d937..0c82b8c653c 100644 --- a/tests/ZendTest/View/Helper/HeadLinkTest.php +++ b/tests/ZendTest/View/Helper/HeadLinkTest.php @@ -92,16 +92,16 @@ public function testOffsetSetThrowsExceptionWithoutArrayArgument() $this->helper->offsetSet(1, 'foo'); } - public function testCreatingLinkStackViaHeadScriptCreatesAppropriateOutput() + public function testCreatingLinkStackViaHeadLinkCreatesAppropriateOutput() { $links = array( 'link1' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'foo'), 'link2' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'bar'), 'link3' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'baz'), ); - $this->helper->__invoke($links['link1']) - ->__invoke($links['link2'], 'PREPEND') - ->__invoke($links['link3']); + $this->helper->headLink($links['link1']) + ->headLink($links['link2'], 'PREPEND') + ->headLink($links['link3']); $string = $this->helper->toString(); $lines = substr_count($string, PHP_EOL);