mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-12 00:04:11 +02:00
Added isBase64 method
This commit is contained in:
committed by
Daniel St. Jules
parent
f086c67ac7
commit
318db789b1
10
README.md
10
README.md
@@ -46,6 +46,7 @@ s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
|
|||||||
* [insert](#insertint-index-string-substring)
|
* [insert](#insertint-index-string-substring)
|
||||||
* [isAlpha](#isalpha)
|
* [isAlpha](#isalpha)
|
||||||
* [isAlphanumeric](#isalphanumeric)
|
* [isAlphanumeric](#isalphanumeric)
|
||||||
|
* [isBase64](#isbase64)
|
||||||
* [isBlank](#isblank)
|
* [isBlank](#isblank)
|
||||||
* [isHexadecimal](#ishexadecimal)
|
* [isHexadecimal](#ishexadecimal)
|
||||||
* [isJson](#isjson)
|
* [isJson](#isjson)
|
||||||
@@ -509,6 +510,15 @@ otherwise.
|
|||||||
s('دانيال1')->isAlphanumeric(); // true
|
s('دانيال1')->isAlphanumeric(); // true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### isBase64()
|
||||||
|
|
||||||
|
Returns true if the string is base64 encoded, false
|
||||||
|
otherwise.
|
||||||
|
|
||||||
|
```php
|
||||||
|
s('Zm9vYmFy')->isBase64(); // true
|
||||||
|
```
|
||||||
|
|
||||||
##### isBlank()
|
##### isBlank()
|
||||||
|
|
||||||
Returns true if the string contains only whitespace chars, false otherwise.
|
Returns true if the string contains only whitespace chars, false otherwise.
|
||||||
|
@@ -627,6 +627,17 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
|||||||
return $this->str === 'b:0;' || @unserialize($this->str) !== false;
|
return $this->str === 'b:0;' || @unserialize($this->str) !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the string is base64 encoded, false otherwise.
|
||||||
|
*
|
||||||
|
* @return bool Whether or not $str is base64 encoded
|
||||||
|
*/
|
||||||
|
public function isBase64()
|
||||||
|
{
|
||||||
|
return $this->str !== '' && ( base64_encode( base64_decode( $this->str, true ) ) === $this->str );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the string contains only lower case chars, false
|
* Returns true if the string contains only lower case chars, false
|
||||||
* otherwise.
|
* otherwise.
|
||||||
|
@@ -2170,6 +2170,31 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider isBase64Provider()
|
||||||
|
*/
|
||||||
|
public function testIsBase64($expected, $str)
|
||||||
|
{
|
||||||
|
$stringy = S::create($str);
|
||||||
|
$result = $stringy->isBase64();
|
||||||
|
$this->assertInternalType('boolean', $result);
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
$this->assertEquals($str, $stringy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isBase64Provider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(false, ' '),
|
||||||
|
array(false, ''),
|
||||||
|
array(true, base64_encode('FooBar') ),
|
||||||
|
array(true, base64_encode(' ') ),
|
||||||
|
array(true, base64_encode('FÒÔBÀŘ') ),
|
||||||
|
array(true, base64_encode('συγγραφέας') ),
|
||||||
|
array(false, 'Foobar'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider isUpperCaseProvider()
|
* @dataProvider isUpperCaseProvider()
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user