-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use a string wrapper to support intl, mbstring and iconv extension #131
Open
sandrokeil
wants to merge
1
commit into
beberlei:master
Choose a base branch
from
sandrokeil:php-intl
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,13 +36,13 @@ | |
* @method static void nullOrNotNull($value, $message = null, $propertyPath = null) | ||
* @method static void nullOrString($value, $message = null, $propertyPath = null) | ||
* @method static void nullOrRegex($value, $pattern, $message = null, $propertyPath = null) | ||
* @method static void nullOrLength($value, $length, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void nullOrMinLength($value, $minLength, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void nullOrMaxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void nullOrBetweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void nullOrStartsWith($string, $needle, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void nullOrEndsWith($string, $needle, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void nullOrContains($string, $needle, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void nullOrLength($value, $length, $message = null, $propertyPath = null) | ||
* @method static void nullOrMinLength($value, $minLength, $message = null, $propertyPath = null) | ||
* @method static void nullOrMaxLength($value, $maxLength, $message = null, $propertyPath = null) | ||
* @method static void nullOrBetweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null) | ||
* @method static void nullOrStartsWith($string, $needle, $message = null, $propertyPath = null) | ||
* @method static void nullOrEndsWith($string, $needle, $message = null, $propertyPath = null) | ||
* @method static void nullOrContains($string, $needle, $message = null, $propertyPath = null) | ||
* @method static void nullOrChoice($value, $choices, $message = null, $propertyPath = null) | ||
* @method static void nullOrInArray($value, $choices, $message = null, $propertyPath = null) | ||
* @method static void nullOrNumeric($value, $message = null, $propertyPath = null) | ||
|
@@ -92,13 +92,13 @@ | |
* @method static void allNotNull($value, $message = null, $propertyPath = null) | ||
* @method static void allString($value, $message = null, $propertyPath = null) | ||
* @method static void allRegex($value, $pattern, $message = null, $propertyPath = null) | ||
* @method static void allLength($value, $length, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void allMinLength($value, $minLength, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void allMaxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void allBetweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void allStartsWith($string, $needle, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void allEndsWith($string, $needle, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void allContains($string, $needle, $message = null, $propertyPath = null, $encoding = "utf8") | ||
* @method static void allLength($value, $length, $message = null, $propertyPath = null) | ||
* @method static void allMinLength($value, $minLength, $message = null, $propertyPath = null) | ||
* @method static void allMaxLength($value, $maxLength, $message = null, $propertyPath = null) | ||
* @method static void allBetweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null) | ||
* @method static void allStartsWith($string, $needle, $message = null, $propertyPath = null) | ||
* @method static void allEndsWith($string, $needle, $message = null, $propertyPath = null) | ||
* @method static void allContains($string, $needle, $message = null, $propertyPath = null) | ||
* @method static void allChoice($value, $choices, $message = null, $propertyPath = null) | ||
* @method static void allInArray($value, $choices, $message = null, $propertyPath = null) | ||
* @method static void allNumeric($value, $message = null, $propertyPath = null) | ||
|
@@ -132,7 +132,6 @@ | |
* @method static void allChoicesNotEmpty($values, $choices, $message = null, $propertyPath = null) | ||
* @method static void allMethodExists($value, $object, $message = null, $propertyPath = null) | ||
* @method static void allIsObject($value, $message = null, $propertyPath = null) | ||
* @method static void allDate($value, $format, $message = null, $propertyPath = null) | ||
* METHODEND | ||
*/ | ||
class Assertion | ||
|
@@ -543,23 +542,22 @@ public static function regex($value, $pattern, $message = null, $propertyPath = | |
* @param int $length | ||
* @param string|null $message | ||
* @param string|null $propertyPath | ||
* @param string $encoding | ||
* @return void | ||
* @throws \Assert\AssertionFailedException | ||
*/ | ||
public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') | ||
public static function length($value, $length, $message = null, $propertyPath = null) | ||
{ | ||
static::string($value, $message, $propertyPath); | ||
|
||
if (mb_strlen($value, $encoding) !== $length) { | ||
if (grapheme_strlen($value) !== $length) { | ||
$message = sprintf( | ||
$message ?: 'Value "%s" has to be %d exactly characters long, but length is %d.', | ||
self::stringify($value), | ||
$length, | ||
mb_strlen($value, $encoding) | ||
grapheme_strlen($value) | ||
); | ||
|
||
$constraints = array('length' => $length, 'encoding' => $encoding); | ||
$constraints = array('length' => $length); | ||
throw static::createException($value, $message, static::INVALID_LENGTH, $propertyPath, $constraints); | ||
} | ||
} | ||
|
@@ -571,23 +569,22 @@ public static function length($value, $length, $message = null, $propertyPath = | |
* @param int $minLength | ||
* @param string|null $message | ||
* @param string|null $propertyPath | ||
* @param string $encoding | ||
* @return void | ||
* @throws \Assert\AssertionFailedException | ||
*/ | ||
public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') | ||
public static function minLength($value, $minLength, $message = null, $propertyPath = null) | ||
{ | ||
static::string($value, $message, $propertyPath); | ||
|
||
if (mb_strlen($value, $encoding) < $minLength) { | ||
if (grapheme_strlen($value) < $minLength) { | ||
$message = sprintf( | ||
$message ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', | ||
self::stringify($value), | ||
$minLength, | ||
mb_strlen($value, $encoding) | ||
grapheme_strlen($value) | ||
); | ||
|
||
$constraints = array('min_length' => $minLength, 'encoding' => $encoding); | ||
$constraints = array('min_length' => $minLength); | ||
throw static::createException($value, $message, static::INVALID_MIN_LENGTH, $propertyPath, $constraints); | ||
} | ||
} | ||
|
@@ -599,23 +596,22 @@ public static function minLength($value, $minLength, $message = null, $propertyP | |
* @param integer $maxLength | ||
* @param string|null $message | ||
* @param string|null $propertyPath | ||
* @param string $encoding | ||
* @return void | ||
* @throws \Assert\AssertionFailedException | ||
*/ | ||
public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') | ||
public static function maxLength($value, $maxLength, $message = null, $propertyPath = null) | ||
{ | ||
static::string($value, $message, $propertyPath); | ||
|
||
if (mb_strlen($value, $encoding) > $maxLength) { | ||
if (grapheme_strlen($value) > $maxLength) { | ||
$message = sprintf( | ||
$message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', | ||
self::stringify($value), | ||
$maxLength, | ||
mb_strlen($value, $encoding) | ||
grapheme_strlen($value) | ||
); | ||
|
||
$constraints = array('max_length' => $maxLength, 'encoding' => $encoding); | ||
$constraints = array('max_length' => $maxLength); | ||
throw static::createException($value, $message, static::INVALID_MAX_LENGTH, $propertyPath, $constraints); | ||
} | ||
} | ||
|
@@ -628,35 +624,34 @@ public static function maxLength($value, $maxLength, $message = null, $propertyP | |
* @param integer $maxLength | ||
* @param string|null $message | ||
* @param string|null $propertyPath | ||
* @param string $encoding | ||
* @return void | ||
* @throws \Assert\AssertionFailedException | ||
*/ | ||
public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') | ||
public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null) | ||
{ | ||
static::string($value, $message, $propertyPath); | ||
|
||
if (mb_strlen($value, $encoding) < $minLength) { | ||
if (grapheme_strlen($value) < $minLength) { | ||
$message = sprintf( | ||
$message ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', | ||
self::stringify($value), | ||
$minLength, | ||
mb_strlen($value, $encoding) | ||
grapheme_strlen($value) | ||
); | ||
|
||
$constraints = array('min_length' => $minLength, 'encoding' => $encoding); | ||
$constraints = array('min_length' => $minLength); | ||
throw static::createException($value, $message, static::INVALID_MIN_LENGTH, $propertyPath, $constraints); | ||
} | ||
|
||
if (mb_strlen($value, $encoding) > $maxLength) { | ||
if (grapheme_strlen($value) > $maxLength) { | ||
$message = sprintf( | ||
$message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', | ||
self::stringify($value), | ||
$maxLength, | ||
mb_strlen($value, $encoding) | ||
grapheme_strlen($value) | ||
); | ||
|
||
$constraints = array('max_length' => $maxLength, 'encoding' => $encoding); | ||
$constraints = array('max_length' => $maxLength); | ||
throw static::createException($value, $message, static::INVALID_MAX_LENGTH, $propertyPath, $constraints); | ||
} | ||
} | ||
|
@@ -668,22 +663,21 @@ public static function betweenLength($value, $minLength, $maxLength, $message = | |
* @param string $needle | ||
* @param string|null $message | ||
* @param string|null $propertyPath | ||
* @param string $encoding | ||
* @return void | ||
* @throws \Assert\AssertionFailedException | ||
*/ | ||
public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') | ||
public static function startsWith($string, $needle, $message = null, $propertyPath = null) | ||
{ | ||
static::string($string, $message, $propertyPath); | ||
|
||
if (mb_strpos($string, $needle, null, $encoding) !== 0) { | ||
if (grapheme_strpos($string, $needle, null) !== 0) { | ||
$message = sprintf( | ||
$message ?: 'Value "%s" does not start with "%s".', | ||
self::stringify($string), | ||
self::stringify($needle) | ||
); | ||
|
||
$constraints = array('needle' => $needle, 'encoding' => $encoding); | ||
$constraints = array('needle' => $needle); | ||
throw static::createException($string, $message, static::INVALID_STRING_START, $propertyPath, $constraints); | ||
} | ||
} | ||
|
@@ -695,24 +689,23 @@ public static function startsWith($string, $needle, $message = null, $propertyPa | |
* @param string $needle | ||
* @param string|null $message | ||
* @param string|null $propertyPath | ||
* @param string $encoding | ||
* @return void | ||
* @throws \Assert\AssertionFailedException | ||
*/ | ||
public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') | ||
public static function endsWith($string, $needle, $message = null, $propertyPath = null) | ||
{ | ||
static::string($string, $message, $propertyPath); | ||
|
||
$stringPosition = mb_strlen($string, $encoding) - mb_strlen($needle, $encoding); | ||
$stringPosition = grapheme_strlen($string) - grapheme_strlen($needle); | ||
|
||
if (mb_strripos($string, $needle, null, $encoding) !== $stringPosition) { | ||
if (grapheme_strripos($string, $needle, null) !== $stringPosition) { | ||
$message = sprintf( | ||
$message ?: 'Value "%s" does not end with "%s".', | ||
self::stringify($string), | ||
self::stringify($needle) | ||
); | ||
|
||
$constraints = array('needle' => $needle, 'encoding' => $encoding); | ||
$constraints = array('needle' => $needle); | ||
throw static::createException($string, $message, static::INVALID_STRING_END, $propertyPath, $constraints); | ||
} | ||
} | ||
|
@@ -724,22 +717,21 @@ public static function endsWith($string, $needle, $message = null, $propertyPath | |
* @param string $needle | ||
* @param string|null $message | ||
* @param string|null $propertyPath | ||
* @param string $encoding | ||
* @return void | ||
* @throws \Assert\AssertionFailedException | ||
*/ | ||
public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') | ||
public static function contains($string, $needle, $message = null, $propertyPath = null) | ||
{ | ||
static::string($string, $message, $propertyPath); | ||
|
||
if (mb_strpos($string, $needle, null, $encoding) === false) { | ||
if (grapheme_strpos($string, $needle, null) === false) { | ||
$message = sprintf( | ||
$message ?: 'Value "%s" does not contain "%s".', | ||
self::stringify($string), | ||
self::stringify($needle) | ||
); | ||
|
||
$constraints = array('needle' => $needle, 'encoding' => $encoding); | ||
$constraints = array('needle' => $needle); | ||
throw static::createException($string, $message, static::INVALID_STRING_CONTAINS, $propertyPath, $constraints); | ||
} | ||
} | ||
|
@@ -1657,23 +1649,23 @@ public static function greaterOrEqualThan($value, $limit, $message = null, $prop | |
* | ||
* @link http://php.net/manual/function.date.php#refsect1-function.date-parameters | ||
*/ | ||
public static function date($value, $format, $message = null, $propertyPath = null) | ||
{ | ||
static::string($value, $message, $propertyPath); | ||
static::string($format, $message, $propertyPath); | ||
public static function date($value, $format, $message = null, $propertyPath = null) | ||
{ | ||
static::string($value, $message, $propertyPath); | ||
static::string($format, $message, $propertyPath); | ||
|
||
$dateTime = \DateTime::createFromFormat($format, $value); | ||
$dateTime = \DateTime::createFromFormat($format, $value); | ||
|
||
if (false === $dateTime || $value !== $dateTime->format($format)) { | ||
$message = sprintf( | ||
$message ?: 'Date "%s" is invalid or does not match format "%s".', | ||
self::stringify($value), | ||
self::stringify($format) | ||
); | ||
if (false === $dateTime || $value !== $dateTime->format($format)) { | ||
$message = sprintf( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why removing this feature ? |
||
$message ?: 'Date "%s" is invalid or does not match format "%s".', | ||
self::stringify($value), | ||
self::stringify($format) | ||
); | ||
|
||
throw static::createException($value, $message, static::INVALID_DATE, $propertyPath, array('format' => $format)); | ||
} | ||
} | ||
throw static::createException($value, $message, static::INVALID_DATE, $propertyPath, array('format' => $format)); | ||
} | ||
} | ||
|
||
/** | ||
* Make a string version of a value. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another removal?
Are you using
bin/generate_method_docs.php
to update the docblocks?