Skip to content

Instantly share code, notes, and snippets.

@Saeven
Created April 7, 2015 15:30
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 Saeven/7801acf25c95ab1bfdb5 to your computer and use it in GitHub Desktop.
Save Saeven/7801acf25c95ab1bfdb5 to your computer and use it in GitHub Desktop.
Form object
/**
* Class UserFormFactory
* @package CirclicalUser\Factory\Form
*/
class UserFormFactory implements FactoryInterface, MutableCreationOptionsInterface
{
/**
* @var array
*/
protected $options;
/**
* Set creation options
*
* @param array $options
* @return void
*/
public function setCreationOptions( array $options )
{
$this->options = $options;
}
/**
* {@inheritdoc}
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
/**
* @var \Zend\Form\FormElementManager $serviceLocator
* @var \Zend\ServiceManager\ServiceManager $serviceManager
*/
$serviceManager = $serviceLocator->getServiceLocator();
try
{
$form = new UserForm( 'user' );
$form->setHydrator(new ClassMethods());
$form->setInputFilter(
$serviceManager->get('InputFilterManager')->get( UserInputFilter::class, $this->options )
);
$form->setObject(new User());
}
catch( \Exception $x ){
die( $x->getMessage() );
}
return $form;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment