From 571cf8f78fb1d202d8379c6058782d384cd9f3c7 Mon Sep 17 00:00:00 2001 From: "Daniel St. Jules" Date: Thu, 25 Jul 2013 23:02:34 -0400 Subject: [PATCH] Update readmewith OO/Procedural info, fix instances where is called instead of ->str --- README.md | 23 +++++++++++++++++++++-- src/Stringy/Stringy.php | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 231559e..7656be7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Stringy -A PHP library with a variety of string manipulation functions with multibyte support. It contains both an OO and Static wrapper. Inspired by underscore.string.js. +A PHP library with a variety of string manipulation functions with multibyte support. Offers both OO method chaining and a procedural-style static wrapper. Inspired by underscore.string.js. Note: The methods listed below are subject to change until we reach a 1.0.0 release. @@ -70,7 +70,26 @@ use Stringy\StaticStringy as S; ## OO & Procedural -Documentation coming soon. +The library offers both OO method chaining with `Stringy\Stringy`, as well as +procedural-style static method calls with `Stringy\StaticStringy`. An example +of the former is the following: + +```php +use Stringy\Stringy as S; +echo S::create("Fòô Bàř", 'UTF-8')->collapseWhitespace()->swapCase(); // 'fÒÔ bÀŘ' +``` + +`Stringy\Stringy` contains a __toString() method, which returns the current +string when the object is used in a string context. Its $str property is also +public, and can be accessed directly if required, ie: `S::create('foo')->str // 'foo'` + +Using the static wrapper, an alternative is the following: + +```php +use Stringy\StaticStringy as S; +$string = S::collapseWhitespace("Fòô Bàř", 'UTF-8'); +echo S::swapCase($string, 'UTF-8'); // 'fÒÔ bÀŘ'' +``` ## Methods diff --git a/src/Stringy/Stringy.php b/src/Stringy/Stringy.php index f69af7e..f20e82a 100644 --- a/src/Stringy/Stringy.php +++ b/src/Stringy/Stringy.php @@ -176,7 +176,7 @@ class Stringy else return mb_strtoupper($match[0], $encoding); }, - $this + $this->str ); return $this; @@ -204,7 +204,7 @@ class Stringy $that->str = $match[0]; return $that->upperCaseFirst(); }, - $this->trim() + $this->trim()->str ); return $this;