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
0
 /**
  * @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;
 }
 /**
  * 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
0
 public function testAllowEmptyFlagIsMutable()
 {
     $input = new Input('foo');
     $input->setAllowEmpty(true);
     $this->assertTrue($input->allowEmpty());
 }
Пример #5
0
 /**
  * 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
0
 public function testAllowEmptyFlagIsMutable()
 {
     $this->input->setAllowEmpty(true);
     $this->assertTrue($this->input->allowEmpty());
 }