mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-12 08:14:06 +02:00
Update create() and added __construct()
This commit is contained in:
@@ -8,6 +8,20 @@ class Stringy
|
|||||||
|
|
||||||
public $encoding;
|
public $encoding;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inializes a Stringy object and assigns both str and encoding properties
|
||||||
|
* the supplied values. If $encoding is not specified, it defaults to
|
||||||
|
* mb_internal_encoding().
|
||||||
|
*
|
||||||
|
* @param string $str String to modify
|
||||||
|
* @param string $encoding The character encoding
|
||||||
|
*/
|
||||||
|
public function __construct($str, $encoding = null)
|
||||||
|
{
|
||||||
|
$this->str = $str;
|
||||||
|
$this->encoding = $encoding ?: mb_internal_encoding();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Stringy object and assigns both str and encoding properties
|
* Creates a Stringy object and assigns both str and encoding properties
|
||||||
* the supplied values. If $encoding is not specified, it defaults to
|
* the supplied values. If $encoding is not specified, it defaults to
|
||||||
@@ -19,13 +33,7 @@ class Stringy
|
|||||||
*/
|
*/
|
||||||
public static function create($str, $encoding = null)
|
public static function create($str, $encoding = null)
|
||||||
{
|
{
|
||||||
$encoding = $encoding ?: mb_internal_encoding();
|
return new static($str, $encoding);
|
||||||
|
|
||||||
$stringyObj = new self();
|
|
||||||
$stringyObj->str = $str;
|
|
||||||
$stringyObj->encoding = $encoding;
|
|
||||||
|
|
||||||
return $stringyObj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user