mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-09-02 17:42:58 +02:00
Compare commits
1 Commits
master
...
disable-mb
Author | SHA1 | Date | |
---|---|---|---|
|
ee1e4074a6 |
10
.travis.yml
10
.travis.yml
@@ -10,6 +10,10 @@ sudo: false
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- php: 5.3
|
||||
env: polyfill='true'
|
||||
- php: 5.3
|
||||
env: polyfill='false'
|
||||
- php: 5.4
|
||||
env: polyfill='true'
|
||||
- php: 5.4
|
||||
@@ -26,18 +30,14 @@ matrix:
|
||||
env: polyfill='true'
|
||||
- php: 7.0
|
||||
env: polyfill='false'
|
||||
- php: 7.1
|
||||
env: polyfill='true'
|
||||
- php: 7.1
|
||||
env: polyfill='false'
|
||||
|
||||
install: travis_retry composer install --no-interaction --prefer-source
|
||||
|
||||
before_script:
|
||||
- travis_retry composer self-update
|
||||
- travis_retry composer install --no-interaction --prefer-source
|
||||
- if [[ $polyfill = 'true' ]]; then cat ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
|
||||
- if [[ $polyfill = 'false' ]]; then travis_retry composer remove symfony/polyfill-mbstring; fi
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit
|
||||
|
||||
|
36
CHANGELOG.md
36
CHANGELOG.md
@@ -1,39 +1,3 @@
|
||||
### 3.1.0 (2017-06-11)
|
||||
* Add $language support to slugify
|
||||
* Add bg specific transliteration
|
||||
* ЬЪ/ьъ handling is now language-specific
|
||||
|
||||
### 3.0.1 (2017-04-12)
|
||||
* Don't replace @ in toAscii
|
||||
* Use normal replacement for @ in slugify, e.g. user@home => user-home
|
||||
|
||||
### 3.0.0 (2017-03-08)
|
||||
|
||||
* Breaking change: added $language parameter to toAscii, before
|
||||
$removeUnsupported
|
||||
* Breaking change: dropped PHP 5.3 support
|
||||
* Breaking change: any StaticStringy methods that previously returned instances
|
||||
of Stringy now return strings
|
||||
|
||||
### 2.4.0 (2017-03-02)
|
||||
|
||||
* Add startsWithAny
|
||||
* Add endsWithAny
|
||||
* Add stripWhitespace
|
||||
* Fix error handling for unsupported encodings
|
||||
* Change private methods to protected for extending class
|
||||
* Fix safeTruncate for strings without spaces
|
||||
* Additional char support in toAscii, e.g. full width chars and wide
|
||||
non-breaking space
|
||||
|
||||
### 2.3.2 (2016-05-02)
|
||||
|
||||
* Improve support without mbstring
|
||||
|
||||
### 2.3.1 (2016-03-21)
|
||||
|
||||
* Always use root namespace for mbstring functions
|
||||
|
||||
### 2.3.0 (2016-03-19)
|
||||
|
||||
* Add Persian characters in Stringy::charsArray()
|
||||
|
283
README.md
283
README.md
@@ -1,16 +1,13 @@
|
||||

