Created
August 29, 2012 14:13
-
-
Save santouras/3513171 to your computer and use it in GitHub Desktop.
Failing ZF2 validator requiring Service Locator
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 | |
namespace My\Validator; | |
use Zend\Validator\AbstractValidator; | |
use Zend\ServiceManager\ServiceLocatorAwareInterface; | |
use Zend\ServiceManager\ServiceLocatorInterface; | |
class Unique extends AbstractValidator | |
implements ServiceLocatorAwareInterface | |
{ | |
/** | |
* Service Locator class | |
* @var \Zend\ServiceManager\ServiceLocatorAwareInterface | |
*/ | |
protected $sm; | |
public function isValid($value) | |
{ | |
$sm = $this->getServiceLocator(); | |
var_dump($sm); | |
$db = $sm->get('Zend\Db\Adapter\Adapter'); | |
} | |
/** | |
* Set service manager instance | |
* | |
* @param ServiceLocatorInterface $serviceLocator | |
* @return void | |
*/ | |
public function setServiceLocator(ServiceLocatorInterface $serviceLocator) | |
{ | |
$this->sm = $serviceLocator; | |
} | |
/** | |
* Retrieve service manager instance | |
* | |
* @return ServiceLocatorInterface | |
*/ | |
public function getServiceLocator() | |
{ | |
return $this->sm; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi - how did you solve this? :)