Skip to content

Commit 8db25d8

Browse files
Pre-release commit of 1.1.2
1 parent 1886d50 commit 8db25d8

File tree

1 file changed

+89
-14
lines changed

1 file changed

+89
-14
lines changed

README.md

Lines changed: 89 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ https://bank.gov.ua/en/news/all/natsionalniy-bank-vidkriv-spetsrahunok-dlya-zbor
99

1010
# SimpUtils
1111

12+
Those badges are outdated for now :(
13+
1214
[![Build Status](https://app.travis-ci.com/PandaHugMonster/php-simputils.svg?branch=main)](https://app.travis-ci.com/PandaHugMonster/php-simputils)
1315
[![codecov](https://codecov.io/gh/PandaHugMonster/php-simputils/branch/main/graph/badge.svg)](https://codecov.io/gh/PandaHugMonster/php-simputils)
1416

@@ -42,6 +44,11 @@ I will be really happy hearing from you.
4244

4345
## Changelog
4446

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+
4552
### 1.1.1
4653

4754
* 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.
130137

131138
Minimal PHP version: **8.0**
132139

133-
Current framework version: **1.1.1**
140+
Current framework version: **1.1.2**
134141
```shell
135142
composer require spaf/simputils "^1"
136143
```
@@ -149,6 +156,7 @@ Just a few tini-tiny examples of very condensed functionality :)
149156
3. [Advanced PHP Info Object](#Advanced-PHP-Info-Object)
150157
4. [IPv4 model](#IPv4-model)
151158
5. [Path-alike Box-array](#Path-alike-Box-array)
159+
5. ["with" love](#with-love)
152160

153161
### Properties
154162

@@ -570,6 +578,21 @@ You can access top-level fields (those that directly on the object):
570578
}
571579
```
572580

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+
573596
### IPv4 model
574597

575598
Simple example:
@@ -641,20 +664,72 @@ TEST ## PATH ## alike ## box
641664
642665
```
643666

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.
653667

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()`
658733

659734

660735
----

0 commit comments

Comments
 (0)