Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
54 changes: 8 additions & 46 deletions library/Zend/View/Helper/EscapeCss.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,16 @@
*/
class EscapeCss extends Escaper\AbstractHelper
{
/**@+
* @const Recursion constants
*/
const RECURSE_NONE = 0x00;
const RECURSE_ARRAY = 0x01;
const RECURSE_OBJECT = 0x02;
/**@-*/


/**
* Invoke this helper: escape a value
*
* @param mixed $value
* @param int $recurse Expects one of the recursion constants; used to decide whether or not to recurse the given value when escaping
* @return mixed Given a scalar, a scalar value is returned. Given an object, with the $recurse flag not allowing object recursion, returns a string. Otherwise, returns an array.
* @throws Exception\InvalidArgumentException
* Escape a value for current escaping strategy
*
* @param string $value
* @return string
*/
public function __invoke($value, $recurse = self::RECURSE_NONE)
protected function escape($value)
{
if (is_string($value)) {
return $this->getEscaper()->escapeCss($value);
}
if (is_array($value)) {
if (!(self::RECURSE_ARRAY & $recurse)) {
throw new Exception\InvalidArgumentException(
'Array provided to Escape helper, but flags do not allow recursion'
);
}
foreach ($value as $k => $v) {
$value[$k] = $this->__invoke($v, $recurse);
}
return $value;
}
if (is_object($value)) {
if (!(self::RECURSE_OBJECT & $recurse)) {
// Attempt to cast it to a string
if (method_exists($value, '__toString')) {
return $this->getEscaper()->escapeCss((string) $value);
}
throw new Exception\InvalidArgumentException(
'Object provided to Escape helper, but flags do not allow recursion'
);
}
if (method_exists($value, 'toArray')) {
return $this->__invoke($value->toArray(), $recurse | self::RECURSE_ARRAY);
}
return $this->__invoke((array) $value, $recurse | self::RECURSE_ARRAY);
}
// At this point, we have a scalar; simply return it
return $value;
return $this->getEscaper()->escapeCss($value);
}

}
54 changes: 8 additions & 46 deletions library/Zend/View/Helper/EscapeHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,16 @@
*/
class EscapeHtml extends Escaper\AbstractHelper
{
/**@+
* @const Recursion constants
*/
const RECURSE_NONE = 0x00;
const RECURSE_ARRAY = 0x01;
const RECURSE_OBJECT = 0x02;
/**@-*/


/**
* Invoke this helper: escape a value
*
* @param mixed $value
* @param int $recurse Expects one of the recursion constants; used to decide whether or not to recurse the given value when escaping
* @return mixed Given a scalar, a scalar value is returned. Given an object, with the $recurse flag not allowing object recursion, returns a string. Otherwise, returns an array.
* @throws Exception\InvalidArgumentException
* Escape a value for current escaping strategy
*
* @param string $value
* @return string
*/
public function __invoke($value, $recurse = self::RECURSE_NONE)
protected function escape($value)
{
if (is_string($value)) {
return $this->getEscaper()->escapeHtml($value);
}
if (is_array($value)) {
if (!(self::RECURSE_ARRAY & $recurse)) {
throw new Exception\InvalidArgumentException(
'Array provided to Escape helper, but flags do not allow recursion'
);
}
foreach ($value as $k => $v) {
$value[$k] = $this->__invoke($v, $recurse);
}
return $value;
}
if (is_object($value)) {
if (!(self::RECURSE_OBJECT & $recurse)) {
// Attempt to cast it to a string
if (method_exists($value, '__toString')) {
return $this->getEscaper()->escapeHtml((string) $value);
}
throw new Exception\InvalidArgumentException(
'Object provided to Escape helper, but flags do not allow recursion'
);
}
if (method_exists($value, 'toArray')) {
return $this->__invoke($value->toArray(), $recurse | self::RECURSE_ARRAY);
}
return $this->__invoke((array) $value, $recurse | self::RECURSE_ARRAY);
}
// At this point, we have a scalar; simply return it
return $value;
return $this->getEscaper()->escapeHtml($value);
}

}
54 changes: 8 additions & 46 deletions library/Zend/View/Helper/EscapeHtmlAttr.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,16 @@
*/
class EscapeHtmlAttr extends Escaper\AbstractHelper
{
/**@+
* @const Recursion constants
*/
const RECURSE_NONE = 0x00;
const RECURSE_ARRAY = 0x01;
const RECURSE_OBJECT = 0x02;
/**@-*/


/**
* Invoke this helper: escape a value
*
* @param mixed $value
* @param int $recurse Expects one of the recursion constants; used to decide whether or not to recurse the given value when escaping
* @return mixed Given a scalar, a scalar value is returned. Given an object, with the $recurse flag not allowing object recursion, returns a string. Otherwise, returns an array.
* @throws Exception\InvalidArgumentException
* Escape a value for current escaping strategy
*
* @param string $value
* @return string
*/
public function __invoke($value, $recurse = self::RECURSE_NONE)
protected function escape($value)
{
if (is_string($value)) {
return $this->getEscaper()->escapeHtmlAttr($value);
}
if (is_array($value)) {
if (!(self::RECURSE_ARRAY & $recurse)) {
throw new Exception\InvalidArgumentException(
'Array provided to Escape helper, but flags do not allow recursion'
);
}
foreach ($value as $k => $v) {
$value[$k] = $this->__invoke($v, $recurse);
}
return $value;
}
if (is_object($value)) {
if (!(self::RECURSE_OBJECT & $recurse)) {
// Attempt to cast it to a string
if (method_exists($value, '__toString')) {
return $this->getEscaper()->escapeHtmlAttr((string) $value);
}
throw new Exception\InvalidArgumentException(
'Object provided to Escape helper, but flags do not allow recursion'
);
}
if (method_exists($value, 'toArray')) {
return $this->__invoke($value->toArray(), $recurse | self::RECURSE_ARRAY);
}
return $this->__invoke((array) $value, $recurse | self::RECURSE_ARRAY);
}
// At this point, we have a scalar; simply return it
return $value;
return $this->getEscaper()->escapeHtmlAttr($value);
}

}
54 changes: 8 additions & 46 deletions library/Zend/View/Helper/EscapeJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,16 @@
*/
class EscapeJs extends Escaper\AbstractHelper
{
/**@+
* @const Recursion constants
*/
const RECURSE_NONE = 0x00;
const RECURSE_ARRAY = 0x01;
const RECURSE_OBJECT = 0x02;
/**@-*/


/**
* Invoke this helper: escape a value
*
* @param mixed $value
* @param int $recurse Expects one of the recursion constants; used to decide whether or not to recurse the given value when escaping
* @return mixed Given a scalar, a scalar value is returned. Given an object, with the $recurse flag not allowing object recursion, returns a string. Otherwise, returns an array.
* @throws Exception\InvalidArgumentException
* Escape a value for current escaping strategy
*
* @param string $value
* @return string
*/
public function __invoke($value, $recurse = self::RECURSE_NONE)
protected function escape($value)
{
if (is_string($value)) {
return $this->getEscaper()->escapeJs($value);
}
if (is_array($value)) {
if (!(self::RECURSE_ARRAY & $recurse)) {
throw new Exception\InvalidArgumentException(
'Array provided to Escape helper, but flags do not allow recursion'
);
}
foreach ($value as $k => $v) {
$value[$k] = $this->__invoke($v, $recurse);
}
return $value;
}
if (is_object($value)) {
if (!(self::RECURSE_OBJECT & $recurse)) {
// Attempt to cast it to a string
if (method_exists($value, '__toString')) {
return $this->getEscaper()->escapeJs((string) $value);
}
throw new Exception\InvalidArgumentException(
'Object provided to Escape helper, but flags do not allow recursion'
);
}
if (method_exists($value, 'toArray')) {
return $this->__invoke($value->toArray(), $recurse | self::RECURSE_ARRAY);
}
return $this->__invoke((array) $value, $recurse | self::RECURSE_ARRAY);
}
// At this point, we have a scalar; simply return it
return $value;
return $this->getEscaper()->escapeJs($value);
}

}
56 changes: 9 additions & 47 deletions library/Zend/View/Helper/EscapeUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,56 +32,18 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class EscapeCss extends Escaper\AbstractHelper
class EscapeUrl extends Escaper\AbstractHelper
{
/**@+
* @const Recursion constants
*/
const RECURSE_NONE = 0x00;
const RECURSE_ARRAY = 0x01;
const RECURSE_OBJECT = 0x02;
/**@-*/


/**
* Invoke this helper: escape a value
*
* @param mixed $value
* @param int $recurse Expects one of the recursion constants; used to decide whether or not to recurse the given value when escaping
* @return mixed Given a scalar, a scalar value is returned. Given an object, with the $recurse flag not allowing object recursion, returns a string. Otherwise, returns an array.
* @throws Exception\InvalidArgumentException
* Escape a value for current escaping strategy
*
* @param string $value
* @return string
*/
public function __invoke($value, $recurse = self::RECURSE_NONE)
protected function escape($value)
{
if (is_string($value)) {
return $this->getEscaper()->escapeUrl($value);
}
if (is_array($value)) {
if (!(self::RECURSE_ARRAY & $recurse)) {
throw new Exception\InvalidArgumentException(
'Array provided to Escape helper, but flags do not allow recursion'
);
}
foreach ($value as $k => $v) {
$value[$k] = $this->__invoke($v, $recurse);
}
return $value;
}
if (is_object($value)) {
if (!(self::RECURSE_OBJECT & $recurse)) {
// Attempt to cast it to a string
if (method_exists($value, '__toString')) {
return $this->getEscaper()->escapeUrl((string) $value);
}
throw new Exception\InvalidArgumentException(
'Object provided to Escape helper, but flags do not allow recursion'
);
}
if (method_exists($value, 'toArray')) {
return $this->__invoke($value->toArray(), $recurse | self::RECURSE_ARRAY);
}
return $this->__invoke((array) $value, $recurse | self::RECURSE_ARRAY);
}
// At this point, we have a scalar; simply return it
return $value;
return $this->getEscaper()->escapeUrl($value);
}

}
Loading