Skip to content
Browse files

StringUtils: phpdoc + cs

  • Loading branch information...
1 parent 6b42747 commit 3dd2d06bc5af0ae3321a6285c57d850384f4a4f2 @marc-mabe committed Nov 26, 2012
View
92 library/Zend/Stdlib/StringUtils.php
@@ -1,19 +1,45 @@
<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Stdlib
+ */
namespace Zend\Stdlib;
-use Zend\Loader\Broker,
- Zend\Loader\PluginBroker,
- Zend\Stdlib\StringWrapper\StringWrapperInterface,
- Zend\Stdlib\StringWrapper\MbString as MbStringWrapper,
- Zend\Stdlib\StringWrapper\Iconv as IconvWrapper,
- Zend\Stdlib\StringWrapper\Intl as IntlWrapper,
- Zend\Stdlib\StringWrapper\Native as NativeWrapper;
-
-class StringUtils
+use Zend\Stdlib\StringWrapper\StringWrapperInterface;
+use Zend\Stdlib\StringWrapper\MbString as MbStringWrapper;
+use Zend\Stdlib\StringWrapper\Iconv as IconvWrapper;
+use Zend\Stdlib\StringWrapper\Intl as IntlWrapper;
+use Zend\Stdlib\StringWrapper\Native as NativeWrapper;
+
+/**
+ * Utility class for handling strings of different character encodings
+ * using available PHP extensions.
+ *
+ * Declared abstract, as we have no need for instantiation.
+ *
+ * @category Zend
+ * @package Zend_Stdlib
+ */
+abstract class StringUtils
{
+ /**
+ * Ordered list of registered string wrapper instances
+ *
+ * @var StringWrapperInterface[]
+ */
protected static $wrapperRegistry;
+
+ /**
+ * A list of known single-byte charsets (upper-case)
+ *
+ * @var string[]
+ */
protected static $singleByteCharsets = array(
'ASCII', '7BIT', '8BIT',
'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5',
@@ -27,7 +53,7 @@ class StringUtils
/**
* Get registered wrappers
*
- * @return Zend\Stdlib\StringWrapper\StringWrapperInterface[]
+ * @return StringWrapperInterface[]
*/
public static function getRegisteredWrappers()
{
@@ -52,13 +78,25 @@ public static function getRegisteredWrappers()
return static::$wrapperRegistry;
}
+ /**
+ * Register a string wrapper
+ *
+ * @param StringWrapperInterface
+ * @return void
+ */
public static function registerWrapper(StringWrapperInterface $wrapper)
{
if (!in_array($wrapper, static::$wrapperRegistry, true)) {
static::$wrapperRegistry[] = $wrapper;
}
}
+ /**
+ * Unregister a string wrapper
+ *
+ * @param StringWrapperInterface $wrapper
+ * @return void
+ */
public static function unregisterWrapper(StringWrapperInterface $wrapper)
{
$index = array_search($wrapper, static::$wrapperRegistry, true);
@@ -67,6 +105,14 @@ public static function unregisterWrapper(StringWrapperInterface $wrapper)
}
}
+ /**
+ * Get the first string wrapper supporting one or more charsets
+ *
+ * @param string $charset Charset supported by he string wrapper
+ * @param string $charsetN, ... Unlimited OPTIONAL number of additional charsets
+ * @return StringWrapperInterface
+ * @throws Exception\RuntimeException If no wrapper supports all given charsets
+ */
public static function getWrapper($charset = 'UTF-8')
{
$charsets = func_get_args();
@@ -81,21 +127,41 @@ public static function getWrapper($charset = 'UTF-8')
return $wrapper;
}
- throw new Exception\RuntimeException('No wrapper found supporting charset(s) ' . implode(', ', $charsets));
+ throw new Exception\RuntimeException(
+ 'No wrapper found supporting charset(s) ' . implode(', ', $charsets)
+ );
}
+ /**
+ * Get a list of all known single-byte charsets
+ *
+ * @return string[]
+ */
public static function getSingleByteCharsets()
{
return static::$singleByteCharsets;
}
+ /**
+ * Check if a given charset is a known single-byte charset
+ *
+ * @param string $charset
+ * @return boolean
+ */
public static function isSingleByteCharset($charset)
{
return in_array(strtoupper($charset), static::$singleByteCharsets);
}
- public static function isValidUtf8($string)
+ /**
+ * Check if a given string is valid UTF-8 encoded
+ *
+ * @param string $str
+ * @return boolean
+ */
+ public static function isValidUtf8($str)
{
- return ($string === '' || preg_match('/^./su', $string) == 1);
+ return is_string($str) && ($str === '' || preg_match('/^./su', $str) == 1);
}
}
+
View
13 library/Zend/Stdlib/StringWrapper/AbstractStringWrapper.php
@@ -1,7 +1,20 @@
<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Stdlib
+ */
namespace Zend\Stdlib\StringWrapper;
+/**
+ * @category Zend
+ * @package Zend_Stdlib
+ * @subpackage StringWrapper
+ */
abstract class AbstractStringWrapper implements StringWrapperInterface
{
View
13 library/Zend/Stdlib/StringWrapper/Iconv.php
@@ -1,7 +1,20 @@
<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Stdlib
+ */
namespace Zend\Stdlib\StringWrapper;
+/**
+ * @category Zend
+ * @package Zend_Stdlib
+ * @subpackage StringWrapper
+ */
class Iconv extends AbstractStringWrapper
{
View
13 library/Zend/Stdlib/StringWrapper/Intl.php
@@ -1,7 +1,20 @@
<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Stdlib
+ */
namespace Zend\Stdlib\StringWrapper;
+/**
+ * @category Zend
+ * @package Zend_Stdlib
+ * @subpackage StringWrapper
+ */
class Intl extends AbstractStringWrapper
{
View
13 library/Zend/Stdlib/StringWrapper/MbString.php
@@ -1,7 +1,20 @@
<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Stdlib
+ */
namespace Zend\Stdlib\StringWrapper;
+/**
+ * @category Zend
+ * @package Zend_Stdlib
+ * @subpackage StringWrapper
+ */
class MbString extends AbstractStringWrapper
{
View
13 library/Zend/Stdlib/StringWrapper/Native.php
@@ -1,9 +1,22 @@
<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Stdlib
+ */
namespace Zend\Stdlib\StringWrapper;
use Zend\Stdlib\StringUtils;
+/**
+ * @category Zend
+ * @package Zend_Stdlib
+ * @subpackage StringWrapper
+ */
class Native extends AbstractStringWrapper
{
public function __construct()
View
61 library/Zend/Stdlib/StringWrapper/StringWrapperInterface.php
@@ -1,24 +1,81 @@
<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Stdlib
+ */
namespace Zend\Stdlib\StringWrapper;
+/**
+ * @category Zend
+ * @package Zend_Stdlib
+ * @subpackage StringWrapper
+ */
interface StringWrapperInterface
{
+ /**
+ * Check if the given charset is supported
+ *
+ * @param string $charset
+ * @return boolean
+ */
public function isCharsetSupported($charset);
+ /**
+ * Get a list of supported charsets
+ *
+ * @return string[]
+ */
public function getSupportedCharsets();
+ /**
+ * Returns the length of the given string
+ *
+ * @param string $str
+ * @param string $charset
+ * @return int
+ */
public function strlen($str, $charset = 'UTF-8');
+ /**
+ * Returns the portion of string specified by the start and length parameters
+ *
+ * @param string $str
+ * @param int $offset
+ * @param int|null $length
+ * @param string $charset
+ * @return string|false
+ */
public function substr($str, $offset = 0, $length = null, $charset = 'UTF-8');
+ /**
+ * Find the position of the first occurrence of a substring in a string
+ *
+ * @param string $haystack
+ * @param string $needle
+ * @param int $offset
+ * @param string $charset
+ * @return int|false
+ */
public function strpos($haystack, $needle, $offset = 0, $charset = 'UTF-8');
+ /**
+ * Convert a string from one character encoding to another
+ *
+ * @param string $str
+ * @param string $toCharset
+ * @param string $fromCharset
+ * @return string|false
+ */
public function convert($str, $toCharset, $fromCharset = 'UTF-8');
/**
- * Word wrap
+ * Wraps a string to a given number of characters
*
* @param string $str
* @param integer $width
@@ -30,7 +87,7 @@ public function convert($str, $toCharset, $fromCharset = 'UTF-8');
public function wordWrap($str, $width = 75, $break = "\n", $cut = false, $charset = 'UTF-8');
/**
- * String padding
+ * Pad a string to a certain length with another string
*
* @param string $input
* @param integer $padLength

0 comments on commit 3dd2d06

Please sign in to comment.
Something went wrong with that request. Please try again.