Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[2.1] Added Zend\Stdlib\StringUtils::hasPcreUnicodeSupport() #3495

Merged
merged 1 commit into from

2 participants

@marc-mabe

The method is a copy of Zend\Filter\AbstractFilter::hasPcreUnicodeSupport() but within Zend\Stdlib\StringUtils it's more reusable an can be used without Zend\Filter.

Zend\Stdlib isn't marked as a dependency of Zend\Filter but this method is using Zend\Stdlib\ErrorHandler. If we mark it as a dependency we could redirect and deprecate the method else the use of ErrorHandler should be removed.

@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#3495] Use StringUtils::hasPcreUnicodeSupport
- Updated Filter classes to use StringUtils::hasPcreUnicodeSupport
- AbstractFilter::hasPcreUnicodeSupport now proxies to
  StringUtils::hasPcreUnicodeSupport
  - docblock marks the method as deprecated
- Added zendframework/zend-stdlib to composer.json (should have been
  there regardless)
6e58907
@weierophinney weierophinney merged commit 4913c64 into zendframework:develop
@weierophinney

Merged, and made the changes suggested to the Filter component.

@katalonec katalonec referenced this pull request from a commit in katalonec/zf2
@weierophinney weierophinney Merge branch 'feature/3495' into develop
Close #3495
f4a94bb
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney [#3495] Use StringUtils::hasPcreUnicodeSupport
- Updated Filter classes to use StringUtils::hasPcreUnicodeSupport
- AbstractFilter::hasPcreUnicodeSupport now proxies to
  StringUtils::hasPcreUnicodeSupport
  - docblock marks the method as deprecated
- Added zendframework/zend-stdlib to composer.json (should have been
  there regardless)
71e7471
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'feature/3495' into develop
Close #3495
86420fd
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-stdlib
@weierophinney weierophinney Merge branch 'feature/3495' into develop bc7ad45
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-filter
@weierophinney weierophinney [zendframework/zf2#3495] Use StringUtils::hasPcreUnicodeSupport
- Updated Filter classes to use StringUtils::hasPcreUnicodeSupport
- AbstractFilter::hasPcreUnicodeSupport now proxies to
  StringUtils::hasPcreUnicodeSupport
  - docblock marks the method as deprecated
- Added zendframework/zend-stdlib to composer.json (should have been
  there regardless)
6bd21e4
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-filter
@weierophinney weierophinney Merge branch 'feature/3495' into develop 0da8a0e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
23 library/Zend/Stdlib/StringUtils.php
@@ -10,6 +10,7 @@
namespace Zend\Stdlib;
+use Zend\Stdlib\ErrorHandler;
use Zend\Stdlib\StringWrapper\StringWrapperInterface;
/**
@@ -46,6 +47,13 @@
);
/**
+ * Is PCRE compiled with Unicode support?
+ *
+ * @var bool
+ **/
+ protected static $hasPcreUnicodeSupport = null;
+
+ /**
* Get registered wrapper classes
*
* @return string[]
@@ -167,4 +175,19 @@ public static function isValidUtf8($str)
{
return is_string($str) && ($str === '' || preg_match('/^./su', $str) == 1);
}
+
+ /**
+ * Is PCRE compiled with Unicode support?
+ *
+ * @return bool
+ */
+ public static function hasPcreUnicodeSupport()
+ {
+ if (static::$hasPcreUnicodeSupport === null) {
+ ErrorHandler::start();
+ static::$hasPcreUnicodeSupport = defined('PREG_BAD_UTF8_OFFSET_ERROR') && preg_match('/\pL/u', 'a') == 1;
+ ErrorHandler::stop();
+ }
+ return static::$hasPcreUnicodeSupport;
+ }
}
View
10 tests/ZendTest/Stdlib/StringUtilsTest.php
@@ -11,6 +11,7 @@
namespace ZendTest\Stdlib;
use PHPUnit_Framework_TestCase as TestCase;
+use Zend\Stdlib\ErrorHandler;
use Zend\Stdlib\StringUtils;
class StringUtilsTest extends TestCase
@@ -147,4 +148,13 @@ public function testIsValidUtf8($str, $valid)
{
$this->assertSame($valid, StringUtils::isValidUtf8($str));
}
+
+ public function testHasPcreUnicodeSupport()
+ {
+ ErrorHandler::start();
+ $expected = defined('PREG_BAD_UTF8_OFFSET_ERROR') && preg_match('/\pL/u', 'a') == 1;
+ ErrorHandler::stop();
+
+ $this->assertSame($expected, StringUtils::hasPcreUnicodeSupport());
+ }
}
Something went wrong with that request. Please try again.