mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-09-02 01:22:37 +02:00
Compare commits
52 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2288363663 | ||
|
f22117862b | ||
|
eb13cc35d6 | ||
|
9b6bddcb20 | ||
|
67f16c9423 | ||
|
3708b6ba90 | ||
|
5c50a58bb8 | ||
|
8b59cd2233 | ||
|
63d81901ad | ||
|
a2624d4969 | ||
|
72102ae911 | ||
|
bf2a302aa1 | ||
|
5303203a72 | ||
|
e01ba7f848 | ||
|
f9f3b7f2f2 | ||
|
75b0cd2e0d | ||
|
b0976c72b7 | ||
|
edbda419cb | ||
|
e8afcffc7c | ||
|
986260239d | ||
|
841600867d | ||
|
845e8d693d | ||
|
b35270671c | ||
|
0aab4361bf | ||
|
df777da6ac | ||
|
ded4d41d44 | ||
|
569736327a | ||
|
6f2e2851ac | ||
|
553bf37acb | ||
|
916f79221e | ||
|
d71d4f0ad6 | ||
|
de93eab01f | ||
|
9b6404d5c3 | ||
|
27a4f11f2e | ||
|
46de78bda9 | ||
|
cb14fc2e6b | ||
|
090a15f2fd | ||
|
d80347e72a | ||
|
0491ed8db8 | ||
|
eb445b55ef | ||
|
91b153d30e | ||
|
9ebdf88b71 | ||
|
0607751e17 | ||
|
6507f0ac44 | ||
|
4e214a5195 | ||
|
fcc2969210 | ||
|
30d1742082 | ||
|
bd90918858 | ||
|
a2d1ec535a | ||
|
b953a85d2c | ||
|
e07a07a076 | ||
|
c4d785d29f |
@@ -10,10 +10,6 @@ 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
|
||||
|
33
CHANGELOG.md
33
CHANGELOG.md
@@ -1,4 +1,35 @@
|
||||
### 2.3.0 (2015-03-19)
|
||||
### 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()
|
||||
* Use symfony/polyfill-mbstring to avoid dependency on ext-mbstring
|
||||
|
281
README.md
281
README.md
@@ -1,13 +1,16 @@
|
||||

