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:
11
README.md
11
README.md
@@ -22,6 +22,7 @@ Compatible with PHP 5.3+. Inspired by underscore.string.js.
|
|||||||
* [ensureLeft](#ensureleft)
|
* [ensureLeft](#ensureleft)
|
||||||
* [ensureRight](#ensureright)
|
* [ensureRight](#ensureright)
|
||||||
* [first](#first)
|
* [first](#first)
|
||||||
|
* [getEncoding](#getencoding)
|
||||||
* [humanize](#humanize)
|
* [humanize](#humanize)
|
||||||
* [insert](#insert)
|
* [insert](#insert)
|
||||||
* [isAlpha](#isalpha)
|
* [isAlpha](#isalpha)
|
||||||
@@ -340,6 +341,16 @@ S::create('fòô bàř', 'UTF-8')->first(3);
|
|||||||
S::first('fòô bàř', 3, 'UTF-8'); // 'fòô'
|
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
|
#### humanize
|
||||||
|
|
||||||
$stringy->humanize()
|
$stringy->humanize()
|
||||||
|
@@ -4,9 +4,9 @@ namespace Stringy;
|
|||||||
|
|
||||||
class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
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
|
* Initializes a Stringy object and assigns both str and encoding properties
|
||||||
@@ -64,6 +64,16 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
|||||||
return $this->str;
|
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.
|
* Returns the length of the string, implementing the countable interface.
|
||||||
*
|
*
|
||||||
|
@@ -12,7 +12,7 @@ class StringyTestCase extends CommonTest
|
|||||||
$stringy = new S('foo bar', 'UTF-8');
|
$stringy = new S('foo bar', 'UTF-8');
|
||||||
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||||
$this->assertEquals('foo bar', (string) $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');
|
$stringy = S::create('foo bar', 'UTF-8');
|
||||||
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
$this->assertInstanceOf('Stringy\Stringy', $stringy);
|
||||||
$this->assertEquals('foo bar', (string) $stringy);
|
$this->assertEquals('foo bar', (string) $stringy);
|
||||||
$this->assertEquals('UTF-8', $stringy->encoding);
|
$this->assertEquals('UTF-8', $stringy->getEncoding());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testChaining()
|
public function testChaining()
|
||||||
|
Reference in New Issue
Block a user