本文整理汇总了PHP中Zend\InputFilter\Factory::createInputFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::createInputFilter方法的具体用法?PHP Factory::createInputFilter怎么用?PHP Factory::createInputFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\InputFilter\Factory
的用法示例。
在下文中一共展示了Factory::createInputFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValid
/**
* Is the data set valid?
*
* @return bool
*/
public function isValid()
{
$this->messages = [];
try {
$this->validationFactory->createInputFilter($this->data);
return true;
} catch (\Exception $e) {
$this->messages['inputFilter'] = $e->getMessage();
return false;
}
}
示例2: getInputFilter
public function getInputFilter()
{
$factory = new Factory;
return $factory->createInputFilter(array(
'type' => 'ZF\Apigility\Admin\InputFilter\Authentication\OAuth2InputFilter',
));
}
示例3: getInputFilter
public function getInputFilter()
{
if (!$this->filter) {
$factory = new InputFilterFactory();
$inputFilterSpec = array('id' => array('required' => false), 'block_id' => array('required' => false), 'href' => array('required' => false), 'title' => array('required' => true), 'type' => array('required' => true), 'file' => array('required' => false), 'link' => array('required' => false, 'validators' => array(new UrlValidator())), 'page' => array('required' => false), 'entity_id' => array('required' => false), 'position' => array('required' => false));
$data = $this->data;
// if ($this->getName()){
// $name = str_replace(']','', $this->getName());
// $name = explode('[', $name);
// while (!empty($name)){
// $key = array_shift($name);
// $data = $data[$key];
// }
// }
switch ($data['type']) {
case 'link':
$inputFilterSpec['link']['required'] = true;
break;
case 'page':
$inputFilterSpec['page']['required'] = true;
break;
case 'file':
$inputFilterSpec['file']['required'] = true;
break;
}
$this->filter = $factory->createInputFilter($inputFilterSpec);
}
return $this->filter;
}
示例4: createServiceWithName
/**
* Create service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
* @param $requestedName
* @return mixed
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
$config = $serviceLocator->get('Config');
$zohoConfig = $config['zoho'];
$resourceConfig = $config['zoho']['resources'][$requestedName];
$resource = new Resource($zohoConfig['auth_token'], $zohoConfig['organization_id']);
$resource->setPath($resourceConfig['path']);
$resource->setCollectionName($resourceConfig['collectionName']);
$entityClass = array_key_exists('entityClass', $resourceConfig) ? $resourceConfig['entityClass'] : str_replace('Resource', 'Entity', $requestedName);
$resource->setEntityClass($entityClass);
$resource->setEntityName($resourceConfig['entityName']);
if (isset($resourceConfig['input-filter']) && is_array($resourceConfig['input-filter'])) {
$inputFilterFactory = new InputFilterFactory();
$inputFilter = $inputFilterFactory->createInputFilter($resourceConfig['input-filter']);
$resource->setInputFilter($inputFilter);
}
$hydratorManager = $serviceLocator->get('HydratorManager');
$hydratorName = str_replace('Entity', 'Hydrator', $entityClass);
if ($hydratorManager->has($hydratorName)) {
$hydrator = $hydratorManager->get($hydratorName);
} else {
$hydrator = new ClassMethods();
}
$resource->setHydrator($hydrator);
return $resource;
}
示例5: init
public function init()
{
$this->setName('ef');
$this->add(array('name' => 'ef-name', 'type' => 'Text', 'attributes' => array('id' => 'ef-name', 'style' => 'width: 320px'), 'options' => array('label' => 'Name')));
$this->add(array('name' => 'ef-description', 'type' => 'Textarea', 'attributes' => array('id' => 'ef-description', 'class' => 'wysiwyg-editor', 'style' => 'width: 320px; height: 180px;'), 'options' => array('label' => 'Description')));
$this->add(array('name' => 'ef-date-start', 'type' => 'Text', 'attributes' => array('id' => 'ef-date-start', 'class' => 'datepicker', 'style' => 'width: 110px;'), 'options' => array('label' => 'Date (Start)')));
$this->add(array('name' => 'ef-time-start', 'type' => 'Text', 'attributes' => array('id' => 'ef-time-start', 'style' => 'width: 110px;'), 'options' => array('label' => 'Time (Start)')));
$this->add(array('name' => 'ef-date-end', 'type' => 'Text', 'attributes' => array('id' => 'ef-date-end', 'class' => 'datepicker', 'style' => 'width: 110px;'), 'options' => array('label' => 'Date (End)')));
$this->add(array('name' => 'ef-time-end', 'type' => 'Text', 'attributes' => array('id' => 'ef-time-end', 'style' => 'width: 110px;'), 'options' => array('label' => 'Time (End)')));
$squareOptions = array('null' => 'All squares');
foreach ($this->squareManager->getAll() as $sid => $square) {
$squareOptions[$sid] = $square->get('name');
}
$this->add(array('name' => 'ef-sid', 'type' => 'Select', 'attributes' => array('id' => 'ef-sid', 'style' => 'width: 124px'), 'options' => array('label' => 'Square', 'value_options' => $squareOptions)));
$this->add(array('name' => 'ef-capacity', 'type' => 'Text', 'attributes' => array('id' => 'ef-capacity', 'style' => 'width: 110px;'), 'options' => array('label' => 'Capacity', 'notes' => 'How many people can participate?')));
$this->add(array('name' => 'ef-notes', 'type' => 'Textarea', 'attributes' => array('id' => 'ef-notes', 'style' => 'width: 250px; height: 48px;'), 'options' => array('label' => 'Notes', 'notes' => 'These are only visible for administration')));
$this->add(array('name' => 'ef-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Save', 'id' => 'ef-submit', 'class' => 'default-button', 'style' => 'width: 200px;')));
/* Input filters */
$factory = new Factory();
$this->setInputFilter($factory->createInputFilter(array('ef-name' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true))), 'ef-description' => array('required' => false, 'filters' => array(array('name' => 'StringTrim'))), 'ef-date-start' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) {
try {
new \DateTime($value);
return true;
} catch (\Exception $e) {
return false;
}
}, 'message' => 'Invalid date')))), 'ef-time-start' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Regex', 'options' => array('pattern' => '/^[0-9]?[0-9]:[0-9][0-9]$/', 'message' => 'Please provide the time in format HH:MM')))), 'ef-date-end' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) {
try {
new \DateTime($value);
return true;
} catch (\Exception $e) {
return false;
}
}, 'message' => 'Invalid date')))), 'ef-time-end' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Regex', 'options' => array('pattern' => '/^[0-9]?[0-9]:[0-9][0-9]$/', 'message' => 'Please provide the time in format HH:MM')))), 'ef-capacity' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Digits', 'options' => array('message' => 'Please type a number here')))), 'ef-notes' => array('required' => false, 'filters' => array(array('name' => 'StringTrim'))))));
}
示例6: init
public function init()
{
$this->setName('eef');
$this->add(array('name' => 'eef-email1', 'type' => 'Text', 'attributes' => array('id' => 'eef-email1', 'style' => 'width: 235px;'), 'options' => array('notes' => 'Please provide your email address')));
$this->add(array('name' => 'eef-email2', 'type' => 'Text', 'attributes' => array('id' => 'eef-email2', 'style' => 'width: 235px;'), 'options' => array('notes' => 'Please type your email address again<br>to prevent typing errors')));
$this->add(array('name' => 'eef-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Update email address', 'class' => 'default-button')));
/* Input filters */
$userManager = $this->userManager;
$factory = new Factory();
$this->setInputFilter($factory->createInputFilter(array('eef-email1' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your email address here'), 'break_chain_on_failure' => true), array('name' => 'EmailAddress', 'options' => array('useMxCheck' => true, 'message' => 'Please type your correct email address here', 'messages' => array('emailAddressInvalidMxRecord' => 'We could not verify your email provider')), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) {
$blacklist = getcwd() . '/data/res/blacklist-emails.txt';
if (is_readable($blacklist)) {
$blacklistContent = file_get_contents($blacklist);
$blacklistDomains = explode("\r\n", $blacklistContent);
foreach ($blacklistDomains as $blacklistDomain) {
$blacklistPattern = str_replace('.', '\\.', $blacklistDomain);
if (preg_match('/' . $blacklistPattern . '$/', $value)) {
return false;
}
}
}
return true;
}, 'message' => 'Trash mail addresses are currently blocked - sorry'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) use($userManager) {
if ($userManager->getBy(array('email' => $value))) {
return false;
} else {
return true;
}
}, 'message' => 'This email address has already been registered')))), 'eef-email2' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your email address here'), 'break_chain_on_failure' => true), array('name' => 'Identical', 'options' => array('token' => 'eef-email1', 'message' => array('Both email addresses must be identical'))))))));
}
示例7: init
/**
* Init Module form
*
* @return void
*/
public function init()
{
$this->setAttribute('class', 'relative');
$fileInfo = new Info();
$modulesInfos = array();
$options = array('' => 'Select an option');
foreach ($this->getServiceLocator()->get('ModulesList') as $path => $dir) {
$options[$dir] = $dir;
$configFile = $path . '/module.info';
if ($fileInfo->fromFile($configFile) === true) {
$modulesInfos[$dir] = $fileInfo->render();
}
}
$collection = new ModuleCollection();
$modules = $collection->getModules();
foreach ($modules as $module) {
if (in_array($module->getName(), $options)) {
unset($options[$module->getName()]);
unset($modulesInfos[$module->getName()]);
}
}
$module = new Element\Select('module');
$module->setLabel('Module')->setLabelAttributes(array('class' => 'required'));
$module->setAttribute('id', 'module')->setAttribute('class', 'form-control')->setAttribute('modules_info', $modulesInfos)->setValueOptions($options);
$this->add($module);
$inputFilterFactory = new InputFilterFactory();
$inputFilter = $inputFilterFactory->createInputFilter(array('module' => array('name' => 'module', 'required' => true, 'validators' => array(array('name' => 'not_empty')))));
$this->setInputFilter($inputFilter);
}
示例8: getInputFilter
public function getInputFilter()
{
$factory = new Factory();
return $factory->createInputFilter(array(
'type' => 'ZF\Apigility\Admin\InputFilter\VersionInputFilter',
));
}
示例9: init
public function init()
{
$this->setName('bf');
$this->add(array('name' => 'bf-date-start', 'type' => 'Text', 'attributes' => array('id' => 'bf-date-start', 'style' => 'width: 80px;'), 'options' => array('label' => 'Date (Start)')));
$this->add(array('name' => 'bf-date-end', 'type' => 'Text', 'attributes' => array('id' => 'bf-date-end', 'style' => 'width: 80px;'), 'options' => array('label' => 'Date (End)')));
$this->add(array('name' => 'bf-repeat', 'type' => 'Select', 'attributes' => array('id' => 'bf-repeat', 'style' => 'width: 124px'), 'options' => array('label' => 'Repeat', 'value_options' => Booking::$repeatOptions)));
$this->add(array('name' => 'bf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Save', 'id' => 'bf-submit', 'class' => 'default-button', 'style' => 'width: 125px;')));
/* Input filters */
$factory = new Factory();
$this->setInputFilter($factory->createInputFilter(array('bf-date-start' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) {
try {
new \DateTime($value);
return true;
} catch (\Exception $e) {
return false;
}
}, 'message' => 'Invalid date')))), 'bf-date-end' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) {
try {
new \DateTime($value);
return true;
} catch (\Exception $e) {
return false;
}
}, 'message' => 'Invalid date')))))));
}
示例10: validate
/**
* @inheritdoc
*/
public function validate(array $data, $method = null)
{
if ($method !== null && $method !== 'POST') {
// Not a post request, skip validation
return new ValidationResult([], [], [], $method);
}
$inputFilter = $this->factory->createInputFilter([]);
// Add all validators and filters to the InputFilter
$this->buildInputFilterFromForm($inputFilter);
$inputFilter->setData($data);
$messages = [];
// Do some validation
if (!$inputFilter->isValid()) {
foreach ($inputFilter->getInvalidInput() as $message) {
$messages[$message->getName()] = $message->getMessages();
}
}
// Get the submit button
$submitName = null;
foreach ($this->getSubmitStateNodeList() as $name) {
if (array_key_exists($name, $data)) {
$submitName = $name;
}
}
// Return validation result
return new ValidationResult($inputFilter->getRawValues(), $inputFilter->getValues(), $messages, $method, $submitName);
}
示例11: init
/**
* Init Module form
*
* @return void
*/
public function init()
{
$showEmail = new Element\Checkbox('show_email');
$showEmail->setLabel('Show email');
$showEmail->setAttribute('required', 'required')->setAttribute('id', 'show-email');
$username = new Element\Text('username');
$username->setLabel('Username');
$username->setAttribute('required', 'required')->setAttribute('id', 'username');
$email = new Element\Text('email');
$email->setLabel('Email');
$email->setAttribute('required', 'required')->setAttribute('id', 'email');
$message = new Element\Textarea('message');
$message->setLabel('Message');
$message->setAttribute('required', 'required')->setAttribute('id', 'message');
$captchaImage = new CaptchaImage(array('font' => GC_PUBLIC_PATH . '/backend/fonts/arial.ttf', 'width' => 250, 'height' => 50, 'dotNoiseLevel' => 40, 'lineNoiseLevel' => 3));
$captchaImage->setImgDir(GC_PUBLIC_PATH . '/frontend/tmp');
$captchaImage->setImgUrl('/frontend/tmp');
$captcha = new Element\Captcha('captcha');
$captcha->setLabel('Please verify you are human')->setCaptcha($captchaImage)->setAttribute('required', 'required')->setAttribute('id', 'captcha');
$this->add($showEmail);
$this->add($username);
$this->add($email);
$this->add($message);
$this->add($captcha);
$inputFilterFactory = new InputFilterFactory();
$inputFilter = $inputFilterFactory->createInputFilter(array('show_email' => array('name' => 'show_email', 'required' => false), 'username' => array('name' => 'username', 'required' => true), 'email' => array('name' => 'email', 'required' => true, 'validators' => array(array('name' => 'email_address'))), 'message' => array('name' => 'message', 'required' => true), 'captcha' => $captcha->getInputSpecification()));
$this->setInputFilter($inputFilter);
}
示例12: testInputSpecificationFilterIfSecondNotProvided
public function testInputSpecificationFilterIfSecondNotProvided()
{
$element = new DateTimeSelectElement('test');
$factory = new InputFilterFactory();
$inputFilter = $factory->createInputFilter(array('test' => $element->getInputSpecification()));
$inputFilter->setData(array('test' => array('year' => '2013', 'month' => '02', 'day' => '07', 'hour' => '03', 'minute' => '14')));
$this->assertTrue($inputFilter->isValid());
}
示例13: init
public function init()
{
$this->setName('epf');
$this->add(array('name' => 'epf-phone', 'type' => 'Text', 'attributes' => array('id' => 'epf-phone', 'style' => 'width: 235px;'), 'options' => array('notes' => 'We only use this to inform you<br>about changes to your bookings')));
$this->add(array('name' => 'epf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Update phone number', 'class' => 'default-button')));
/* Input filters */
$factory = new Factory();
$this->setInputFilter($factory->createInputFilter(array('epf-phone' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your phone number here'), 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'This phone number is somewhat short ...')), array('name' => 'Regex', 'options' => array('pattern' => '/^([ \\+\\/\\(\\)\\-0-9])+$/u', 'message' => 'This phone number contains invalid characters - sorry')))))));
}
示例14: getInputFilter
public function getInputFilter()
{
if (!$this->filter) {
$factory = new InputFilterFactory();
$inputFilterSpec = array('type' => 'Dots\\InputFilter\\InputFilter', 'id' => array('required' => false), 'title' => array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))), 'alias' => array('required' => false, 'allow_empty' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim')), 'validators' => array(array('name' => 'Zend\\Validator\\Db\\NoRecordExists', 'options' => array('table' => 'pages', 'field' => 'alias', 'adapter' => \Dots\Registry::get('service_locator')->get('Zend\\Db\\Adapter\\Adapter'), 'exclude' => "id!='" . $this->data['id'] . "'")))), 'template' => array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))), 'language' => array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))));
$this->filter = $factory->createInputFilter($inputFilterSpec);
}
return $this->filter;
}
示例15: init
public function init()
{
$this->setName('pf');
$this->add(array('name' => 'pf-email', 'type' => 'Text', 'attributes' => array('id' => 'pf-email', 'class' => 'autofocus', 'style' => 'width: 250px;'), 'options' => array('label' => 'Email address', 'label_attributes' => array('class' => 'symbolic symbolic-email', 'label_attributes' => array('class' => 'symbolic symbolic-email')))));
$this->add(array('name' => 'pf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Change password', 'class' => 'default-button', 'style' => 'width: 175px;')));
/* Input filters */
$factory = new Factory();
$this->setInputFilter($factory->createInputFilter(array('pf-email' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'break_chain_on_failure' => true), array('name' => 'EmailAddress'))))));
}