@@ -9,6 +9,8 @@ https://bank.gov.ua/en/news/all/natsionalniy-bank-vidkriv-spetsrahunok-dlya-zbor
9
9
10
10
# SimpUtils
11
11
12
+ Those badges are outdated for now :(
13
+
12
14
[ ![ Build Status] ( https://app.travis-ci.com/PandaHugMonster/php-simputils.svg?branch=main )] ( https://app.travis-ci.com/PandaHugMonster/php-simputils )
13
15
[ ![ codecov] ( https://codecov.io/gh/PandaHugMonster/php-simputils/branch/main/graph/badge.svg )] ( https://codecov.io/gh/PandaHugMonster/php-simputils )
14
16
@@ -42,6 +44,11 @@ I will be really happy hearing from you.
42
44
43
45
## Changelog
44
46
47
+ ### 1.1.2
48
+
49
+ * Implemented ` \spaf\simputils\basic\with ` functionality of a transactional style like
50
+ python ` with ` command. Really useful for DB and other connection types.
51
+
45
52
### 1.1.1
46
53
47
54
* Implemented ` \spaf\simputils\components\normalizers\BoxNormalizer ` To normalize simple
@@ -130,7 +137,7 @@ so documentation will come after that in the very nearest time. My apologies.
130
137
131
138
Minimal PHP version: ** 8.0**
132
139
133
- Current framework version: ** 1.1.1 **
140
+ Current framework version: ** 1.1.2 **
134
141
``` shell
135
142
composer require spaf/simputils " ^1"
136
143
```
@@ -149,6 +156,7 @@ Just a few tini-tiny examples of very condensed functionality :)
149
156
3 . [ Advanced PHP Info Object] ( #Advanced-PHP-Info-Object )
150
157
4 . [ IPv4 model] ( #IPv4-model )
151
158
5 . [ Path-alike Box-array] ( #Path-alike-Box-array )
159
+ 5 . [ "with" love] ( #with-love )
152
160
153
161
### Properties
154
162
@@ -570,6 +578,21 @@ You can access top-level fields (those that directly on the object):
570
578
}
571
579
```
572
580
581
+ ## Additional benefits
582
+ 1 . All the versions are wrapped into ` Version ` class (out of the box version comparison, etc.)
583
+ 2 . The object is created once, and can be accessed through ` PHP::info() `
584
+ (manually possible to have multiple)
585
+ 3 . The object is being derivative from Box, that means that it has all the benefits (
586
+ all the underlying arrays are Boxed as well, so the whole content of the php info
587
+ is available through Box functionality)
588
+ 4 . Contains lots of information, and probably will be extended in the future with more
589
+ relevant information.
590
+
591
+ ## Reasoning to use Advanced PHP Info Object
592
+ The native ` phpinfo() ` returns just a static text representation, which is incredibly
593
+ uncomfortable to use.
594
+ Info about native one you can find here: https://www.php.net/manual/ru/function.phpinfo.php
595
+
573
596
### IPv4 model
574
597
575
598
Simple example:
@@ -641,20 +664,72 @@ TEST ## PATH ## alike ## box
641
664
642
665
```
643
666
644
- ## Additional benefits
645
- 1 . All the versions are wrapped into ` Version ` class (out of the box version comparison, etc.)
646
- 2 . The object is created once, and can be accessed through ` PHP::info() `
647
- (manually possible to have multiple)
648
- 3 . The object is being derivative from Box, that means that it has all the benefits (
649
- all the underlying arrays are Boxed as well, so the whole content of the php info
650
- is available through Box functionality)
651
- 4 . Contains lots of information, and probably will be extended in the future with more
652
- relevant information.
653
667
654
- ## Reasoning to use Advanced PHP Info Object
655
- The native ` phpinfo() ` returns just a static text representation, which is incredibly
656
- uncomfortable to use.
657
- Info about native one you can find here: https://www.php.net/manual/ru/function.phpinfo.php
668
+ ### "with" love
669
+
670
+ Python specific command ` with ` can be easily implemented through meta-magic and callables.
671
+
672
+ Simple example:
673
+ ``` php
674
+
675
+ PHP::init();
676
+
677
+ class Totoro extends SimpleObject {
678
+
679
+ protected function ___withStart($obj, $callback) {
680
+ pr('PREPARED! %)');
681
+ // $callback($obj);
682
+ // return true;
683
+ }
684
+
685
+ protected function ___withEnd($obj) {
686
+ pr('POST DONE %_%');
687
+ }
688
+
689
+ }
690
+
691
+ $obj = new Totoro;
692
+
693
+ with($obj, function () {
694
+ pr('HEY! :)');
695
+ });
696
+ ```
697
+
698
+ You can access the target object easily from the callable:
699
+ ``` php
700
+ $obj = new Totoro;
701
+
702
+ with($obj, function ($obj) {
703
+ pr('HEY! :)', $obj);
704
+ });
705
+
706
+ // or less elegant way:
707
+ with($obj, function () use ($obj) {
708
+ pr('HEY! :)', $obj);
709
+ });
710
+
711
+ ```
712
+
713
+ The example above can be combined if you want to use more from the outer scope,
714
+ but to keep the elegant way :)
715
+
716
+ ``` php
717
+ $obj = new Totoro;
718
+
719
+ $var1 = 1;
720
+ $var2 = 0.2;
721
+ $var3 = 'CooCoo';
722
+
723
+ with($obj, function ($obj) use ($var1, $var2, $var3) {
724
+ pr('HEY! :)', $obj, $var1, $var2, $var3);
725
+ });
726
+
727
+ ```
728
+
729
+ The syntax obviously is not that cute as in python, but functionally it's the same thing.
730
+
731
+ P.S. Keep in mind that the ` with() ` functionality relies on "MetaMagic" trait, and object
732
+ should use either the trait or implement 2 methods of ` ___withStart() ` and ` ___withEnd() `
658
733
659
734
660
735
----
0 commit comments