Skip to content

Instantly share code, notes, and snippets.

@Bittarman
Created August 28, 2013 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bittarman/6368543 to your computer and use it in GitHub Desktop.
Save Bittarman/6368543 to your computer and use it in GitHub Desktop.
<?php
/**
* @copyright Lupimedia ltd 2013
*/
namespace Contentled\Filter;
use Zend\Filter\Exception;
use Zend\Filter\FilterInterface;
class FormatActivationKey implements FilterInterface
{
/**
* Returns the result of filtering $value
*
* @param mixed $value
* @throws Exception\RuntimeException If filtering $value is impossible
* @return mixed
*/
public function filter($value)
{
$value = str_replace('-', '', $value);
return trim(chunk_split($value, 4, '-'), '-');
}
}
<?php
/**
* @copyright Lupimedia ltd 2013
*/
namespace Contentled\Filter;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class FormatActivationKeyFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return new FormatActivationKey(); // you could inject dependencies here
}
}
<?php
/**
* @copyright Lupimedia ltd 2013
*/
namespace Contentled;
class Module
{
/**
* @return array
*/
public function getServiceConfig()
{
return [
'factories' => [
'FormatActivationKey' => 'Contentled\Filter\FormatActivationKeyFactory',
'Form\ConfirmRegistration' => function($sm) {
$form = new Form\ConfirmRegistration('confirm-registration');
$plugins = $sm->get('FilterManager');
$chain = new FilterChain();
$chain->setPluginManager($plugins);
$form->getFormFactory()->getInputFilterFactory()->setDefaultFilterChain($chain);
return $form;
},
]
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment