Created
June 27, 2012 09:38
-
-
Save awartoft/3002936 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Antoine Hedgecock <[email protected]> | |
*/ | |
/** | |
* @namespace | |
*/ | |
namespace MCNCore\View\Helper; | |
use MCNCore\Object\AbstractObject, | |
Zend\View\Helper\AbstractHelper, | |
Zend\ServiceManager\ServiceLocatorInterface, | |
Zend\ServiceManager\ServiceLocatorAwareInterface; | |
/** | |
* | |
*/ | |
class SlugUrl extends AbstractHelper implements ServiceLocatorAwareInterface | |
{ | |
/** | |
* @var ServiceLocatorInterface | |
*/ | |
protected $sm; | |
/** | |
* @param ServiceLocatorInterface $serviceLocator | |
* | |
* @return SlugUrl | |
*/ | |
public function setServiceLocator(ServiceLocatorInterface $serviceLocator) | |
{ | |
$this->sm = $serviceLocator; | |
return $this; | |
} | |
/** | |
* @return ServiceLocatorInterface | |
*/ | |
public function getServiceLocator() | |
{ | |
return $this->sm; | |
} | |
/** | |
* @param $name | |
* @param AbstractObject $object | |
* @return mixed | |
*/ | |
public function __invoke($name, AbstractObject $object) | |
{ | |
$parameters = array( | |
'slug' => $object->getUrlSlug() | |
); | |
foreach($this->router->getParams() as $param => $value) | |
{ | |
// if the param exists in the object then use that instead of default value.. | |
if ($object->offsetExists($param)) { | |
$parameters[$param] = $object->offsetGet($param); | |
} else { | |
$parameters[$param] = $value; | |
} | |
} | |
return $this->getView() | |
->url($name, $parameters); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment