Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Stdlib\StringUtils #3110

Merged
merged 54 commits into from Jan 7, 2013
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
cd09a59
initial StringUtils
marc-mabe Jun 15, 2012
6c0f698
Merge branch 'master' of git://github.com/zendframework/zf2 into string
marc-mabe Jul 7, 2012
906b5c3
Native string adapter don't need ext/mbstring
marc-mabe Jul 8, 2012
2098c00
StringUtils: tests, no component deps
marc-mabe Jul 8, 2012
696fbec
Merge branch 'master' of git://github.com/zendframework/zf2 into string
marc-mabe Jul 8, 2012
49d8ec4
adapter -> wrapper
marc-mabe Jul 8, 2012
29e0da2
intl string wrapper and some small other changes
marc-mabe Jul 13, 2012
4adbb3d
Merge branch 'develop' of git://github.com/zendframework/zf2 into string
marc-mabe Nov 26, 2012
6b42747
ZendTest namespace
marc-mabe Nov 26, 2012
3dd2d06
StringUtils: phpdoc + cs
marc-mabe Nov 26, 2012
b17b3de
StringUtils: phpdoc + cs
marc-mabe Nov 27, 2012
0819967
StringUtils: added tests
marc-mabe Nov 27, 2012
1ebab45
StringUtilsTest: updated phpdoc
marc-mabe Nov 27, 2012
5c89903
StringUtils: cs
marc-mabe Nov 27, 2012
35b91e6
StringUtils: tests + fixes + supported encodings for iconv and mbstring
marc-mabe Nov 29, 2012
dde5cf5
StringUtils: wording: charset -> encoding
marc-mabe Nov 29, 2012
1d800eb
fixed wrong typed variable in StringUtils::getWrapper
marc-mabe Nov 29, 2012
bdeddca
StringUtils: cs
marc-mabe Nov 29, 2012
9a44514
StringUtils: implemented basic functionality into AbstractStringWrapp…
marc-mabe Nov 29, 2012
b831a53
StringUtils: hopefully a little better encoding list
marc-mabe Nov 29, 2012
5f42457
StringUtils: hopefully a little better encoding list
marc-mabe Nov 29, 2012
1c82b00
StringUtils: optimations
marc-mabe Nov 29, 2012
0c998cb
StringUtils: cs
marc-mabe Nov 29, 2012
c16b3ef
Updated Zend\Validator to used StringUtils
marc-mabe Nov 29, 2012
954950d
Updated Zend\Mvc to used StringUtils
marc-mabe Nov 29, 2012
7ba3c5f
StringUtils: MbString wrapper use of 'mb_list_encodings'
marc-mabe Nov 29, 2012
6b82989
Updated Zend\Text to use StringUtils and deprecated Zend\Text\MultiByte
marc-mabe Nov 29, 2012
d0fa0ad
Updated Zend\Feed to use StringUtils
marc-mabe Nov 29, 2012
0a17816
Zend\Feed: replaced one iconv_strlen with a string wrapper
marc-mabe Nov 30, 2012
90b0367
FIXME: Converting the euro sign from UTF-8 to ISO-8859-16 using the m…
marc-mabe Nov 30, 2012
46ae440
removed trailing spaces
marc-mabe Nov 30, 2012
0eb46d6
Changed API to only check given encoding once and to better support t…
marc-mabe Dec 31, 2012
7721563
Updated consumers after API changes
marc-mabe Dec 31, 2012
85b600e
It's 2013
marc-mabe Jan 2, 2013
54d97d5
else isn't needed, as the previous block returns on completion + remo…
marc-mabe Jan 3, 2013
68b0119
StringWrapper::convert() Renamed second argument to and fixed phpdoc
marc-mabe Jan 3, 2013
fca36d1
phpdoc
marc-mabe Jan 3, 2013
9c700c0
Added missing @deprecated
marc-mabe Jan 3, 2013
602787f
The native string wrapper doesn't support to convert between encodings
marc-mabe Jan 3, 2013
dbbbeeb
Added note why encodings are typed in case-mix
marc-mabe Jan 3, 2013
97a6da4
added methods get[Convert]Encoding() and removed constructor from int…
marc-mabe Jan 3, 2013
de69ead
fixed phpdoc
marc-mabe Jan 3, 2013
b394227
psr
marc-mabe Jan 6, 2013
5ef114b
added StringUtils::resetRegisteredWrappers() for testing purposes
marc-mabe Jan 6, 2013
adb6827
Global namespace not needed for constants
marc-mabe Jan 6, 2013
170b863
just use $this->encoding
marc-mabe Jan 6, 2013
9811ee1
File and class level docblocks
marc-mabe Jan 6, 2013
c5ec8cd
Removed not neccessary variable comversion as there is no strict comp…
marc-mabe Jan 6, 2013
e6d514f
Added short describtions on tests using data providers
marc-mabe Jan 6, 2013
4b8897a
added comment for a commented out block
marc-mabe Jan 6, 2013
7f0751a
Use array keys as description for data provider
marc-mabe Jan 6, 2013
ad9bf3d
There is no encoding argument of strlen
marc-mabe Jan 6, 2013
c3034a1
Make sure StringWrapper::convert don't substring return value on inva…
marc-mabe Jan 7, 2013
0c8ad71
removed unneccissary 'word-wrap-' prefix
marc-mabe Jan 7, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 23 additions & 6 deletions library/Zend/Feed/Writer/Extension/ITunes/Entry.php
Expand Up @@ -12,6 +12,8 @@

use Zend\Feed\Writer;
use Zend\Feed\Writer\Extension;
use Zend\Stdlib\StringUtils;
use Zend\Stdlib\StringWrapper\StringWrapperInterface;

/**
* @category Zend
Expand All @@ -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->encoding);
}

/**
* Set feed encoding
*
Expand All @@ -41,7 +55,8 @@ class Entry
*/
public function setEncoding($enc)
{
$this->encoding = $enc;
$this->stringWrapper = StringUtils::getWrapper($enc);
$this->encoding = $enc;
return $this;
}

Expand All @@ -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');
}
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');
Expand All @@ -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');
}
Expand All @@ -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');
}
Expand Down
40 changes: 29 additions & 11 deletions library/Zend/Feed/Writer/Extension/ITunes/Feed.php
Expand Up @@ -12,6 +12,8 @@

use Zend\Feed\Writer;
use Zend\Uri;
use Zend\Stdlib\StringUtils;
use Zend\Stdlib\StringWrapper\StringWrapperInterface;

/**
* @category Zend
Expand All @@ -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->encoding);
}

/**
* Set feed encoding
*
Expand All @@ -41,7 +58,8 @@ class Feed
*/
public function setEncoding($enc)
{
$this->encoding = $enc;
$this->stringWrapper = StringUtils::getWrapper($enc);
$this->encoding = $enc;
return $this;
}

Expand All @@ -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');
}
Expand Down Expand Up @@ -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');
}
Expand All @@ -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');
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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"');
Expand All @@ -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');
}
Expand All @@ -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');
}
Expand Down
7 changes: 6 additions & 1 deletion library/Zend/Mvc/View/Console/RouteNotFoundStrategy.php
Expand Up @@ -26,6 +26,7 @@
use Zend\View\Model\ConsoleModel;
use Zend\Version\Version;
use Zend\Stdlib\ResponseInterface as Response;
use Zend\Stdlib\StringUtils;
use Zend\Text\Table;

/**
Expand Down Expand Up @@ -389,6 +390,7 @@ protected function renderTable($data, $cols, $consoleWidth)
$result = '';
$padding = 2;


// If there is only 1 column, just concatenate it
if ($cols == 1) {
foreach ($data as $row) {
Expand All @@ -397,12 +399,15 @@ protected function renderTable($data, $cols, $consoleWidth)
return $result;
}

// Get the string wrapper supporting UTF-8 character encoding
$strWrapper = StringUtils::getWrapper('UTF-8');

// Determine max width for each column
$maxW = array();
for ($x = 1; $x <= $cols; $x += 1) {
$maxW[$x] = 0;
foreach ($data as $row) {
$maxW[$x] = max($maxW[$x], mb_strlen($row[$x-1],'utf-8') + $padding * 2);
$maxW[$x] = max($maxW[$x], $strWrapper->strlen($row[$x-1]) + $padding * 2);
}
}

Expand Down
8 changes: 7 additions & 1 deletion library/Zend/ProgressBar/Adapter/Console.php
Expand Up @@ -12,6 +12,7 @@

use Zend\ProgressBar\Adapter\Exception;
use Zend\Stdlib\ErrorHandler;
use Zend\Stdlib\StringUtils;

/**
* Zend_ProgressBar_Adapter_Console offers a text-based progressbar for console
Expand Down Expand Up @@ -438,7 +439,12 @@ public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $te
break;

case self::ELEMENT_TEXT:
$renderedElements[] = \Zend\Text\MultiByte::strPad(substr($text, 0, $this->textWidth), $this->textWidth, ' ', STR_PAD_RIGHT, $this->charset);
$renderedElements[] = StringUtils::getWrapper($this->charset)->strPad(
substr($text, 0, $this->textWidth),
$this->textWidth,
' ',
STR_PAD_RIGHT
);
break;
}
}
Expand Down
22 changes: 22 additions & 0 deletions library/Zend/Stdlib/Exception/ExtensionNotLoadedException.php
@@ -0,0 +1,22 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Stdlib
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs file and class level docblocks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

namespace Zend\Stdlib\Exception;

/**
* Extension not loaded exception
*
* @category Zend
* @package Zend_Stdlib
* @subpackage Exception
*/
class ExtensionNotLoadedException extends RuntimeException
{
}
22 changes: 22 additions & 0 deletions library/Zend/Stdlib/Exception/RuntimeException.php
@@ -0,0 +1,22 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Stdlib
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs file and class level docblocks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

namespace Zend\Stdlib\Exception;

/**
* Runtime exception
*
* @category Zend
* @package Zend_Stdlib
* @subpackage Exception
*/
class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}