Deprecated IString.

This commit is contained in:
Pachira 2023-11-09 12:58:04 +00:00
parent 82a350a5c7
commit 1c2058e199
15 changed files with 126 additions and 167 deletions

View file

@ -1 +1 @@
0.2309.152244
0.2311.91257

137
composer.lock generated
View file

@ -68,16 +68,16 @@
},
{
"name": "nikic/php-parser",
"version": "v4.16.0",
"version": "v4.17.1",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "19526a33fb561ef417e822e85f08a00db4059c17"
"reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/19526a33fb561ef417e822e85f08a00db4059c17",
"reference": "19526a33fb561ef417e822e85f08a00db4059c17",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d",
"reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d",
"shasum": ""
},
"require": {
@ -118,9 +118,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v4.16.0"
"source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1"
},
"time": "2023-06-25T14:52:30+00:00"
"time": "2023-08-13T19:53:39+00:00"
},
{
"name": "phar-io/manifest",
@ -235,16 +235,16 @@
},
{
"name": "phpstan/phpstan",
"version": "1.10.26",
"version": "1.10.41",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "5d660cbb7e1b89253a47147ae44044f49832351f"
"reference": "c6174523c2a69231df55bdc65b61655e72876d76"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/5d660cbb7e1b89253a47147ae44044f49832351f",
"reference": "5d660cbb7e1b89253a47147ae44044f49832351f",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/c6174523c2a69231df55bdc65b61655e72876d76",
"reference": "c6174523c2a69231df55bdc65b61655e72876d76",
"shasum": ""
},
"require": {
@ -293,20 +293,20 @@
"type": "tidelift"
}
],
"time": "2023-07-19T12:44:37+00:00"
"time": "2023-11-05T12:57:57+00:00"
},
{
"name": "phpunit/php-code-coverage",
"version": "10.1.2",
"version": "10.1.7",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "db1497ec8dd382e82c962f7abbe0320e4882ee4e"
"reference": "355324ca4980b8916c18b9db29f3ef484078f26e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/db1497ec8dd382e82c962f7abbe0320e4882ee4e",
"reference": "db1497ec8dd382e82c962f7abbe0320e4882ee4e",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/355324ca4980b8916c18b9db29f3ef484078f26e",
"reference": "355324ca4980b8916c18b9db29f3ef484078f26e",
"shasum": ""
},
"require": {
@ -363,7 +363,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.2"
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.7"
},
"funding": [
{
@ -371,20 +371,20 @@
"type": "github"
}
],
"time": "2023-05-22T09:04:27+00:00"
"time": "2023-10-04T15:34:17+00:00"
},
{
"name": "phpunit/php-file-iterator",
"version": "4.0.2",
"version": "4.1.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "5647d65443818959172645e7ed999217360654b6"
"reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/5647d65443818959172645e7ed999217360654b6",
"reference": "5647d65443818959172645e7ed999217360654b6",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a95037b6d9e608ba092da1b23931e537cadc3c3c",
"reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c",
"shasum": ""
},
"require": {
@ -424,7 +424,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
"security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy",
"source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.0.2"
"source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.1.0"
},
"funding": [
{
@ -432,7 +432,7 @@
"type": "github"
}
],
"time": "2023-05-07T09:13:23+00:00"
"time": "2023-08-31T06:24:48+00:00"
},
{
"name": "phpunit/php-invoker",
@ -499,16 +499,16 @@
},
{
"name": "phpunit/php-text-template",
"version": "3.0.0",
"version": "3.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-text-template.git",
"reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d"
"reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/9f3d3709577a527025f55bcf0f7ab8052c8bb37d",
"reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d",
"url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c7b06ff49e3d5072f057eb1fa59258bf287a748",
"reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748",
"shasum": ""
},
"require": {
@ -546,7 +546,8 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-text-template/issues",
"source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.0"
"security": "https://github.com/sebastianbergmann/php-text-template/security/policy",
"source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.1"
},
"funding": [
{
@ -554,7 +555,7 @@
"type": "github"
}
],
"time": "2023-02-03T06:56:46+00:00"
"time": "2023-08-31T14:07:24+00:00"
},
{
"name": "phpunit/php-timer",
@ -617,16 +618,16 @@
},
{
"name": "phpunit/phpunit",
"version": "10.2.6",
"version": "10.4.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "1c17815c129f133f3019cc18e8d0c8622e6d9bcd"
"reference": "cacd8b9dd224efa8eb28beb69004126c7ca1a1a1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1c17815c129f133f3019cc18e8d0c8622e6d9bcd",
"reference": "1c17815c129f133f3019cc18e8d0c8622e6d9bcd",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/cacd8b9dd224efa8eb28beb69004126c7ca1a1a1",
"reference": "cacd8b9dd224efa8eb28beb69004126c7ca1a1a1",
"shasum": ""
},
"require": {
@ -640,7 +641,7 @@
"phar-io/manifest": "^2.0.3",
"phar-io/version": "^3.0.2",
"php": ">=8.1",
"phpunit/php-code-coverage": "^10.1.1",
"phpunit/php-code-coverage": "^10.1.5",
"phpunit/php-file-iterator": "^4.0",
"phpunit/php-invoker": "^4.0",
"phpunit/php-text-template": "^3.0",
@ -650,8 +651,8 @@
"sebastian/comparator": "^5.0",
"sebastian/diff": "^5.0",
"sebastian/environment": "^6.0",
"sebastian/exporter": "^5.0",
"sebastian/global-state": "^6.0",
"sebastian/exporter": "^5.1",
"sebastian/global-state": "^6.0.1",
"sebastian/object-enumerator": "^5.0",
"sebastian/recursion-context": "^5.0",
"sebastian/type": "^4.0",
@ -666,7 +667,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "10.2-dev"
"dev-main": "10.4-dev"
}
},
"autoload": {
@ -698,7 +699,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.6"
"source": "https://github.com/sebastianbergmann/phpunit/tree/10.4.2"
},
"funding": [
{
@ -714,7 +715,7 @@
"type": "tidelift"
}
],
"time": "2023-07-17T12:08:28+00:00"
"time": "2023-10-26T07:21:45+00:00"
},
{
"name": "sebastian/cli-parser",
@ -885,16 +886,16 @@
},
{
"name": "sebastian/comparator",
"version": "5.0.0",
"version": "5.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "72f01e6586e0caf6af81297897bd112eb7e9627c"
"reference": "2db5010a484d53ebf536087a70b4a5423c102372"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/72f01e6586e0caf6af81297897bd112eb7e9627c",
"reference": "72f01e6586e0caf6af81297897bd112eb7e9627c",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2db5010a484d53ebf536087a70b4a5423c102372",
"reference": "2db5010a484d53ebf536087a70b4a5423c102372",
"shasum": ""
},
"require": {
@ -905,7 +906,7 @@
"sebastian/exporter": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "^10.0"
"phpunit/phpunit": "^10.3"
},
"type": "library",
"extra": {
@ -949,7 +950,8 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/comparator/issues",
"source": "https://github.com/sebastianbergmann/comparator/tree/5.0.0"
"security": "https://github.com/sebastianbergmann/comparator/security/policy",
"source": "https://github.com/sebastianbergmann/comparator/tree/5.0.1"
},
"funding": [
{
@ -957,20 +959,20 @@
"type": "github"
}
],
"time": "2023-02-03T07:07:16+00:00"
"time": "2023-08-14T13:18:12+00:00"
},
{
"name": "sebastian/complexity",
"version": "3.0.0",
"version": "3.1.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/complexity.git",
"reference": "e67d240970c9dc7ea7b2123a6d520e334dd61dc6"
"reference": "68cfb347a44871f01e33ab0ef8215966432f6957"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/e67d240970c9dc7ea7b2123a6d520e334dd61dc6",
"reference": "e67d240970c9dc7ea7b2123a6d520e334dd61dc6",
"url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/68cfb347a44871f01e33ab0ef8215966432f6957",
"reference": "68cfb347a44871f01e33ab0ef8215966432f6957",
"shasum": ""
},
"require": {
@ -983,7 +985,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "3.0-dev"
"dev-main": "3.1-dev"
}
},
"autoload": {
@ -1006,7 +1008,8 @@
"homepage": "https://github.com/sebastianbergmann/complexity",
"support": {
"issues": "https://github.com/sebastianbergmann/complexity/issues",
"source": "https://github.com/sebastianbergmann/complexity/tree/3.0.0"
"security": "https://github.com/sebastianbergmann/complexity/security/policy",
"source": "https://github.com/sebastianbergmann/complexity/tree/3.1.0"
},
"funding": [
{
@ -1014,7 +1017,7 @@
"type": "github"
}
],
"time": "2023-02-03T06:59:47+00:00"
"time": "2023-09-28T11:50:59+00:00"
},
{
"name": "sebastian/diff",
@ -1149,16 +1152,16 @@
},
{
"name": "sebastian/exporter",
"version": "5.0.0",
"version": "5.1.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
"reference": "f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0"
"reference": "64f51654862e0f5e318db7e9dcc2292c63cdbddc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0",
"reference": "f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/64f51654862e0f5e318db7e9dcc2292c63cdbddc",
"reference": "64f51654862e0f5e318db7e9dcc2292c63cdbddc",
"shasum": ""
},
"require": {
@ -1172,7 +1175,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "5.0-dev"
"dev-main": "5.1-dev"
}
},
"autoload": {
@ -1214,7 +1217,8 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/exporter/issues",
"source": "https://github.com/sebastianbergmann/exporter/tree/5.0.0"
"security": "https://github.com/sebastianbergmann/exporter/security/policy",
"source": "https://github.com/sebastianbergmann/exporter/tree/5.1.1"
},
"funding": [
{
@ -1222,7 +1226,7 @@
"type": "github"
}
],
"time": "2023-02-03T07:06:49+00:00"
"time": "2023-09-24T13:22:09+00:00"
},
{
"name": "sebastian/global-state",
@ -1288,16 +1292,16 @@
},
{
"name": "sebastian/lines-of-code",
"version": "2.0.0",
"version": "2.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/lines-of-code.git",
"reference": "17c4d940ecafb3d15d2cf916f4108f664e28b130"
"reference": "649e40d279e243d985aa8fb6e74dd5bb28dc185d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/17c4d940ecafb3d15d2cf916f4108f664e28b130",
"reference": "17c4d940ecafb3d15d2cf916f4108f664e28b130",
"url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/649e40d279e243d985aa8fb6e74dd5bb28dc185d",
"reference": "649e40d279e243d985aa8fb6e74dd5bb28dc185d",
"shasum": ""
},
"require": {
@ -1333,7 +1337,8 @@
"homepage": "https://github.com/sebastianbergmann/lines-of-code",
"support": {
"issues": "https://github.com/sebastianbergmann/lines-of-code/issues",
"source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.0"
"security": "https://github.com/sebastianbergmann/lines-of-code/security/policy",
"source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.1"
},
"funding": [
{
@ -1341,7 +1346,7 @@
"type": "github"
}
],
"time": "2023-02-03T07:08:02+00:00"
"time": "2023-08-31T09:25:50+00:00"
},
{
"name": "sebastian/object-enumerator",

View file

@ -1,7 +1,7 @@
<?php
// AString.php
// Created: 2021-04-26
// Updated: 2023-07-05
// Updated: 2023-11-09
namespace Index;
@ -11,7 +11,7 @@ use InvalidArgumentException;
/**
* Provides an immutable ASCII string with arrow methods.
*
* Normal PHP strings should be used for buffers/byte arrays.
* @deprecated IString, AString and WString are deprecated and will be removed. Use XString methods instead.
*/
final class AString implements IString {
use XStringTrait;

View file

@ -1,13 +1,11 @@
<?php
// IDbResult.php
// Created: 2021-05-02
// Updated: 2022-02-16
// Updated: 2023-11-09
namespace Index\Data;
use Index\AString;
use Index\ICloseable;
use Index\WString;
use Index\IO\Stream;
/**
@ -45,23 +43,6 @@ interface IDbResult extends ICloseable {
*/
function getString(int|string $index): string;
/**
* Gets the value from the target index cast as an ASCII string.
*
* @param int|string $index Target index.
* @return AString Returns an AString of the value.
*/
function getAString(int|string $index): AString;
/**
* Gets the value from the target index cast as a multi-byte string.
*
* @param int|string $index Target index.
* @param string $encoding Encoding of the string.
* @return WString Returns an WString of the value.
*/
function getWString(int|string $index, string $encoding): WString;
/**
* Gets the value from the target index cast as an integer.
*

View file

@ -1,7 +1,7 @@
<?php
// MariaDBConnection.php
// Created: 2021-04-30
// Updated: 2023-07-10
// Updated: 2023-11-09
namespace Index\Data\MariaDB;
@ -9,7 +9,6 @@ use mysqli;
use mysqli_sql_exception;
use InvalidArgumentException;
use RuntimeException;
use Index\AString;
use Index\Version;
use Index\Data\BeginTransactionFailedException;
use Index\Data\DataException;

View file

@ -1,15 +1,13 @@
<?php
// MariaDBResult.php
// Created: 2021-05-02
// Updated: 2023-01-01
// Updated: 2023-11-09
namespace Index\Data\MariaDB;
use mysqli_result;
use mysqli_stmt;
use InvalidArgumentException;
use Index\AString;
use Index\WString;
use Index\Data\IDbResult;
use Index\IO\Stream;
use Index\IO\TempFileStream;
@ -73,14 +71,6 @@ abstract class MariaDBResult implements IDbResult {
return (string)$this->getValue($index);
}
public function getAString(int|string $index): AString {
return new AString($this->getString($index));
}
public function getWString(int|string $index, string $encoding): WString {
return new WString($this->getString($index), $encoding);
}
public function getInteger(int|string $index): int {
return (int)$this->getValue($index);
}

View file

@ -1,12 +1,10 @@
<?php
// NullDbResult.php
// Created: 2021-05-02
// Updated: 2022-02-16
// Updated: 2023-11-09
namespace Index\Data\NullDb;
use Index\AString;
use Index\WString;
use Index\Data\IDbResult;
use Index\IO\Stream;
@ -30,14 +28,6 @@ class NullDbResult implements IDbResult {
return '';
}
public function getAString(int|string $index): AString {
return AString::empty();
}
public function getWString(int|string $index, string $encoding): WString {
return WString::empty();
}
public function getInteger(int|string $index): int {
return 0;
}

View file

@ -1,14 +1,12 @@
<?php
// SQLiteResult.php
// Created: 2021-05-02
// Updated: 2023-01-01
// Updated: 2023-11-09
namespace Index\Data\SQLite;
use SQLite3Result;
use InvalidArgumentException;
use Index\AString;
use Index\WString;
use Index\Data\IDbResult;
use Index\IO\Stream;
use Index\IO\TempFileStream;
@ -59,14 +57,6 @@ class SQLiteResult implements IDbResult {
return (string)$this->getValue($index);
}
public function getAString(int|string $index): AString {
return new AString($this->getString($index));
}
public function getWString(int|string $index, string $encoding): WString {
return new WString($this->getString($index), $encoding);
}
public function getInteger(int|string $index): int {
return (int)$this->getValue($index);
}

View file

@ -1,7 +1,7 @@
<?php
// HttpFx.php
// Created: 2022-02-15
// Updated: 2023-09-11
// Updated: 2023-11-09
namespace Index\Http;
@ -9,8 +9,6 @@ use stdClass;
use Exception;
use JsonSerializable;
use Index\Environment;
use Index\IString;
use Index\WString;
use Index\IO\Stream;
use Index\Http\Content\BencodedContent;
use Index\Http\Content\JsonContent;
@ -115,7 +113,7 @@ class HttpFx implements IRouter {
if(!$responseBuilder->hasContentType())
$responseBuilder->setTypeJson();
$responseBuilder->setContent(new JsonContent($result));
} elseif(is_object($result) && !($result instanceof IString)) {
} elseif(is_object($result)) {
foreach($this->objectHandlers as $info)
if($info[0]($result)) {
$info[1]($responseBuilder, $result);
@ -124,17 +122,18 @@ class HttpFx implements IRouter {
}
if(!$responseBuilder->hasContent() && $result !== null) {
$charset = ($result instanceof WString) ? $result->getEncoding() : null;
$result = (string)$result;
$responseBuilder->setContent(new StringContent($result));
if(!$responseBuilder->hasContentType()) {
$charset = strtolower(mb_preferred_mime_name(mb_detect_encoding($result)));
if(strtolower(substr($result, 0, 5)) === '<?xml')
$responseBuilder->setTypeXML($charset ?? WString::getDefaultEncoding());
$responseBuilder->setTypeXML($charset);
elseif(strtolower(substr($result, 0, 14)) === '<!doctype html')
$responseBuilder->setTypeHTML($charset ?? WString::getDefaultEncoding());
$responseBuilder->setTypeHTML($charset);
else
$responseBuilder->setTypePlain($charset ?? 'us-ascii');
$responseBuilder->setTypePlain($charset);
}
}
}
@ -154,7 +153,7 @@ class HttpFx implements IRouter {
'<!doctype html><html><head><meta charset="%3$s"/><title>%1$03d %2$s</title></head><body><center><h1>%1$03d %2$s</h1></center><hr/><center>Index</center></body></html>',
$code,
$message,
WString::getDefaultEncoding()
strtolower(mb_preferred_mime_name(mb_internal_encoding()))
)));
}

View file

@ -1,7 +1,7 @@
<?php
// IString.php
// Created: 2021-06-20
// Updated: 2023-07-05
// Updated: 2023-11-09
namespace Index;
@ -12,6 +12,9 @@ use JsonSerializable;
use Stringable;
use Index\Serialisation\IBencodeSerialisable;
/**
* @deprecated IString, AString and WString are deprecated and will be removed. Use XString methods instead.
*/
interface IString extends ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Stringable, IComparable, ICloneable, IEquatable, IBencodeSerialisable {
/**
* Default trim characters.

View file

@ -1,7 +1,7 @@
<?php
// StringIterator.php
// Created: 2022-02-02
// Updated: 2022-02-02
// Updated: 2023-11-09
namespace Index;
@ -9,6 +9,8 @@ use Iterator;
/**
* Provides an iterator for IString types.
*
* @deprecated Will be removed along with IString, AString and WString.
*/
class StringIterator implements Iterator {
private IString $value;

View file

@ -1,7 +1,7 @@
<?php
// WString.php
// Created: 2021-06-22
// Updated: 2023-07-05
// Updated: 2023-11-09
namespace Index;
@ -11,6 +11,8 @@ use ValueError;
/**
* Provides an immutable multi-byte string with arrow methods.
*
* @deprecated IString, AString and WString are deprecated and will be removed. Use XString methods instead.
*/
final class WString implements IString {
use XStringTrait;

View file

@ -1,11 +1,12 @@
<?php
// XString.php
// Created: 2022-02-03
// Updated: 2023-07-05
// Updated: 2023-11-09
namespace Index;
use InvalidArgumentException;
use Stringable;
/**
* Provides various helper methods for strings.
@ -18,35 +19,34 @@ final class XString {
*/
public const RANDOM_CHARS = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789';
public static function toBool(string $value): bool {
return boolval($value);
}
public static function toInt(string $value, int $base = 10): int {
return $base === 10 ? (int)$value : intval($value, $base);
}
public static function toFloat(string $value): float {
return (float)$value;
}
/**
* Converts special characters to HTML entities.
*
* Uses htmlspecialchars with alternate defaults.
*
* @param Stringable|string $string The string being converted.
* @param int $flags A bitmask consisting of flags found in the documentation for htmlspecialchars.
* @param ?string $encoding Optional argument defining the encoding used when converting characters.
* @param bool $doubleEncoding Also reencode existing HTML entities.
* @return string The converted string.
*/
public static function escape(
string $value,
Stringable|string $string,
int $flags = ENT_COMPAT | ENT_HTML5,
?string $encoding = null,
bool $doubleEncoding = true
): string {
return htmlspecialchars($value, $flags, $encoding, $doubleEncoding);
return htmlspecialchars((string)$string, $flags, $encoding, $doubleEncoding);
}
/**
* Counts unique characters in a string.
*
* @param string $string String to count unique characters of.
* @param Stringable|string $string String to count unique characters of.
* @return int Unique character count.
*/
public static function countUnique(string $string): int {
$string = str_split($string);
public static function countUnique(Stringable|string $string): int {
$string = str_split((string)$string);
$chars = [];
foreach($string as $char)
@ -59,24 +59,22 @@ final class XString {
/**
* Check if a string is null or empty.
*
* @param IString|string|null $string String ot check for emptiness.
* @param Stringable|string|null $string String ot check for emptiness.
* @return bool true if the string is empty, false if not.
*/
public static function nullOrEmpty(IString|string|null $string): bool {
public static function nullOrEmpty(Stringable|string|null $string): bool {
if($string === null)
return true;
if($string instanceof IString)
return $string->isEmpty();
return empty($string);
return empty((string)$string);
}
/**
* Check if a string is null or whitespace.
*
* @param IString|string|null $string String to check for whitespace.
* @param Stringable|string|null $string String to check for whitespace.
* @return bool true if the string is whitespace, false if not.
*/
public static function nullOrWhitespace(IString|string|null $string): bool {
public static function nullOrWhitespace(Stringable|string|null $string): bool {
if($string === null)
return true;
return empty(trim((string)$string));

View file

@ -1,7 +1,7 @@
<?php
// XStringTrait.php
// Created: 2021-06-22
// Updated: 2022-02-27
// Updated: 2023-11-09
namespace Index;
@ -10,6 +10,7 @@ use BadMethodCallException;
/**
* Provides method implementations that are common between all string types.
* @internal
* @deprecated Will be removed along with IString, AString and WString.
*/
trait XStringTrait {
/**
@ -43,15 +44,15 @@ trait XStringTrait {
}
public function toBool(): bool {
return XString::toBool($this);
return boolval((string)$this);
}
public function toInt(int $base = 10): int {
return XString::toInt($this, $base);
return $base === 10 ? (int)(string)$this : intval((string)$this, $base);
}
public function toFloat(): float {
return XString::toFloat($this);
return (float)(string)$this;
}
public function escape(

View file

@ -1,12 +1,11 @@
<?php
// EnvironmentTest.php
// Created: 2021-05-02
// Updated: 2023-01-01
// Updated: 2023-11-09
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use Index\AString;
use Index\Environment;
use Index\Version;