This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide new function names, according to changes to the RFC
- Loading branch information
Showing
29 changed files
with
966 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* This file is part of the ramsey/str-begins-ends library | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
*/ | ||
|
||
namespace Ramsey\String; | ||
|
||
abstract class AbstractString implements StringInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $value; | ||
|
||
/** | ||
* @param string $value | ||
*/ | ||
public function __construct($value) | ||
{ | ||
$this->value = $this->checkString($value, 1); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return (string) $this->value; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* @param int $position | ||
* @return StringValue | ||
*/ | ||
protected function checkString($value, $position) | ||
{ | ||
if (is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) { | ||
return strval($value); | ||
} | ||
|
||
throw new InvalidStringArgumentException($value, $position); | ||
} | ||
} |
Oops, something went wrong.