/** * Add an input to the input filter * * @param array|Traversable|InputInterface|InputFilterInterface $input * @param null|string $name * @param $disablePurifier * @return InputFilter */ public function add($input, $name = null, $disablePurifier = false) { /** * By Default all Inputs will filter against XSS and invalid HTML, attributes and scripts */ $purifier = $this->getHtmlPurifier(); $input->getFilterChain()->attach(function ($value) use($purifier, $disablePurifier) { if ($purifier instanceof HTMLPurifier && !$disablePurifier) { if (is_array($value)) { foreach ($value as $key => $v) { $value[$key] = $purifier->purify($v); } return $value; } else { return $purifier->purify($value); } } return $value; }); return parent::add($input, $name); }
/** * @param InputInterface $input * @return Input */ public function merge(InputInterface $input) { $this->setAllowEmpty($input->allowEmpty()); $this->setBreakOnFailure($input->breakOnFailure()); $this->setContinueIfEmpty($input->continueIfEmpty()); $this->setErrorMessage($input->getErrorMessage()); $this->setName($input->getName()); $this->setRequired($input->isRequired()); $this->setValue($input->getRawValue()); $filterChain = $input->getFilterChain(); $this->getFilterChain()->merge($filterChain); $validatorChain = $input->getValidatorChain(); $this->getValidatorChain()->merge($validatorChain); return $this; }
/** * Attach filters from data-filters attribute * * @param InputInterface $input * @param DOMElement $element */ protected function attachFilters(InputInterface $input, DOMElement $element) { $dataFilters = $element->getAttribute('data-filters'); if (!$dataFilters) { return; } $filters = $this->parseDataAttribute($dataFilters); foreach ($filters as $filter => $options) { // TODO: Needs to fixed when zend-inputfilter 3 is released. if (array_key_exists($filter, $this->filters)) { $class = $this->filters[$filter]; $input->getFilterChain()->attach(new $class($options)); } } }