|
||||
|
||||
A PHP string manipulation library with multibyte support. Compatible with PHP
|
||||
5.4+, PHP 7+, and HHVM.
|
||||
5.3+, PHP 7, and HHVM. Refer to the [1.x branch](https://github.com/danielstjules/Stringy/tree/1.x)
|
||||
for older documentation.
|
||||
|
||||
``` php
|
||||
s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
|
||||
```
|
||||
|
||||
Refer to the [1.x branch](https://github.com/danielstjules/Stringy/tree/1.x) or
|
||||
[2.x branch](https://github.com/danielstjules/Stringy/tree/2.x) for older
|
||||
documentation.
|
||||
|
||||
[](https://travis-ci.org/danielstjules/Stringy)
|
||||
[](https://packagist.org/packages/danielstjules/stringy)
|
||||
[](https://packagist.org/packages/danielstjules/stringy)
|
||||
@@ -24,129 +21,83 @@ documentation.
|
||||
* [Class methods](#class-methods)
|
||||
* [create](#createmixed-str--encoding-)
|
||||
* [Instance methods](#instance-methods)
|
||||
<table>
|
||||
<tr>
|
||||
<td><a href="#appendstring-string">append</a></td>
|
||||
<td><a href="#atint-index">at</a></td>
|
||||
<td><a href="#betweenstring-start-string-end--int-offset">between</a></td>
|
||||
<td><a href="#camelize">camelize</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#chars">chars</a></td>
|
||||
<td><a href="#collapsewhitespace">collapseWhitespace</a></td>
|
||||
<td><a href="#containsstring-needle--boolean-casesensitive--true-">contains</a></td>
|
||||
<td><a href="#containsallarray-needles--boolean-casesensitive--true-">containsAll</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#containsanyarray-needles--boolean-casesensitive--true-">containsAny</a></td>
|
||||
<td><a href="#countsubstrstring-substring--boolean-casesensitive--true-">countSubstr</a></td>
|
||||
<td><a href="#dasherize">dasherize</a></td>
|
||||
<td><a href="#delimitint-delimiter">delimit</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#endswithstring-substring--boolean-casesensitive--true-">endsWith</a></td>
|
||||
<td><a href="#endswithanystring-substrings--boolean-casesensitive--true-">endsWithAny</a></td>
|
||||
<td><a href="#ensureleftstring-substring">ensureLeft</a></td>
|
||||
<td><a href="#ensurerightstring-substring">ensureRight</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#firstint-n">first</a></td>
|
||||
<td><a href="#getencoding">getEncoding</a></td>
|
||||
<td><a href="#haslowercase">hasLowerCase</a></td>
|
||||
<td><a href="#hasuppercase">hasUpperCase</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#htmldecode">htmlDecode</a></td>
|
||||
<td><a href="#htmlencode">htmlEncode</a></td>
|
||||
<td><a href="#humanize">humanize</a></td>
|
||||
<td><a href="#indexofstring-needle--offset--0-">indexOf</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#indexoflaststring-needle--offset--0-">indexOfLast</a></td>
|
||||
<td><a href="#insertint-index-string-substring">insert</a></td>
|
||||
<td><a href="#isalpha">isAlpha</a></td>
|
||||
<td><a href="#isalphanumeric">isAlphanumeric</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#isbase64">isBase64</a></td>
|
||||
<td><a href="#isblank">isBlank</a></td>
|
||||
<td><a href="#ishexadecimal">isHexadecimal</a></td>
|
||||
<td><a href="#isjson">isJson</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#islowercase">isLowerCase</a></td>
|
||||
<td><a href="#isserialized">isSerialized</a></td>
|
||||
<td><a href="#isuppercase">isUpperCase</a></td>
|
||||
<td><a href="#lastint-n">last</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#length">length</a></td>
|
||||
<td><a href="#lines">lines</a></td>
|
||||
<td><a href="#longestcommonprefixstring-otherstr">longestCommonPrefix</a></td>
|
||||
<td><a href="#longestcommonsuffixstring-otherstr">longestCommonSuffix</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#longestcommonsubstringstring-otherstr">longestCommonSubstring</a></td>
|
||||
<td><a href="#lowercasefirst">lowerCaseFirst</a></td>
|
||||
<td><a href="#padint-length--string-padstr-----string-padtype--right-">pad</a></td>
|
||||
<td><a href="#padbothint-length--string-padstr----">padBoth</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#padleftint-length--string-padstr----">padLeft</a></td>
|
||||
<td><a href="#padrightint-length--string-padstr----">padRight</a></td>
|
||||
<td><a href="#prependstring-string">prepend</a></td>
|
||||
<td><a href="#regexreplacestring-pattern-string-replacement--string-options--msr">regexReplace</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#removeleftstring-substring">removeLeft</a></td>
|
||||
<td><a href="#removerightstring-substring">removeRight</a></td>
|
||||
<td><a href="#repeatint-multiplier">repeat</a></td>
|
||||
<td><a href="#replacestring-search-string-replacement">replace</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#reverse">reverse</a></td>
|
||||
<td><a href="#safetruncateint-length--string-substring---">safeTruncate</a></td>
|
||||
<td><a href="#shuffle">shuffle</a></td>
|
||||
<td><a href="#slugify-string-replacement-----string-language--en">slugify</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#sliceint-start--int-end-">slice</a></td>
|
||||
<td><a href="#splitstring-pattern--int-limit-">split</a></td>
|
||||
<td><a href="#startswithstring-substring--boolean-casesensitive--true-">startsWith</a></td>
|
||||
<td><a href="#startswithanystring-substrings--boolean-casesensitive--true-">startsWithAny</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#stripwhitespace">stripWhitespace</a></td>
|
||||
<td><a href="#substrint-start--int-length-">substr</a></td>
|
||||
<td><a href="#surroundstring-substring">surround</a></td>
|
||||
<td><a href="#swapcase">swapCase</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#tidy">tidy</a></td>
|
||||
<td><a href="#titleize-array-ignore">titleize</a></td>
|
||||
<td><a href="#toascii-string-language--en--bool-removeunsupported--true-">toAscii</a></td>
|
||||
<td><a href="#toboolean">toBoolean</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#tolowercase">toLowerCase</a></td>
|
||||
<td><a href="#tospaces-tablength--4-">toSpaces</a></td>
|
||||
<td><a href="#totabs-tablength--4-">toTabs</a></td>
|
||||
<td><a href="#totitlecase">toTitleCase</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#touppercase">toUpperCase</a></td>
|
||||
<td><a href="#trim-string-chars">trim</a></td>
|
||||
<td><a href="#trimleft-string-chars">trimLeft</a></td>
|
||||
<td><a href="#trimright-string-chars">trimRight</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="#truncateint-length--string-substring---">truncate</a></td>
|
||||
<td><a href="#underscored">underscored</a></td>
|
||||
<td><a href="#uppercamelize">upperCamelize</a></td>
|
||||
<td><a href="#uppercasefirst">upperCaseFirst</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
* [append](#appendstring-string)
|
||||
* [at](#atint-index)
|
||||
* [between](#betweenstring-start-string-end--int-offset)
|
||||
* [camelize](#camelize)
|
||||
* [chars](#chars)
|
||||
* [collapseWhitespace](#collapsewhitespace)
|
||||
* [contains](#containsstring-needle--boolean-casesensitive--true-)
|
||||
* [containsAll](#containsallarray-needles--boolean-casesensitive--true-)
|
||||
* [containsAny](#containsanyarray-needles--boolean-casesensitive--true-)
|
||||
* [countSubstr](#countsubstrstring-substring--boolean-casesensitive--true-)
|
||||
* [dasherize](#dasherize)
|
||||
* [delimit](#delimitint-delimiter)
|
||||
* [endsWith](#endswithstring-substring--boolean-casesensitive--true-)
|
||||
* [ensureLeft](#ensureleftstring-substring)
|
||||
* [ensureRight](#ensurerightstring-substring)
|
||||
* [first](#firstint-n)
|
||||
* [getEncoding](#getencoding)
|
||||
* [hasLowerCase](#haslowercase)
|
||||
* [hasUpperCase](#hasuppercase)
|
||||
* [htmlDecode](#htmldecode)
|
||||
* [htmlEncode](#htmlencode)
|
||||
* [humanize](#humanize)
|
||||
* [indexOf](#indexofstring-needle--offset--0-)
|
||||
* [indexOfLast](#indexoflaststring-needle--offset--0-)
|
||||
* [insert](#insertint-index-string-substring)
|
||||
* [isAlpha](#isalpha)
|
||||
* [isAlphanumeric](#isalphanumeric)
|
||||
* [isBase64](#isbase64)
|
||||
* [isBlank](#isblank)
|
||||
* [isHexadecimal](#ishexadecimal)
|
||||
* [isJson](#isjson)
|
||||
* [isLowerCase](#islowercase)
|
||||
* [isSerialized](#isserialized)
|
||||
* [isUpperCase](#isuppercase)
|
||||
* [last](#last)
|
||||
* [length](#length)
|
||||
* [lines](#lines)
|
||||
* [longestCommonPrefix](#longestcommonprefixstring-otherstr)
|
||||
* [longestCommonSuffix](#longestcommonsuffixstring-otherstr)
|
||||
* [longestCommonSubstring](#longestcommonsubstringstring-otherstr)
|
||||
* [lowerCaseFirst](#lowercasefirst)
|
||||
* [pad](#padint-length--string-padstr-----string-padtype--right-)
|
||||
* [padBoth](#padbothint-length--string-padstr----)
|
||||
* [padLeft](#padleftint-length--string-padstr----)
|
||||
* [padRight](#padrightint-length--string-padstr----)
|
||||
* [prepend](#prependstring-string)
|
||||
* [regexReplace](#regexreplacestring-pattern-string-replacement--string-options--msr)
|
||||
* [removeLeft](#removeleftstring-substring)
|
||||
* [removeRight](#removerightstring-substring)
|
||||
* [repeat](#repeatmultiplier)
|
||||
* [replace](#replacestring-search-string-replacement)
|
||||
* [reverse](#reverse)
|
||||
* [safeTruncate](#safetruncateint-length--string-substring---)
|
||||
* [shuffle](#shuffle)
|
||||
* [slugify](#slugify-string-replacement----)
|
||||
* [startsWith](#startswithstring-substring--boolean-casesensitive--true-)
|
||||
* [slice](#sliceint-start--int-end-)
|
||||
* [split](#splitstring-pattern--int-limit-)
|
||||
* [substr](#substrint-start--int-length-)
|
||||
* [surround](#surroundstring-substring)
|
||||
* [swapCase](#swapcase)
|
||||
* [tidy](#tidy)
|
||||
* [titleize](#titleize-array-ignore)
|
||||
* [toAscii](#toascii)
|
||||
* [toBoolean](#toboolean)
|
||||
* [toLowerCase](#tolowercase)
|
||||
* [toSpaces](#tospaces-tablength--4-)
|
||||
* [toTabs](#totabs-tablength--4-)
|
||||
* [toTitleCase](#totitlecase)
|
||||
* [toUpperCase](#touppercase)
|
||||
* [trim](#trim-string-chars)
|
||||
* [trimLeft](#trimleft-string-chars)
|
||||
* [trimRight](#trimright-string-chars)
|
||||
* [truncate](#truncateint-length--string-substring---)
|
||||
* [underscored](#underscored)
|
||||
* [upperCamelize](#uppercamelize)
|
||||
* [upperCaseFirst](#uppercasefirst)
|
||||
* [Extensions](#extensions)
|
||||
* [Tests](#tests)
|
||||
* [License](#license)
|
||||
@@ -180,7 +131,7 @@ in your composer.json file:
|
||||
|
||||
```json
|
||||
"require": {
|
||||
"danielstjules/stringy": "~3.1.0"
|
||||
"danielstjules/stringy": "~2.3"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -288,9 +239,9 @@ integer, boolean, etc.
|
||||
```php
|
||||
use Stringy\StaticStringy as S;
|
||||
|
||||
// Translates to Stringy::create('fòôbàř')->slice(0, 3);
|
||||
// Translates to Stringy::create('fòôbàř', 'UTF-8')->slice(0, 3);
|
||||
// Returns a Stringy object with the string "fòô"
|
||||
S::slice('fòôbàř', 0, 3);
|
||||
S::slice('fòôbàř', 0, 3, 'UTF-8');
|
||||
```
|
||||
|
||||
## Class methods
|
||||
@@ -304,7 +255,7 @@ then returns the initialized object. Throws an InvalidArgumentException
|
||||
if the first argument is an array or object without a __toString method.
|
||||
|
||||
```php
|
||||
$stringy = S::create('fòôbàř'); // 'fòôbàř'
|
||||
$stringy = S::create('fòôbàř', 'UTF-8'); // 'fòôbàř'
|
||||
```
|
||||
|
||||
## Instance Methods
|
||||
@@ -437,17 +388,7 @@ default, the comparison is case-sensitive, but can be made insensitive by
|
||||
setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
s('fòôbàř')->endsWith('bàř'); // true
|
||||
```
|
||||
|
||||
##### endsWithAny(string[] $substrings [, boolean $caseSensitive = true ])
|
||||
|
||||
Returns true if the string ends with any of $substrings, false otherwise.
|
||||
By default, the comparison is case-sensitive, but can be made insensitive
|
||||
by setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
s('fòôbàř')->endsWithAny(['bàř', 'baz']); // true
|
||||
s('fòôbàř')->endsWith('bàř', true); // true
|
||||
```
|
||||
|
||||
##### ensureLeft(string $substring)
|
||||
@@ -479,7 +420,7 @@ s('fòôbàř')->first(3); // 'fòô'
|
||||
Returns the encoding used by the Stringy object.
|
||||
|
||||
```php
|
||||
s('fòôbàř')->getEncoding(); // 'UTF-8'
|
||||
s('fòôbàř', 'UTF-8')->getEncoding(); // 'UTF-8'
|
||||
```
|
||||
|
||||
##### hasLowerCase()
|
||||
@@ -810,19 +751,28 @@ random order.
|
||||
s('fòôbàř')->shuffle(); // 'àôřbòf'
|
||||
```
|
||||
|
||||
##### slugify([, string $replacement = '-' [, string $language = 'en']])
|
||||
##### slugify([, string $replacement = '-' ])
|
||||
|
||||
Converts the string into an URL slug. This includes replacing non-ASCII
|
||||
characters with their closest ASCII equivalents, removing remaining
|
||||
non-ASCII and non-alphanumeric characters, and replacing whitespace with
|
||||
$replacement. The replacement defaults to a single dash, and the string
|
||||
is also converted to lowercase. The language of the source string can
|
||||
also be supplied for language-specific transliteration.
|
||||
is also converted to lowercase.
|
||||
|
||||
```php
|
||||
s('Using strings like fòô bàř')->slugify(); // 'using-strings-like-foo-bar'
|
||||
```
|
||||
|
||||
##### startsWith(string $substring [, boolean $caseSensitive = true ])
|
||||
|
||||
Returns true if the string begins with $substring, false otherwise.
|
||||
By default, the comparison is case-sensitive, but can be made insensitive
|
||||
by setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
s('FÒÔbàřbaz')->startsWith('fòôbàř', false); // true
|
||||
```
|
||||
|
||||
##### slice(int $start [, int $end ])
|
||||
|
||||
Returns the substring beginning at $start, and up to, but not including
|
||||
@@ -844,36 +794,6 @@ results.
|
||||
s('foo,bar,baz')->split(',', 2); // ['foo', 'bar']
|
||||
```
|
||||
|
||||
##### startsWith(string $substring [, boolean $caseSensitive = true ])
|
||||
|
||||
Returns true if the string begins with $substring, false otherwise.
|
||||
By default, the comparison is case-sensitive, but can be made insensitive
|
||||
by setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
s('FÒÔbàřbaz')->startsWith('fòôbàř', false); // true
|
||||
```
|
||||
|
||||
##### startsWithAny(string[] $substrings [, boolean $caseSensitive = true ])
|
||||
|
||||
Returns true if the string begins with any of $substrings, false
|
||||
otherwise. By default the comparison is case-sensitive, but can be made
|
||||
insensitive by setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
s('FÒÔbàřbaz')->startsWithAny(['fòô', 'bàř'], false); // true
|
||||
```
|
||||
|
||||
##### stripWhitespace()
|
||||
|
||||
Strip all whitespace characters. This includes tabs and newline
|
||||
characters, as well as multibyte whitespace such as the thin space
|
||||
and ideographic space.
|
||||
|
||||
```php
|
||||
s(' Ο συγγραφέας ')->stripWhitespace(); // 'Οσυγγραφέας'
|
||||
```
|
||||
|
||||
##### substr(int $start [, int $length ])
|
||||
|
||||
Returns the substring beginning at $start with the specified $length.
|
||||
@@ -921,19 +841,14 @@ s('i like to watch television')->titleize($ignore);
|
||||
// 'I Like to Watch Television'
|
||||
```
|
||||
|
||||
##### toAscii([, string $language = 'en' [, bool $removeUnsupported = true ]])
|
||||
##### toAscii()
|
||||
|
||||
Returns an ASCII version of the string. A set of non-ASCII characters are
|
||||
replaced with their closest ASCII counterparts, and the rest are removed
|
||||
by default. The language or locale of the source string can be supplied
|
||||
for language-specific transliteration in any of the following formats:
|
||||
en, en_GB, or en-GB. For example, passing "de" results in "äöü" mapping
|
||||
to "aeoeue" rather than "aou" as in other languages.
|
||||
unless instructed otherwise.
|
||||
|
||||
```php
|
||||
s('fòôbàř')->toAscii(); // 'foobar'
|
||||
s('äöü')->toAscii(); // 'aou'
|
||||
s('äöü')->toAscii('de'); // 'aeoeue'
|
||||
```
|
||||
|
||||
##### toBoolean()
|
||||
|
@@ -15,7 +15,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"php": ">=5.3.0",
|
||||
"symfony/polyfill-mbstring": "~1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
|
@@ -16,14 +16,13 @@ use ReflectionMethod;
|
||||
* @method static string chars(string $str, string $encoding = null)
|
||||
* @method static string collapseWhitespace(string $str, string $encoding = null)
|
||||
* @method static bool contains(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static bool containsAll(string $str, string[] $needle, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static bool containsAny(string $str, string[] $needle, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static bool containsAll(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static bool containsAny(string $str, string $needle, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static int count(string $str, string $encoding = null)
|
||||
* @method static int countSubstr(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static string dasherize(string $str, string $encoding = null)
|
||||
* @method static string delimit(string $str, string $delimiter, string $encoding = null)
|
||||
* @method static bool endsWith(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static bool endsWithAny(string $str, string[] $substrings, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static string ensureLeft(string $str, string $substring, string $encoding = null)
|
||||
* @method static string ensureRight(string $str, string $substring, string $encoding = null)
|
||||
* @method static string first(string $str, int $n, string $encoding = null)
|
||||
@@ -46,7 +45,7 @@ use ReflectionMethod;
|
||||
* @method static bool isUpperCase(string $str, string $encoding = null)
|
||||
* @method static string last(string $str, string $encoding = null)
|
||||
* @method static int length(string $str, string $encoding = null)
|
||||
* @method static string[] lines(string $str, string $encoding = null)
|
||||
* @method static Stringy[] lines(string $str, string $encoding = null)
|
||||
* @method static string longestCommonPrefix(string $str, string $otherStr, string $encoding = null)
|
||||
* @method static string longestCommonSuffix(string $str, string $otherStr, string $encoding = null)
|
||||
* @method static string longestCommonSubstring(string $str, string $otherStr, string $encoding = null)
|
||||
@@ -65,17 +64,15 @@ use ReflectionMethod;
|
||||
* @method static string safeTruncate(string $str, int $length, string $substring = '', string $encoding = null)
|
||||
* @method static string shuffle(string $str, string $encoding = null)
|
||||
* @method static string slugify(string $str, string $replacement = '-', string $encoding = null)
|
||||
* @method static bool startsWith(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static string slice(string $str, int $start, int $end = null, string $encoding = null)
|
||||
* @method static string split(string $str, string $pattern, int $limit = null, string $encoding = null)
|
||||
* @method static bool startsWith(string $str, string $substring, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static bool startsWithAny(string $str, string[] $substrings, bool $caseSensitive = true, string $encoding = null)
|
||||
* @method static string stripWhitespace(string $str, string $encoding = null)
|
||||
* @method static string substr(string $str, int $start, int $length = null, string $encoding = null)
|
||||
* @method static string surround(string $str, string $substring, string $encoding = null)
|
||||
* @method static string swapCase(string $str, string $encoding = null)
|
||||
* @method static string tidy(string $str, string $encoding = null)
|
||||
* @method static string titleize(string $str, string $encoding = null)
|
||||
* @method static string toAscii(string $str, string $language = 'en', bool $removeUnsupported = true, string $encoding = null)
|
||||
* @method static string toAscii(string $str, bool $removeUnsupported = true, string $encoding = null)
|
||||
* @method static bool toBoolean(string $str, string $encoding = null)
|
||||
* @method static string toLowerCase(string $str, string $encoding = null)
|
||||
* @method static string toSpaces(string $str, int $tabLength = 4, string $encoding = null)
|
||||
@@ -146,16 +143,6 @@ class StaticStringy
|
||||
|
||||
$stringy = Stringy::create($str, $encoding);
|
||||
|
||||
$result = call_user_func_array([$stringy, $name], $args);
|
||||
|
||||
$cast = function($val) {
|
||||
if (is_object($val) && $val instanceof Stringy) {
|
||||
return (string) $val;
|
||||
} else {
|
||||
return $val;
|
||||
}
|
||||
};
|
||||
|
||||
return is_array($result) ? array_map($cast, $result) : $cast($result);
|
||||
return call_user_func_array(array($stringy, $name), $args);
|
||||
}
|
||||
}
|
||||
|
932
src/Stringy.php
932
src/Stringy.php
File diff suppressed because it is too large
Load Diff
@@ -15,38 +15,25 @@ class StaticStringyTestCase extends PHPUnit_Framework_TestCase
|
||||
public function testEmptyArgsInvocation()
|
||||
{
|
||||
$result = S::toLowerCase();
|
||||
$this->assertEquals('', $result);
|
||||
$this->assertEquals('', (string) $result);
|
||||
}
|
||||
|
||||
public function testInvocation()
|
||||
{
|
||||
$result = S::toLowerCase('FOOBAR');
|
||||
$this->assertEquals('foobar', $result);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals('foobar', (string) $result);
|
||||
}
|
||||
|
||||
public function testPartialArgsInvocation()
|
||||
{
|
||||
$result = S::slice('foobar', 0, 3);
|
||||
$this->assertEquals('foo', $result);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals('foo', (string) $result);
|
||||
}
|
||||
|
||||
public function testFullArgsInvocation()
|
||||
{
|
||||
$result = S::slice('fòôbàř', 0, 3, 'UTF-8');
|
||||
$this->assertEquals('fòô', $result);
|
||||
$this->assertInternalType('string', $result);
|
||||
}
|
||||
|
||||
public function testArrayReturnValue()
|
||||
{
|
||||
$result = S::lines("a\nb");
|
||||
$this->assertEquals(['a', 'b'], $result);
|
||||
$this->assertInternalType('array', $result);
|
||||
foreach ($result as $val) {
|
||||
$this->assertInternalType('string', $val);
|
||||
}
|
||||
$this->assertEquals('fòô', (string) $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user