File tree Expand file tree Collapse file tree 12 files changed +225
-71
lines changed Expand file tree Collapse file tree 12 files changed +225
-71
lines changed Original file line number Diff line number Diff line change 44[ ![ Php Version] ( https://img.shields.io/badge/php-%3E8.0-brightgreen.svg?maxAge=2592000 )] ( https://packagist.org/packages/toolkit/stdlib )
55[ ![ Latest Stable Version] ( http://img.shields.io/packagist/v/toolkit/stdlib.svg )] ( https://packagist.org/packages/toolkit/stdlib )
66[ ![ Github Actions Status] ( https://github.com/php-toolkit/stdlib/workflows/Unit-Tests/badge.svg )] ( https://github.com/php-toolkit/stdlib/actions )
7+ [ ![ Docs on pages] ( https://img.shields.io/badge/DocsOn-GhPages-brightgreen.svg?maxAge=2592000 )] ( https://php-toolkit.github.io/stdlib/ )
78
89🧰 Stdlib - Useful basic tools library for PHP development.
910
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="">
3+ < head >
4+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge,chrome=1 ">
5+ < meta name ="viewport " content ="width=device-width,initial-scale=1 ">
6+ < meta charset ="UTF-8 ">
7+ < link rel ="stylesheet " href ="//cdn.jsdelivr.net/npm/docsify/themes/vue.css ">
8+ < title > 🧰 Stdlib - Useful basic tools library for PHP development.</ title >
9+ </ head >
10+ < body >
11+ < div id ="app "> </ div >
12+ < script >
13+ window . $docsify = {
14+ repo : 'php-toolkit/stdlib' ,
15+ maxLevel : 4 ,
16+ // 加载 _navbar.md
17+ loadNavbar : true ,
18+ // loadNavbar: 'https://raw.githubusercontent.com/inhere/conf/master/docsify/php-projects.md',
19+ // 加载 _sidebar.md
20+ // loadSidebar: true,
21+ alias : {
22+ // '/_navbar.md': 'https://raw.githubusercontent.com/inhere/conf/master/docsify/php-projects.md',
23+ // '/.*/_sidebar.md': 'https://raw.githubusercontent.com/inhere/conf/master/docsify/php-projects.md',
24+ // '/.*/_sidebar.md': '/_sidebar.md', // See #301
25+ }
26+ }
27+ </ script >
28+ < script src ="//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js "> </ script >
29+ </ body >
30+ </ html >
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Toolkit \Stdlib \Helper ;
4+
5+ use function abs ;
6+ use function ceil ;
7+ use function floor ;
8+ use function round ;
9+ use const PHP_ROUND_HALF_UP ;
10+
11+ /**
12+ * class NumHelper
13+ *
14+ * @author inhere
15+ */
16+ class NumHelper
17+ {
18+ /**
19+ * @param float|int $value
20+ *
21+ * @return int
22+ */
23+ public static function floor (float |int $ value ): int
24+ {
25+ return (int )floor ((float )$ value );
26+ }
27+
28+ /**
29+ * @param float|int $value
30+ *
31+ * @return int
32+ */
33+ public static function ceil (float |int $ value ): int
34+ {
35+ return (int )ceil ((float )$ value );
36+ }
37+
38+ /**
39+ * @param float|int $value
40+ *
41+ * @return int
42+ */
43+ public static function abs (float |int $ value ): int
44+ {
45+ return (int )abs ($ value );
46+ }
47+
48+ /**
49+ * @param float|int $value
50+ * @param int $precision
51+ * @param int $mode
52+ *
53+ * @return float
54+ */
55+ public static function round (float |int $ value , int $ precision = 0 , int $ mode = PHP_ROUND_HALF_UP ): float
56+ {
57+ return round ((float )$ value , $ precision , $ mode );
58+ }
59+
60+ /**
61+ * @param float|int $value
62+ *
63+ * @return int
64+ */
65+ public static function roundInt (float |int $ value ): int
66+ {
67+ return (int )round ((float )$ value );
68+ }
69+ }
Original file line number Diff line number Diff line change 99
1010namespace Toolkit \Stdlib ;
1111
12- use Toolkit \Stdlib \Helper \IntHelper ;
13- use function abs ;
14- use function ceil ;
15- use function floor ;
16- use function round ;
17- use const PHP_ROUND_HALF_UP ;
12+ use Toolkit \Stdlib \Helper \NumHelper ;
1813
1914/**
2015 * Class Math
2116 *
2217 * @package Toolkit\Stdlib
2318 */
24- class Math extends IntHelper
19+ class Math extends NumHelper
2520{
26- /**
27- * @param float|int $value
28- *
29- * @return int
30- */
31- public static function floor (float |int $ value ): int
32- {
33- return (int )floor ((float )$ value );
34- }
3521
36- /**
37- * @param float|int $value
38- *
39- * @return int
40- */
41- public static function ceil (float |int $ value ): int
42- {
43- return (int )ceil ((float )$ value );
44- }
45-
46- /**
47- * @param float|int $value
48- *
49- * @return int
50- */
51- public static function abs (float |int $ value ): int
52- {
53- return (int )abs ($ value );
54- }
55-
56- /**
57- * @param float|int $value
58- * @param int $precision
59- * @param int $mode
60- *
61- * @return float
62- */
63- public static function round (float |int $ value , int $ precision = 0 , int $ mode = PHP_ROUND_HALF_UP ): float
64- {
65- return round ((float )$ value , $ precision , $ mode );
66- }
67-
68- /**
69- * @param float|int $value
70- *
71- * @return int
72- */
73- public static function roundInt (float |int $ value ): int
74- {
75- return (int )round ((float )$ value );
76- }
7722}
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+ /**
3+ * This file is part of toolkit/stdlib.
4+ *
5+ * @author https://github.com/inhere
6+ * @link https://github.com/php-toolkit/stdlib
7+ * @license MIT
8+ */
9+
10+ namespace Toolkit \Stdlib ;
11+
12+ use Toolkit \Stdlib \Helper \NumHelper ;
13+
14+ /**
15+ * Class Num
16+ *
17+ * @package Toolkit\Stdlib
18+ */
19+ class Num extends NumHelper
20+ {
21+
22+ }
Original file line number Diff line number Diff line change 66use Toolkit \Stdlib \Obj ;
77use Toolkit \Stdlib \Obj \Exception \ContainerException ;
88use Toolkit \Stdlib \Obj \Exception \NotFoundException ;
9+ use Toolkit \Stdlib \Obj \Traits \AutoConfigTrait ;
910use function array_keys ;
1011use function count ;
1112use function is_array ;
2526 */
2627class ObjectBox implements ContainerInterface
2728{
29+ use AutoConfigTrait;
30+
2831 /**
2932 * only create object on first fetch.
3033 */
@@ -66,16 +69,6 @@ class ObjectBox implements ContainerInterface
6669 */
6770 private array $ definitions = [];
6871
69- /**
70- * Class constructor.
71- *
72- * @param array $options
73- */
74- public function __construct (array $ options = [])
75- {
76- Obj::init ($ this , $ options );
77- }
78-
7972 /**
8073 * @return static
8174 */
@@ -113,11 +106,11 @@ public function get(string $id): mixed
113106 if ($ callInit && method_exists ($ obj , $ this ->initMethod )) {
114107 $ obj ->init ();
115108 }
116- }
117109
118- // storage it on type is TYPE_SINGLETON
119- if ($ opt ['objType ' ] ?? self ::TYPE_SINGLETON ) {
120- $ this ->objects [$ id ] = $ obj ;
110+ // storage it on type is TYPE_SINGLETON
111+ if ($ opt ['objType ' ] ?? self ::TYPE_SINGLETON ) {
112+ $ this ->objects [$ id ] = $ obj ;
113+ }
121114 }
122115
123116 // type TYPE_PROTOTYPE always create new object.
Original file line number Diff line number Diff line change 77 * @license MIT
88 */
99
10+ use JetBrains \PhpStorm \NoReturn ;
11+
1012if (!function_exists ('vdump ' )) {
1113 /**
1214 * Dump data like var_dump
@@ -34,6 +36,7 @@ function vdump(...$vars): void
3436 *
3537 * @param mixed ...$vars
3638 */
39+ #[NoReturn]
3740 function edump (...$ vars ): void
3841 {
3942 $ trace = debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS , 2 );
@@ -56,6 +59,7 @@ function edump(...$vars): void
5659 *
5760 * @param mixed ...$vars
5861 */
62+ #[NoReturn]
5963 function ddump (...$ vars ): void
6064 {
6165 $ trace = debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS , 2 );
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Toolkit \StdlibTest \Cases ;
4+
5+ use Toolkit \Stdlib \Obj \Traits \AutoConfigTrait ;
6+
7+ /**
8+ * class AutoConfigObj
9+ *
10+ * @author inhere
11+ */
12+ class AutoConfigObj
13+ {
14+ use AutoConfigTrait;
15+
16+ public int $ age = 0 ;
17+
18+ private string $ name = '' ;
19+
20+ /**
21+ * @param string $name
22+ */
23+ public function setName (string $ name ): void
24+ {
25+ $ this ->name = $ name ;
26+ }
27+
28+ /**
29+ * @return string
30+ */
31+ public function getName (): string
32+ {
33+ return $ this ->name ;
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Toolkit \StdlibTest \Obj ;
4+
5+ use Toolkit \Stdlib \Obj \ObjectBox ;
6+ use Toolkit \StdlibTest \BaseLibTestCase ;
7+
8+ /**
9+ * class ObjectBoxTest
10+ *
11+ * @author inhere
12+ */
13+ class ObjectBoxTest extends BaseLibTestCase
14+ {
15+ public function testObjectBox_basic (): void
16+ {
17+ $ box = ObjectBox::new ();
18+ $ box ->set ('name1 ' , 'inhere ' );
19+
20+ $ this ->assertTrue ($ box ->has ('name1 ' ));
21+ $ this ->assertEquals ('inhere ' , $ box ->get ('name1 ' ));
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments