aboutsummaryrefslogtreecommitdiffstats
path: root/Ustring.php
diff options
context:
space:
mode:
Diffstat (limited to 'Ustring.php')
-rw-r--r--Ustring.php30
1 files changed, 20 insertions, 10 deletions
diff --git a/Ustring.php b/Ustring.php
index 93c10a9..fe37f71 100644
--- a/Ustring.php
+++ b/Ustring.php
@@ -204,14 +204,6 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
*/
public function __construct($string = null)
{
- if (false === function_exists('mb_substr')) {
- throw new Exception(
- '%s needs the mbstring extension.',
- 0,
- get_class($this)
- );
- }
-
if (null !== $string) {
$this->append($string);
}
@@ -220,6 +212,16 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
}
/**
+ * Check if ext/mbstring is available.
+ *
+ * @return bool
+ */
+ public static function checkMbString()
+ {
+ return function_exists('mb_substr');
+ }
+
+ /**
* Append a substring to the current string, i.e. add to the end.
*
* @param string $substring Substring to append.
@@ -504,7 +506,7 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
throw new Exception(
'%s needs the class Normalizer to work properly, ' .
'or you can force a try by using %1$s(true).',
- 1,
+ 0,
__METHOD__
);
}
@@ -537,7 +539,7 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
if (null === $transliterator = static::getTransliterator($identifier)) {
throw new Exception(
'%s needs the class Transliterator to work properly.',
- 2,
+ 1,
__METHOD__
);
}
@@ -1035,3 +1037,11 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
* Flex entity.
*/
Core\Consistency::flexEntity('Hoa\Ustring\Ustring');
+
+if (false === Ustring::checkMbString()) {
+ throw new Exception(
+ '%s needs the mbstring extension.',
+ 0,
+ __NAMESPACE__ . '\Ustring'
+ );
+}