mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-15 01:34:03 +02:00
Add some imports
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
namespace Stringy;
|
namespace Stringy;
|
||||||
|
|
||||||
|
use BadMethodCallException;
|
||||||
|
use ReflectionClass;
|
||||||
|
use ReflectionMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class StaticStringy
|
* Class StaticStringy
|
||||||
*
|
*
|
||||||
@@ -107,12 +111,14 @@ class StaticStringy
|
|||||||
* @param mixed[] $arguments
|
* @param mixed[] $arguments
|
||||||
*
|
*
|
||||||
* @return Stringy
|
* @return Stringy
|
||||||
|
*
|
||||||
|
* @throws \BadMethodCallException
|
||||||
*/
|
*/
|
||||||
public static function __callStatic($name, $arguments)
|
public static function __callStatic($name, $arguments)
|
||||||
{
|
{
|
||||||
if (!static::$methodArgs) {
|
if (!static::$methodArgs) {
|
||||||
$stringyClass = new \ReflectionClass('Stringy\Stringy');
|
$stringyClass = new ReflectionClass('Stringy\Stringy');
|
||||||
$methods = $stringyClass->getMethods(\ReflectionMethod::IS_PUBLIC);
|
$methods = $stringyClass->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||||
|
|
||||||
foreach ($methods as $method) {
|
foreach ($methods as $method) {
|
||||||
$params = $method->getNumberOfParameters() + 2;
|
$params = $method->getNumberOfParameters() + 2;
|
||||||
@@ -121,7 +127,7 @@ class StaticStringy
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset(static::$methodArgs[$name])) {
|
if (!isset(static::$methodArgs[$name])) {
|
||||||
throw new \BadMethodCallException($name . ' is not a valid method');
|
throw new BadMethodCallException($name . ' is not a valid method');
|
||||||
}
|
}
|
||||||
|
|
||||||
$numArgs = count($arguments);
|
$numArgs = count($arguments);
|
||||||
|
@@ -2,7 +2,15 @@
|
|||||||
|
|
||||||
namespace Stringy;
|
namespace Stringy;
|
||||||
|
|
||||||
class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
use ArrayAccess;
|
||||||
|
use ArrayIterator;
|
||||||
|
use Countable;
|
||||||
|
use Exception;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use IteratorAggregate;
|
||||||
|
use OutOfBoundsException;
|
||||||
|
|
||||||
|
class Stringy implements Countable, IteratorAggregate, ArrayAccess
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* An instance's string.
|
* An instance's string.
|
||||||
@@ -34,11 +42,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
|||||||
public function __construct($str = '', $encoding = null)
|
public function __construct($str = '', $encoding = null)
|
||||||
{
|
{
|
||||||
if (is_array($str)) {
|
if (is_array($str)) {
|
||||||
throw new \InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'Passed value cannot be an array'
|
'Passed value cannot be an array'
|
||||||
);
|
);
|
||||||
} elseif (is_object($str) && !method_exists($str, '__toString')) {
|
} elseif (is_object($str) && !method_exists($str, '__toString')) {
|
||||||
throw new \InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'Passed object must have a __toString method'
|
'Passed object must have a __toString method'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -421,7 +429,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
|||||||
*/
|
*/
|
||||||
public function getIterator()
|
public function getIterator()
|
||||||
{
|
{
|
||||||
return new \ArrayIterator($this->chars());
|
return new ArrayIterator($this->chars());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -846,7 +854,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
|||||||
$length = $this->length();
|
$length = $this->length();
|
||||||
|
|
||||||
if (($offset >= 0 && $length <= $offset) || $length < abs($offset)) {
|
if (($offset >= 0 && $length <= $offset) || $length < abs($offset)) {
|
||||||
throw new \OutOfBoundsException('No character exists at the index');
|
throw new OutOfBoundsException('No character exists at the index');
|
||||||
}
|
}
|
||||||
|
|
||||||
return mb_substr($this->str, $offset, 1, $this->encoding);
|
return mb_substr($this->str, $offset, 1, $this->encoding);
|
||||||
@@ -863,7 +871,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
|||||||
public function offsetSet($offset, $value)
|
public function offsetSet($offset, $value)
|
||||||
{
|
{
|
||||||
// Stringy is immutable, cannot directly set char
|
// Stringy is immutable, cannot directly set char
|
||||||
throw new \Exception('Stringy object is immutable, cannot modify char');
|
throw new Exception('Stringy object is immutable, cannot modify char');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -876,7 +884,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
|||||||
public function offsetUnset($offset)
|
public function offsetUnset($offset)
|
||||||
{
|
{
|
||||||
// Don't allow directly modifying the string
|
// Don't allow directly modifying the string
|
||||||
throw new \Exception('Stringy object is immutable, cannot unset char');
|
throw new Exception('Stringy object is immutable, cannot unset char');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -896,7 +904,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
|||||||
public function pad($length, $padStr = ' ', $padType = 'right')
|
public function pad($length, $padStr = ' ', $padType = 'right')
|
||||||
{
|
{
|
||||||
if (!in_array($padType, array('left', 'right', 'both'))) {
|
if (!in_array($padType, array('left', 'right', 'both'))) {
|
||||||
throw new \InvalidArgumentException('Pad expects $padType ' .
|
throw new InvalidArgumentException('Pad expects $padType ' .
|
||||||
"to be one of 'left', 'right' or 'both'");
|
"to be one of 'left', 'right' or 'both'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user