本文整理汇总了PHP中Zend\Form\FormInterface::setHydrator方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::setHydrator方法的具体用法?PHP FormInterface::setHydrator怎么用?PHP FormInterface::setHydrator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::setHydrator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareAndInjectHydrator
/**
* Prepare and inject a named hydrator
*
* Takes a string indicating a hydrator class name, instantiates the class
* by that name, and injects the hydrator instance into the form.
*
* @param string $hydratorName
* @param FormInterface $form
* @param string $method
* @return void
* @throws Exception\DomainException if $hydratorName is not a string, does not resolve to a known class, or the class does not implement Hydrator\HydratorInterface
*/
protected function prepareAndInjectHydrator($hydratorName, FormInterface $form, $method)
{
if (!is_string($hydratorName)) {
throw new Exception\DomainException(sprintf(
'%s expects string hydrator class name; received "%s"',
$method,
(is_object($hydratorName) ? get_class($hydratorName) : gettype($hydratorName))
));
}
if (!class_exists($hydratorName)) {
throw new Exception\DomainException(sprintf(
'%s expects string hydrator name to be a valid class name; received "%s"',
$method,
$hydratorName
));
}
$hydrator = new $hydratorName;
if (!$hydrator instanceof Hydrator\HydratorInterface) {
throw new Exception\DomainException(sprintf(
'%s expects a valid implementation of Zend\Form\Hydrator\HydratorInterface; received "%s"',
$method,
$hydratorName
));
}
$form->setHydrator($hydrator);
return;
}