本文整理匯總了PHP中Zend\InputFilter\InputFilter::isValid方法的典型用法代碼示例。如果您正苦於以下問題:PHP InputFilter::isValid方法的具體用法?PHP InputFilter::isValid怎麽用?PHP InputFilter::isValid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\InputFilter\InputFilter
的用法示例。
在下文中一共展示了InputFilter::isValid方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: isValid
/**
* @param array $data
*
* @return bool
*/
public function isValid($data)
{
if ($data === null) {
$data = [];
}
$this->inputFilter->setData($data);
return $this->inputFilter->isValid($data);
}
示例2: validate
/**
* Validates the form data using the provided input filter.
*
* If validation errors are found, the form is populated with the corresponding error messages.
* Form values are updated with the clean values provided by the filter.
*
* @param Form $form
* @return boolean
*/
public function validate(Form $form)
{
$this->inputFilter->setData($form->values());
if (!($isValid = $this->inputFilter->isValid())) {
$form->setErrorMessages($this->inputFilter->getMessages());
return $isValid;
}
$form->submit($this->inputFilter->getValues());
return $isValid;
}
示例3: onDispatch
/**
* @param MvcEvent $e
* @return mixed|void
*/
public function onDispatch(MvcEvent $e)
{
$this->inputFilter->setData($this->params()->fromPost());
if (!$this->inputFilter->isValid()) {
$this->flashMessenger()->addErrorMessage($this->inputFilter->getMessages());
return $this->redirect()->toRoute('frontend');
}
try {
$this->pagesResource->download($this->inputFilter->getValue('site_url'));
$this->flashMessenger()->addSuccessMessage('Url successfully queued for download all images');
} catch (ApiException $e) {
$this->flashMessenger()->addErrorMessage($e->getMessage());
}
$this->redirect()->toRoute('frontend');
}
示例4: isValid
public function isValid()
{
if (!is_null($this->isValid)) {
return $this->isValid;
}
return $this->isValid = parent::isValid();
}
示例5: isValid
/**
* Override isValid to provide conditional input checking
* @return bool
*/
public function isValid()
{
if (!$this->isValidService()) {
return false;
}
return parent::isValid();
}
示例6: uploadImageAction
public function uploadImageAction()
{
$this->checkAuth();
$request = $this->getRequest();
if ($request->isPost()) {
// File upload input
$file = new FileInput('avatar');
// Special File Input type
$file->getValidatorChain()->attach(new Validator\File\UploadFile());
$file->getFilterChain()->attach(new Filter\File\RenameUpload(array('target' => './public/files/users/avatar/origin/', 'use_upload_name' => true, 'randomize' => true)));
// Merge $_POST and $_FILES data together
$request = new Request();
$postData = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
$inputFilter = new InputFilter();
$inputFilter->add($file)->setData($postData);
if ($inputFilter->isValid()) {
// FileInput validators are run, but not the filters...
$data = $inputFilter->getValues();
// This is when the FileInput filters are run.
$avatar = basename($data['avatar']['tmp_name']);
$this->databaseService->updateAvatar($this->user->id, $avatar);
$this->user->avatar = $avatar;
} else {
// error
}
}
return $this->redirect()->toRoute('profile');
}
示例7: process
/**
* Perform any processing or data manipulation needed before render.
*
* A response helper object will be passed to this method to allow you to
* easily add success messages or redirects. This helper should be used
* to handle these kinds of actions so that you can easily test your
* page's code.
*
* @param ResponseHelper $responseHelper
* @return ResponseHelper|null
*/
public function process(ResponseHelper $responseHelper)
{
$isCurrentUser = $this->row->get('user_id') === Pimple::getResource('user')->get('user_id');
if (!$this->component->getPermissions()->can('edit') && !$isCurrentUser) {
return $responseHelper->redirectToUrl('/admin');
}
if ($this->request->isPost()) {
$this->inputFilter->setData($this->request->getPost());
if ($this->inputFilter->isValid()) {
$this->row->hashPassword($this->request->getPost('password'))->save();
if ($isCurrentUser) {
return $responseHelper->redirectToUrl('/admin');
} else {
return $responseHelper->redirectToAdminPage('index');
}
}
}
}
示例8: isValid
public function isValid()
{
$fields = ['id', 'mode'];
$mode = $this->getMode();
if ($mode == 'timecreated') {
$fields[] = 'timecreated';
}
$this->setValidationGroup($fields);
return parent::isValid();
}
示例9: isValid
public function isValid()
{
$type = $this->getType();
if ($type) {
$field = $this->_getRelationshipInput($type);
if ($field) {
$this->setValidationGroup(['id', 'type', $field]);
}
}
return parent::isValid();
}
示例10: isValid
/**
* {@inheritDoc}
*/
public function isValid($context = null)
{
$valid = parent::isValid($context);
if (!$valid) {
return $valid;
}
$validators = $this->getValidatorChain();
$valid = $validators->isValid(new \ArrayObject($this->getValues()), $context);
if (!$valid) {
$validators->getMessages();
}
return $valid;
}
示例11: __invoke
/**
* __invoke
*
* @param Request $request
* @param Response $response
* @param callable|null $out
*
* @return mixed
*/
public function __invoke(Request $request, Response $response, callable $out = null)
{
$filterConfig = $this->getOption($request, 'config', []);
$inputFilter = new InputFilter();
$factory = $inputFilter->getFactory();
foreach ($filterConfig as $field => $config) {
$inputFilter->add($factory->createInput($config));
}
$dataModel = $request->getParsedBody();
$inputFilter->setData($dataModel);
if ($inputFilter->isValid()) {
return $out($request, $response);
}
$messages = new ZfInputFilterMessageResponseModels($inputFilter, $this->getOption($request, 'primaryMessage', 'An Error Occurred'), $this->getOption($request, 'messageParams', []));
return $this->getResponseWithDataBody($response, $messages);
}
示例12: isValid
public function isValid()
{
$valid = parent::isValid();
if ($this->checkPassword) {
$password = $this->get('password');
$confirm_password = $this->get('confirm_password');
if ($password->getValue() != $confirm_password->getValue()) {
$valid = false;
$password->setErrorMessage('Passwords did not match');
if (!isset($this->invalidInputs[$password->getName()])) {
$this->invalidInputs[$password->getName()] = $password;
}
$confirm_password->setErrorMessage('Passwords did not match');
if (!isset($this->invalidInputs[$confirm_password->getName()])) {
$this->invalidInputs[$confirm_password->getName()] = $confirm_password;
}
}
}
return $valid;
}
示例13: isValid
/**
* Check if login form is valid
* - first call parent to validate fields
* - get user by identity and validate
* @return bool
*/
public function isValid()
{
$valid = parent::isValid();
if ($valid) {
$identity = $this->get('identity')->getValue();
$credential = $this->get('credential')->getValue();
$user = $this->getUserByIdentity($identity);
if (!$user) {
$this->invalidInputs['identity'] = $this->get('identity');
$this->get('identity')->setErrorMessage('Invalid identity or credential supplied.');
return false;
}
$salt = $user->getPasswordSalt();
$password = $user->getPassword();
if (!$this->_isValidCredential($password, $salt, $credential)) {
$this->invalidInputs['identity'] = $this->get('identity');
$this->get('identity')->setErrorMessage('Invalid identity or credential supplied.');
return false;
}
}
return $valid;
}
示例14: isValid
public function isValid($context = null)
{
$data = $this->data;
if (null === $data) {
return parent::isValid($context);
}
if ($data instanceof Traversable) {
$data = iterator_to_array($data);
}
if (is_object($data)) {
$data = (array) $data;
}
if (!isset($data['dsn'])) {
$data['dsn'] = null;
}
if (isset($data['dsn_type']) && 'Mongo' === $data['dsn_type']) {
if (!isset($data['database'])) {
$data['database'] = null;
}
}
$this->setData($data);
return parent::isValid($context);
}
示例15: isValid
/**
* Is the data set valid?
*
* @throws RuntimeException
* @return bool
*/
public function isValid()
{
if (true === ($valid = parent::isValid())) {
$validator = new Callback(array('callback' => function ($values) {
if (isset($values['query']) || isset($values['latitude']) && isset($values['longitude']) || isset($values['id'])) {
return true;
}
}, 'messages' => array(Callback::INVALID_VALUE => 'Requires a query, id, or latitude and longitude')));
if (true === ($valid = $validator->isValid($this->getValues()))) {
$this->validInputs['atLeastOne'] = $validator;
} else {
$this->invalidInputs['atLeastOne'] = $validator;
}
}
return $valid;
}