Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
[zendframework/zendframework#4105] Create proxy method headLink()
Browse files Browse the repository at this point in the history
- Creates a proxy "headLink" method which allows us usage as described
  in the manual. Proxies to `__invoke`.
  • Loading branch information
weierophinney committed Jul 22, 2013
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/Helper/HeadLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
8 changes: 4 additions & 4 deletions test/Helper/HeadLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9b635f6

Please sign in to comment.