本文整理汇总了PHP中Zend\InputFilter\Input::allowEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP Input::allowEmpty方法的具体用法?PHP Input::allowEmpty怎么用?PHP Input::allowEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\InputFilter\Input
的用法示例。
在下文中一共展示了Input::allowEmpty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInputFilter
public function getInputFilter()
{
if (is_null($this->filter)) {
$trackingIdValidator = new StringLength(36);
$regexValidator = new Regex('/^[a-zA-Z0-9_-]+$/');
$trackingIdInput = new Input('trackingId');
$trackingIdInput->allowEmpty();
$trackingIdInput->setRequired(false);
$trackingIdInput->getValidatorChain()->attach($trackingIdValidator)->attach($regexValidator);
$inArrayValidator = new InArray();
$inArrayValidator->setHaystack(array_keys($this->locations));
$originInput = new Input('origin');
$originInput->getValidatorChain()->attach($inArrayValidator);
$notSameValidator = new Callback(array('callback' => function ($value, $context = null) {
if ($context) {
return $value !== $context['origin'];
}
return true;
}, 'messages' => array(Callback::INVALID_VALUE => 'Origin and Destination are the same')));
$destinationInput = new Input('final_destination');
$destinationInput->getValidatorChain()->attach($inArrayValidator)->attach($notSameValidator);
$filter = new InputFilter();
$filter->add($trackingIdInput)->add($originInput)->add($destinationInput);
$this->filter = $filter;
}
return $this->filter;
}
示例2: getInputFilter
/**
* @return InputFilterInterface
*/
public function getInputFilter()
{
if (!$this->inputFilter) {
$name = new Input('name');
$name->setAllowEmpty(true);
$name->setRequired(false);
$venueId = new Input('venue_id');
$venueId->setRequired(true);
$type = new Input('type');
$type->setRequired(true);
$type->allowEmpty(false);
$url = new Input('url');
$url->setAllowEmpty(true);
$url->setRequired(false);
$startTime = new Input('start_time');
$startTime->setRequired(true);
$startTime->allowEmpty(false);
$endTime = new Input('end_time');
$endTime->setRequired(true);
$endTime->allowEmpty(false);
$startDate = new Input('start_date');
$startDate->setAllowEmpty(false);
$startDate->setRequired(true);
$endDate = new Input('end_date');
$endDate->setRequired(true);
$endDate->allowEmpty(false);
$minimumAge = new Input('minimum_age');
$minimumAge->setRequired(true);
$minimumAge->allowEmpty(false);
$willStop = new Input('will_stop');
$willStop->setRequired(true);
$repetitions = new Input('repetitions');
$repetitions->setAllowEmpty(true);
$repetitions->setRequired(false);
$description = new Input('description');
$description->setAllowEmpty(true);
$description->setRequired(false);
$specialNotes = new Input('special_notes');
$specialNotes->setAllowEmpty(true);
$specialNotes->setRequired(false);
$costs = new Input('costs');
$costs->setAllowEmpty(true);
$costs->setRequired(false);
$contactEmail = new Input('contact_email');
$contactEmail->setRequired(false);
$contactEmail->setAllowEmpty(true)->getValidatorChain()->addValidator(new \Zend\Validator\EmailAddress());
$inputFilter = new InputFilter();
$inputFilter->add($name)->add($type)->add($url)->add($venueId)->add($startTime)->add($endTime)->add($startDate)->add($endDate)->add($willStop)->add($minimumAge)->add($repetitions)->add($specialNotes)->add($description)->add($costs)->add($contactEmail);
$this->inputFilter = $inputFilter;
}
return $this->inputFilter;
}
示例3: __construct
/**
* Constructor
*
* @param array $modes Array of valid modes
* @param array $units Array of valid units
* @param array $languages Array of valid languages
*
* @return void
*/
public function __construct($modes = array(), $units = array(), $languages = array())
{
// mode
$mode = new Input('mode');
$mode->allowEmpty(false);
$mode->getFilterChain()->attach(new StringToLower());
$mode->getValidatorChain()->attach(new InArray(array('haystack' => $modes, 'messages' => array(InArray::NOT_IN_ARRAY => 'The supplied mode is not valid'))), true);
// units
$unit = new Input('units');
$unit->allowEmpty(false);
$unit->getFilterChain()->attach(new StringToLower());
$unit->getValidatorChain()->attach(new InArray(array('haystack' => $units, 'messages' => array(InArray::NOT_IN_ARRAY => 'The supplied unit is not valid'))), true);
// language
$language = new Input('language');
$language->allowEmpty(false);
$language->getFilterChain()->attach(new StringToLower());
$language->getValidatorChain()->attach(new InArray(array('haystack' => $languages, 'messages' => array(InArray::NOT_IN_ARRAY => 'The supplied language is invalid'))), true);
// query
$query = new Input('query');
$query->setAllowEmpty(true);
$query->getFilterChain()->attach(new StringToLower());
$query->getValidatorChain()->attach(new StringLength(array('min' => 1, 'max' => 100, 'encoding' => 'UTF-8', 'messages' => array(StringLength::INVALID => 'The supplied query should be a string', StringLength::TOO_LONG => 'The supplied query should be no longer than 100 chars', StringLength::TOO_SHORT => 'The supplied query should be at least 1 character'))), true);
// latitude
$latitude = new Input('latitude');
$latitude->setAllowEmpty(true);
$latitude->getValidatorChain()->attach(new Regex(array('pattern' => '#\\A[-|+]?[\\d]{1,2}(?:[\\.][\\d]*)?\\z#')), true);
// longitude
$longitude = new Input('longitude');
$longitude->setAllowEmpty(true);
$longitude->getValidatorChain()->attach(new Regex(array('pattern' => '#\\A[-|+]?[\\d]{1,3}(?:[\\.][\\d]*)?\\z#')), true);
// id
$id = new Input('id');
$id->setAllowEmpty(true);
$id->getValidatorChain()->attach(new Digits(), true);
// apiKey
$apiKey = new Input('apiKey');
$apiKey->setAllowEmpty(true);
$this->add($mode)->add($unit)->add($language)->add($query)->add($latitude)->add($longitude)->add($id)->add($apiKey);
}
示例4: testAllowEmptyFlagIsMutable
public function testAllowEmptyFlagIsMutable()
{
$input = new Input('foo');
$input->setAllowEmpty(true);
$this->assertTrue($input->allowEmpty());
}
示例5: renderLabelContent
/**
* Render the content of a label for the supplied field, included a "required" flag when
* appropriate.
*
* @param FieldInterface $field
* @param Renderer $renderer
* @param Input $input
* @return string
*/
public function renderLabelContent(FieldInterface $field, Renderer $renderer, Input $input = null)
{
return sprintf('%s%s', $renderer->getLabelRenderer()->render($field), $input && !$input->allowEmpty() ? $this->renderRequiredFlag() : '');
}
示例6: testAllowEmptyFlagIsMutable
public function testAllowEmptyFlagIsMutable()
{
$this->input->setAllowEmpty(true);
$this->assertTrue($this->input->allowEmpty());
}