From 8d85ce021ea7dff194704e178a895b2743550724 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Fri, 30 Nov 2012 08:53:44 +0100 Subject: [PATCH 1/4] Zend\Feed: replaced one iconv_strlen with a string wrapper --- src/Writer/Extension/ITunes/Entry.php | 29 +++++++++++++++---- src/Writer/Extension/ITunes/Feed.php | 40 +++++++++++++++++++-------- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/Writer/Extension/ITunes/Entry.php b/src/Writer/Extension/ITunes/Entry.php index d6b9ce9c..a9169e93 100644 --- a/src/Writer/Extension/ITunes/Entry.php +++ b/src/Writer/Extension/ITunes/Entry.php @@ -12,6 +12,8 @@ use Zend\Feed\Writer; use Zend\Feed\Writer\Extension; +use Zend\Stdlib\StringUtils; +use Zend\Stdlib\StringWrapper\StringWrapperInterface; /** * @category Zend @@ -33,6 +35,18 @@ class Entry */ protected $encoding = 'UTF-8'; + /** + * The used string wrapper supporting encoding + * + * @var StringWrapperInterface + */ + protected $stringWrapper; + + public function __construct() + { + $this->stringWrapper = StringUtils::getWrapper($this->getEncoding()); + } + /** * Set feed encoding * @@ -41,7 +55,8 @@ class Entry */ public function setEncoding($enc) { - $this->encoding = $enc; + $this->stringWrapper = StringUtils::getWrapper($enc); + $this->encoding = $enc; return $this; } @@ -68,7 +83,8 @@ public function setItunesBlock($value) throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' . ' contain alphabetic characters'); } - if (iconv_strlen($value, $this->getEncoding()) > 255) { + + if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' . ' contain a maximum of 255 characters'); } @@ -98,7 +114,7 @@ public function addItunesAuthors(array $values) */ public function addItunesAuthor($value) { - if (iconv_strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only' . ' contain a maximum of 255 characters each'); } @@ -160,8 +176,9 @@ public function setItunesKeywords(array $value) throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' . ' contain a maximum of 12 terms'); } + $concat = implode(',', $value); - if (iconv_strlen($concat, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($concat, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' . ' have a concatenated length of 255 chars where terms are delimited' . ' by a comma'); @@ -179,7 +196,7 @@ public function setItunesKeywords(array $value) */ public function setItunesSubtitle($value) { - if (iconv_strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "subtitle" may only' . ' contain a maximum of 255 characters'); } @@ -196,7 +213,7 @@ public function setItunesSubtitle($value) */ public function setItunesSummary($value) { - if (iconv_strlen($value, $this->getEncoding()) > 4000) { + if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 4000) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "summary" may only' . ' contain a maximum of 4000 characters'); } diff --git a/src/Writer/Extension/ITunes/Feed.php b/src/Writer/Extension/ITunes/Feed.php index 25d1d7bf..ac6e27bf 100644 --- a/src/Writer/Extension/ITunes/Feed.php +++ b/src/Writer/Extension/ITunes/Feed.php @@ -12,6 +12,8 @@ use Zend\Feed\Writer; use Zend\Uri; +use Zend\Stdlib\StringUtils; +use Zend\Stdlib\StringWrapper\StringWrapperInterface; /** * @category Zend @@ -33,6 +35,21 @@ class Feed */ protected $encoding = 'UTF-8'; + /** + * The used string wrapper supporting encoding + * + * @var StringWrapperInterface + */ + protected $stringWrapper; + + /** + * Constructor + */ + public function __construct() + { + $this->stringWrapper = StringUtils::getWrapper($this->getEncoding()); + } + /** * Set feed encoding * @@ -41,7 +58,8 @@ class Feed */ public function setEncoding($enc) { - $this->encoding = $enc; + $this->stringWrapper = StringUtils::getWrapper($enc); + $this->encoding = $enc; return $this; } @@ -68,7 +86,7 @@ public function setItunesBlock($value) throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' . ' contain alphabetic characters'); } - if (iconv_strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' . ' contain a maximum of 255 characters'); } @@ -99,7 +117,7 @@ public function addItunesAuthors(array $values) */ public function addItunesAuthor($value) { - if (iconv_strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only' . ' contain a maximum of 255 characters each'); } @@ -124,19 +142,19 @@ public function setItunesCategories(array $values) } foreach ($values as $key=>$value) { if (!is_array($value)) { - if (iconv_strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' . ' contain a maximum of 255 characters each'); } $this->data['categories'][] = $value; } else { - if (iconv_strlen($key, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($key, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' . ' contain a maximum of 255 characters each'); } $this->data['categories'][$key] = array(); foreach ($value as $val) { - if (iconv_strlen($val, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($val, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' . ' contain a maximum of 255 characters each'); } @@ -221,7 +239,7 @@ public function setItunesKeywords(array $value) . ' contain a maximum of 12 terms'); } $concat = implode(',', $value); - if (iconv_strlen($concat, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($concat, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' . ' have a concatenated length of 255 chars where terms are delimited' . ' by a comma'); @@ -274,8 +292,8 @@ public function addItunesOwner(array $value) throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" must' . ' be an array containing keys "name" and "email"'); } - if (iconv_strlen($value['name'], $this->getEncoding()) > 255 - || iconv_strlen($value['email'], $this->getEncoding()) > 255 + if ($this->stringWrapper->strlen($value['name'], $this->getEncoding()) > 255 + || $this->stringWrapper->strlen($value['email'], $this->getEncoding()) > 255 ) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" may only' . ' contain a maximum of 255 characters each for "name" and "email"'); @@ -296,7 +314,7 @@ public function addItunesOwner(array $value) */ public function setItunesSubtitle($value) { - if (iconv_strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "subtitle" may only' . ' contain a maximum of 255 characters'); } @@ -313,7 +331,7 @@ public function setItunesSubtitle($value) */ public function setItunesSummary($value) { - if (iconv_strlen($value, $this->getEncoding()) > 4000) { + if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 4000) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "summary" may only' . ' contain a maximum of 4000 characters'); } From 133ecf6b1286388fd12ebd19d678bcacc079bb69 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Fri, 30 Nov 2012 09:57:52 +0100 Subject: [PATCH 2/4] removed trailing spaces --- src/Writer/Extension/ITunes/Entry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Writer/Extension/ITunes/Entry.php b/src/Writer/Extension/ITunes/Entry.php index a9169e93..6384c0a4 100644 --- a/src/Writer/Extension/ITunes/Entry.php +++ b/src/Writer/Extension/ITunes/Entry.php @@ -83,7 +83,7 @@ public function setItunesBlock($value) throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' . ' contain alphabetic characters'); } - + if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' . ' contain a maximum of 255 characters'); From 04405ebb2b4f2098785c3944921721a943636795 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Sun, 6 Jan 2013 15:28:10 +0100 Subject: [PATCH 3/4] just use $this->encoding --- src/Writer/Extension/ITunes/Entry.php | 2 +- src/Writer/Extension/ITunes/Feed.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Writer/Extension/ITunes/Entry.php b/src/Writer/Extension/ITunes/Entry.php index 6384c0a4..72c703c7 100644 --- a/src/Writer/Extension/ITunes/Entry.php +++ b/src/Writer/Extension/ITunes/Entry.php @@ -44,7 +44,7 @@ class Entry public function __construct() { - $this->stringWrapper = StringUtils::getWrapper($this->getEncoding()); + $this->stringWrapper = StringUtils::getWrapper($this->encoding); } /** diff --git a/src/Writer/Extension/ITunes/Feed.php b/src/Writer/Extension/ITunes/Feed.php index ac6e27bf..30b83fe3 100644 --- a/src/Writer/Extension/ITunes/Feed.php +++ b/src/Writer/Extension/ITunes/Feed.php @@ -47,7 +47,7 @@ class Feed */ public function __construct() { - $this->stringWrapper = StringUtils::getWrapper($this->getEncoding()); + $this->stringWrapper = StringUtils::getWrapper($this->encoding); } /** From 21546e8ea858df6cfb7db213c5b8c1854ff15031 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Sun, 6 Jan 2013 22:11:45 +0100 Subject: [PATCH 4/4] There is no encoding argument of strlen --- src/Writer/Extension/ITunes/Entry.php | 10 +++++----- src/Writer/Extension/ITunes/Feed.php | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Writer/Extension/ITunes/Entry.php b/src/Writer/Extension/ITunes/Entry.php index 72c703c7..c39c28e8 100644 --- a/src/Writer/Extension/ITunes/Entry.php +++ b/src/Writer/Extension/ITunes/Entry.php @@ -84,7 +84,7 @@ public function setItunesBlock($value) . ' contain alphabetic characters'); } - if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' . ' contain a maximum of 255 characters'); } @@ -114,7 +114,7 @@ public function addItunesAuthors(array $values) */ public function addItunesAuthor($value) { - if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only' . ' contain a maximum of 255 characters each'); } @@ -178,7 +178,7 @@ public function setItunesKeywords(array $value) } $concat = implode(',', $value); - if ($this->stringWrapper->strlen($concat, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($concat) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' . ' have a concatenated length of 255 chars where terms are delimited' . ' by a comma'); @@ -196,7 +196,7 @@ public function setItunesKeywords(array $value) */ public function setItunesSubtitle($value) { - if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "subtitle" may only' . ' contain a maximum of 255 characters'); } @@ -213,7 +213,7 @@ public function setItunesSubtitle($value) */ public function setItunesSummary($value) { - if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 4000) { + if ($this->stringWrapper->strlen($value) > 4000) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "summary" may only' . ' contain a maximum of 4000 characters'); } diff --git a/src/Writer/Extension/ITunes/Feed.php b/src/Writer/Extension/ITunes/Feed.php index 30b83fe3..59819f86 100644 --- a/src/Writer/Extension/ITunes/Feed.php +++ b/src/Writer/Extension/ITunes/Feed.php @@ -86,7 +86,7 @@ public function setItunesBlock($value) throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' . ' contain alphabetic characters'); } - if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' . ' contain a maximum of 255 characters'); } @@ -117,7 +117,7 @@ public function addItunesAuthors(array $values) */ public function addItunesAuthor($value) { - if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only' . ' contain a maximum of 255 characters each'); } @@ -142,19 +142,19 @@ public function setItunesCategories(array $values) } foreach ($values as $key=>$value) { if (!is_array($value)) { - if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' . ' contain a maximum of 255 characters each'); } $this->data['categories'][] = $value; } else { - if ($this->stringWrapper->strlen($key, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($key) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' . ' contain a maximum of 255 characters each'); } $this->data['categories'][$key] = array(); foreach ($value as $val) { - if ($this->stringWrapper->strlen($val, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($val) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' . ' contain a maximum of 255 characters each'); } @@ -239,7 +239,7 @@ public function setItunesKeywords(array $value) . ' contain a maximum of 12 terms'); } $concat = implode(',', $value); - if ($this->stringWrapper->strlen($concat, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($concat) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' . ' have a concatenated length of 255 chars where terms are delimited' . ' by a comma'); @@ -292,8 +292,8 @@ public function addItunesOwner(array $value) throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" must' . ' be an array containing keys "name" and "email"'); } - if ($this->stringWrapper->strlen($value['name'], $this->getEncoding()) > 255 - || $this->stringWrapper->strlen($value['email'], $this->getEncoding()) > 255 + if ($this->stringWrapper->strlen($value['name']) > 255 + || $this->stringWrapper->strlen($value['email']) > 255 ) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" may only' . ' contain a maximum of 255 characters each for "name" and "email"'); @@ -314,7 +314,7 @@ public function addItunesOwner(array $value) */ public function setItunesSubtitle($value) { - if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 255) { + if ($this->stringWrapper->strlen($value) > 255) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "subtitle" may only' . ' contain a maximum of 255 characters'); } @@ -331,7 +331,7 @@ public function setItunesSubtitle($value) */ public function setItunesSummary($value) { - if ($this->stringWrapper->strlen($value, $this->getEncoding()) > 4000) { + if ($this->stringWrapper->strlen($value) > 4000) { throw new Writer\Exception\InvalidArgumentException('invalid parameter: "summary" may only' . ' contain a maximum of 4000 characters'); }