1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-09-01 09:03:03 +02:00

8 Commits
1.7.0 ... 1.8.0

Author SHA1 Message Date
Daniel St. Jules
d661047fb3 1.8.0 2015-01-03 22:54:13 -08:00
Daniel St. Jules
26fe399396 Merge pull request #58 from GrahamCampbell/patch-1
Remove duplicate dependencies from autoload-dev
2015-01-03 19:26:38 -05:00
Daniel St. Jules
31c4ba145f Merge pull request #57 from vlakoff/dependency
Add ext-mbstring to composer.json
2015-01-03 19:25:41 -05:00
Graham Campbell
5a1be9bf20 autoload-dev behave the same as require-dev 2015-01-03 22:55:35 +00:00
vlakoff
28c3db01c5 Add ext-mbstring to composer.json 2015-01-03 23:20:21 +01:00
Daniel St. Jules
27ef5a8914 Add Stringy\create function for PHP 5.6 2015-01-01 21:40:48 -08:00
Daniel St. Jules
350d1e6f8e Merge pull request #56 from GrahamCampbell/patch-1
Tweaked the test config
2014-10-26 07:47:54 -07:00
Graham Campbell
ce58c93fc2 Tweaked the test config 2014-10-26 12:44:18 +00:00
6 changed files with 65 additions and 4 deletions

View File

@@ -1,3 +1,8 @@
### 1.8.0 (2015-01-03)
* Listed ext-mbstring in composer.json
* Added Stringy\create function for PHP 5.6
### 1.7.0 (2014-10-14)
* Added containsAll and containsAny

View File

@@ -9,6 +9,7 @@ PHP 5.3+ and HHVM. Inspired by underscore.string.js.
* [Requiring/Loading](#requiringloading)
* [OO and Procedural](#oo-and-procedural)
* [Implemented Interfaces](#implemented-interfaces)
* [PHP 5.6 Creation](#php-56-creation)
* [Methods](#methods)
* [at](#at)
* [camelize](#camelize)
@@ -82,7 +83,7 @@ in your composer.json file:
```json
{
"require": {
"danielstjules/stringy": "~1.7"
"danielstjules/stringy": "~1.8"
}
}
```
@@ -171,6 +172,21 @@ $stringy[3]; // OutOfBoundsException
$stringy[2] = 'a'; // Exception
```
## PHP 5.6 Creation
As of PHP 5.6, [`use function`](https://wiki.php.net/rfc/use_function) is
available for importing functions. Stringy exposes a namespaced function,
`Stringy\create`, which emits the same behaviour as `Stringy\Stringy::create()`.
If running PHP 5.6, or another runtime that supports the `use function` syntax,
you can take advantage of an even simpler API as seen below:
``` php
use function Stringy\create as s;
// Instead of: S::create('Fòô Bàř', 'UTF-8')
s('Fòô Bàř', 'UTF-8')->collapseWhitespace()->swapCase();
```
## Methods
In the list below, any static method other than S::create refers to a method in

View File

@@ -15,10 +15,11 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=5.3.0",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "4.0.*"
"phpunit/phpunit": "~4.0"
},
"support": {
"issues": "https://github.com/danielstjules/Stringy/issues",
@@ -26,6 +27,9 @@
},
"autoload": {
"psr-4": { "Stringy\\": "src/" },
"files": ["src/Create.php"]
},
"autoload-dev": {
"classmap": [ "tests" ]
}
}

View File

@@ -5,7 +5,10 @@
syntaxCheck="false">
<testsuites>
<testsuite name="Stringy">
<directory>tests</directory>
<file>tests/CommonTest.php</file>
<file>tests/StringyTest.php</file>
<file>tests/StaticStringyTest.php</file>
<file phpVersion="5.6.0">tests/CreateTest.php</file>
</testsuite>
</testsuites>
</phpunit>

17
src/Create.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
namespace Stringy;
/**
* Invokes Stringy::create and returns the generated Stringy object on success.
*
* @param mixed $str Value to modify, after being cast to string
* @param string $encoding The character encoding
* @return Stringy A Stringy object
* @throws \InvalidArgumentException if an array or object without a
* __toString method is passed as the first argument
*/
function create($str, $encoding = null)
{
return new Stringy($str, $encoding);
}

16
tests/CreateTest.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
require __DIR__ . '/../src/Create.php';
use function Stringy\create as s;
class CreateTestCase extends PHPUnit_Framework_TestCase
{
public function testCreate()
{
$stringy = s('foo bar', 'UTF-8');
$this->assertInstanceOf('Stringy\Stringy', $stringy);
$this->assertEquals('foo bar', (string) $stringy);
$this->assertEquals('UTF-8', $stringy->getEncoding());
}
}