|
||||
|
||||
A PHP string manipulation library with multibyte support. Compatible with PHP
|
||||
5.3+, PHP 7, and HHVM. Refer to the [1.x branch](https://github.com/danielstjules/Stringy/tree/1.x)
|
||||
for older documentation.
|
||||
5.4+, PHP 7, and HHVM.
|
||||
|
||||
``` 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)
|
||||
@@ -21,83 +24,129 @@ s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
|
||||
* [Class methods](#class-methods)
|
||||
* [create](#createmixed-str--encoding-)
|
||||
* [Instance methods](#instance-methods)
|
||||
* [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)
|
||||
<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----">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>
|
||||
|
||||
* [Extensions](#extensions)
|
||||
* [Tests](#tests)
|
||||
* [License](#license)
|
||||
@@ -131,7 +180,7 @@ in your composer.json file:
|
||||
|
||||
```json
|
||||
"require": {
|
||||
"danielstjules/stringy": "~2.3"
|
||||
"danielstjules/stringy": "~3.0.1"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -239,9 +288,9 @@ integer, boolean, etc.
|
||||
```php
|
||||
use Stringy\StaticStringy as S;
|
||||
|
||||
// Translates to Stringy::create('fòôbàř', 'UTF-8')->slice(0, 3);
|
||||
// Translates to Stringy::create('fòôbàř')->slice(0, 3);
|
||||
// Returns a Stringy object with the string "fòô"
|
||||
S::slice('fòôbàř', 0, 3, 'UTF-8');
|
||||
S::slice('fòôbàř', 0, 3);
|
||||
```
|
||||
|
||||
## Class methods
|
||||
@@ -255,7 +304,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àř', 'UTF-8'); // 'fòôbàř'
|
||||
$stringy = S::create('fòôbàř'); // 'fòôbàř'
|
||||
```
|
||||
|
||||
## Instance Methods
|
||||
@@ -388,7 +437,17 @@ default, the comparison is case-sensitive, but can be made insensitive by
|
||||
setting $caseSensitive to false.
|
||||
|
||||
```php
|
||||
s('fòôbàř')->endsWith('bàř', true); // true
|
||||
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
|
||||
```
|
||||
|
||||
##### ensureLeft(string $substring)
|
||||
@@ -420,7 +479,7 @@ s('fòôbàř')->first(3); // 'fòô'
|
||||
Returns the encoding used by the Stringy object.
|
||||
|
||||
```php
|
||||
s('fòôbàř', 'UTF-8')->getEncoding(); // 'UTF-8'
|
||||
s('fòôbàř')->getEncoding(); // 'UTF-8'
|
||||
```
|
||||
|
||||
##### hasLowerCase()
|
||||
@@ -686,7 +745,8 @@ to a lack of support in the bundled version of Oniguruma in PHP < 5.6,
|
||||
and current versions of HHVM (3.8 and below).
|
||||
|
||||
```php
|
||||
s('fòô ')->regexReplace('f[òô]+\s', 'bàř', 'msr'); // 'bàř'
|
||||
s('fòô ')->regexReplace('f[òô]+\s', 'bàř'); // 'bàř'
|
||||
s('fò')->regexReplace('(ò)', '\\1ô'); // 'fòô'
|
||||
```
|
||||
|
||||
##### removeLeft(string $substring)
|
||||
@@ -762,16 +822,6 @@ is also converted to lowercase.
|
||||
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
|
||||
@@ -793,6 +843,36 @@ 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.
|
||||
@@ -840,14 +920,19 @@ s('i like to watch television')->titleize($ignore);
|
||||
// 'I Like to Watch Television'
|
||||
```
|
||||
|
||||
##### toAscii()
|
||||
##### toAscii([, string $language = 'en' [, bool $removeUnsupported = true ]])
|
||||
|
||||
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
|
||||
unless instructed otherwise.
|
||||
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.
|
||||
|
||||
```php
|
||||
s('fòôbàř')->toAscii(); // 'foobar'
|
||||
s('äöü')->toAscii(); // 'aou'
|
||||
s('äöü')->toAscii('de'); // 'aeoeue'
|
||||
```
|
||||
|
||||
##### toBoolean()
|
||||
|
@@ -15,7 +15,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"php": ">=5.4.0",
|
||||
"symfony/polyfill-mbstring": "~1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
|
@@ -16,13 +16,14 @@ 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)
|
||||
@@ -45,7 +46,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 Stringy[] lines(string $str, string $encoding = null)
|
||||
* @method static string[] 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)
|
||||
@@ -64,15 +65,17 @@ 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, bool $removeUnsupported = true, string $encoding = null)
|
||||
* @method static string toAscii(string $str, string $language = 'en', 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)
|
||||
@@ -143,6 +146,16 @@ class StaticStringy
|
||||
|
||||
$stringy = Stringy::create($str, $encoding);
|
||||
|
||||
return call_user_func_array(array($stringy, $name), $args);
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
920
src/Stringy.php
920
src/Stringy.php
File diff suppressed because it is too large
Load Diff
@@ -15,25 +15,38 @@ class StaticStringyTestCase extends PHPUnit_Framework_TestCase
|
||||
public function testEmptyArgsInvocation()
|
||||
{
|
||||
$result = S::toLowerCase();
|
||||
$this->assertEquals('', (string) $result);
|
||||
$this->assertEquals('', $result);
|
||||
}
|
||||
|
||||
public function testInvocation()
|
||||
{
|
||||
$result = S::toLowerCase('FOOBAR');
|
||||
$this->assertEquals('foobar', (string) $result);
|
||||
$this->assertEquals('foobar', $result);
|
||||
$this->assertInternalType('string', $result);
|
||||
}
|
||||
|
||||
public function testPartialArgsInvocation()
|
||||
{
|
||||
$result = S::slice('foobar', 0, 3);
|
||||
$this->assertEquals('foo', (string) $result);
|
||||
$this->assertEquals('foo', $result);
|
||||
$this->assertInternalType('string', $result);
|
||||
}
|
||||
|
||||
public function testFullArgsInvocation()
|
||||
{
|
||||
$result = S::slice('fòôbàř', 0, 3, 'UTF-8');
|
||||
$this->assertEquals('fòô', (string) $result);
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user