Skip to content

Commit d76cd7a

Browse files
committed
feat: add more std util class
1 parent ac5e1f0 commit d76cd7a

File tree

6 files changed

+342
-221
lines changed

6 files changed

+342
-221
lines changed

src/Arr/ArrayWrap.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Toolkit\Stdlib\Arr;
4+
5+
use Toolkit\Stdlib\Obj\DataObject;
6+
7+
/**
8+
* class ArrayWrap
9+
*
10+
* @author inhere
11+
*/
12+
class ArrayWrap extends DataObject
13+
{
14+
15+
}

src/Arr/FixedArray.php

Lines changed: 0 additions & 220 deletions
This file was deleted.

src/Helper/PhpHelper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,16 @@ public static function exception2html(Throwable $e, bool $getTrace = true, strin
371371
return PhpException::toHtml($e, $getTrace, $catcher);
372372
}
373373

374+
/**
375+
* @param $anyData
376+
*
377+
* @return string
378+
*/
379+
public static function toString($anyData): string
380+
{
381+
return DataHelper::toString($anyData);
382+
}
383+
374384
/**
375385
* @param string $pathname
376386
* @param int|string $projectId This must be a one character

src/Obj/ObjectHelper.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use RuntimeException;
2020
use Toolkit\Stdlib\Helper\PhpHelper;
2121
use Traversable;
22+
use UnexpectedValueException;
2223
use function base64_decode;
2324
use function base64_encode;
2425
use function basename;
@@ -397,7 +398,7 @@ public static function spaceName(string $fullClass): string
397398
/**
398399
* Get class name without namespace.
399400
*
400-
* @param null|string $fullClass
401+
* @param string $fullClass
401402
*
402403
* @return string
403404
*/
@@ -408,4 +409,18 @@ public static function className(string $fullClass): string
408409
return basename($fullClass);
409410
}
410411

412+
/**
413+
* @param object $obj
414+
* @param string $errMsg
415+
*
416+
* @return object
417+
*/
418+
public static function requireNotNull($obj, string $errMsg = '')
419+
{
420+
if ($obj === null) {
421+
throw new UnexpectedValueException($errMsg ?: 'object must not be null');
422+
}
423+
424+
return $obj;
425+
}
411426
}

src/Std/ArrStream.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Toolkit\Stdlib\Std;
4+
5+
/**
6+
* class ArrStream
7+
*
8+
* @author inhere
9+
*/
10+
class ArrStream
11+
{
12+
/**
13+
* @param array $data
14+
*
15+
* @return static
16+
*/
17+
public static function new(array $data = []): self
18+
{
19+
return new static($data);
20+
}
21+
22+
23+
}

0 commit comments

Comments
 (0)