Skip to content

Instantly share code, notes, and snippets.

@santouras
Created August 29, 2012 14:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santouras/3513171 to your computer and use it in GitHub Desktop.
Save santouras/3513171 to your computer and use it in GitHub Desktop.
Failing ZF2 validator requiring Service Locator
<?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;
}
}
@asgrim
Copy link

asgrim commented Jun 20, 2013

Hi - how did you solve this? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment