1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-09 14:56:31 +02:00

Made str and encoding protected, added getEncoding

Neither should be private, so as to allow users to easily extend the
class
This commit is contained in:
Daniel St. Jules
2014-02-16 21:22:32 -05:00
parent e5f66c6eca
commit 1965da2e39
3 changed files with 25 additions and 4 deletions

View File

@@ -22,6 +22,7 @@ Compatible with PHP 5.3+. Inspired by underscore.string.js.
* [ensureLeft](#ensureleft)
* [ensureRight](#ensureright)
* [first](#first)
* [getEncoding](#getencoding)
* [humanize](#humanize)
* [insert](#insert)
* [isAlpha](#isalpha)
@@ -340,6 +341,16 @@ S::create('fòô bàř', 'UTF-8')->first(3);
S::first('fòô bàř', 3, 'UTF-8'); // 'fòô'
```
#### getEncoding
$stringy->getEncoding()
Returns the encoding used by the Stringy object.
```php
S::create('fòô bàř', 'UTF-8')->getEncoding(); // 'UTF-8'
```
#### humanize
$stringy->humanize()

View File

@@ -4,9 +4,9 @@ namespace Stringy;
class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{
private $str;
protected $str;
public $encoding;
protected $encoding;
/**
* Initializes a Stringy object and assigns both str and encoding properties
@@ -64,6 +64,16 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
return $this->str;
}
/**
* Returns the encoding used by the Stringy object.
*
* @return string The current value of the $encoding property
*/
public function getEncoding()
{
return $this->encoding;
}
/**
* Returns the length of the string, implementing the countable interface.
*

View File

@@ -12,7 +12,7 @@ class StringyTestCase extends CommonTest
$stringy = new S('foo bar', 'UTF-8');
$this->assertInstanceOf('Stringy\Stringy', $stringy);
$this->assertEquals('foo bar', (string) $stringy);
$this->assertEquals('UTF-8', $stringy->encoding);
$this->assertEquals('UTF-8', $stringy->getEncoding());
}
/**
@@ -59,7 +59,7 @@ class StringyTestCase extends CommonTest
$stringy = S::create('foo bar', 'UTF-8');
$this->assertInstanceOf('Stringy\Stringy', $stringy);
$this->assertEquals('foo bar', (string) $stringy);
$this->assertEquals('UTF-8', $stringy->encoding);
$this->assertEquals('UTF-8', $stringy->getEncoding());
}
public function testChaining()