<?php
namespace Moto\Filter; use Moto; use Zend; class UriNormalize extends Zend\Filter\UriNormalize { protected $removeFragment = false; protected $escapePath = false; protected $escapeQuery = false; public function setRemoveFragment($value) { $this->removeFragment = $value; return $this; } public function setEscapePath($value) { if (is_bool($value)) { $this->escapePath = $value; } return $this; } public function setEscapeQuery($value) { if (is_bool($value)) { $this->escapeQuery = $value; } return $this; } public function filter($value) { $value = parent::filter($value); if (is_string($value)) { try { $defaultScheme = $this->defaultScheme ?: $this->enforcedScheme; if (!Zend\Uri\UriFactory::getRegisteredSchemeClass($defaultScheme)) { $defaultScheme = null; } $uri = Zend\Uri\UriFactory::factory($value, $defaultScheme); if ($this->enforcedScheme && (!$uri->getScheme())) { $this->enforceScheme($uri); } $path = $uri->getPath(); $path = '/' . ltrim($path, '/'); if ($this->escapePath && strpos($path, '&amp;') === false) { $path = htmlentities($path); } $uri->setPath($path); if ($this->escapeQuery) { $query = $uri->getQuery(); if (is_string($query) && (strpos($query, '&amp;') === false)) { $uri->setQuery(htmlentities($query)); } } if ($this->removeFragment) { $uri->setFragment(null); } $value = $uri->toString(); } catch (Zend\Uri\Exception\ExceptionInterface $ex) { return $value; } } return $value; } }