Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 35 | All time: 11,005 This week: 82 |
Version | License | PHP version | Categories | |||
yii2-array-storage 1.0 | MIT/X Consortium ... | 8 | Data types, PHP 8 |
????? ??? ???????? ? ?????????? ??????? ? ???????. ????? ???? ???????? ?? ????????, ????????, ? ???????? ??????? ??? ?????? ? ?????, ???????? _json_ ? ?????? _ActiveRecord_.
composer require smoren/yii2-array-storage
<?php
use Smoren\Yii2\ArrayStorage\Storage;
// ???????? ??????
$data = [
'a' => [
'b1' => [1, 2, 3],
'b2' => 5,
]
];
// ????????????? ?????????
$storage = new Storage($data);
// ????????? ????? ??????? ?????? ?????????
$value = $storage->get();
print_r($value);
/*
Array
(
[a] => Array
(
[b1] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[b2] => 5
)
)
*/
// ????????? ???????? ?? ?????
$value = $storage->get('a');
print_r($value);
/*
Array
(
[b1] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[b2] => 5
)
*/
// ????????? ???????? ?? ????? ? ???????? ???????????
$value = $storage->get('a.b1.0');
var_dump($value);
/int(1)/
// ??????? ????????? ???????? ?? ?????????????? ? ????????? ????? ?? ????????? ?? ?????????
$value = $storage->get('a.b3', '???????? ?? ?????????');
var_dump($value);
/string(40) "???????? ?? ?????????"/
// ??????? ????????? ???????? ?? ?????????????? ? ????????? ????? ??? ???????? ?? ?????????
try {
$storage->get('a.b3');
} catch(\yii\base\Exception $e) {
var_dump($e->getMessage());
/string(39) "key 'a.b3' is not exist in user storage"/
}
// ???????? ????????????? ????? ? ???????
var_dump($storage->has('a.b2'));
/bool(true)/
var_dump($storage->has('a.b3'));
/bool(false)/
try {
$storage->has('a.b3', true);
} catch(\yii\base\Exception $e) {
var_dump($e->getMessage());
/string(39) "key 'a.b3' is not exist in user storage"/
}
// ?????????? ???????? ? ?????????
$storage->set('a.new', '???????? ?????? ????????');
print_r($storage->get());
/*
Array
(
[a] => Array
(
[b1] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[b2] => 5
[new] => ???????? ?????? ????????
)
)
*/
// ?????????? ???????? ? ????????? ? ???????? ??????????
$storage->set('a.new_another', '??? ???? ???????? ?????? ????????', false);
print_r($storage->get());
/*
Array
(
[a] => Array
(
[b1] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[b2] => 5
[new] => ???????? ?????? ????????
[new_another] => ??? ???? ???????? ?????? ????????
)
)
*/
// ??????? ?????????? ???????? ? ???????? ??????????
try {
$storage->set('a.b2', '??? ???????? ?? ?????????', false);
} catch(\yii\base\Exception $e) {
var_dump($e->getMessage());
/string(43) "key 'a.b2' is already exist in user storage"/
}
print_r($storage->get());
/*
Array
(
[a] => Array
(
[b1] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[b2] => 5
[new] => ???????? ?????? ????????
[new_another] => ??? ???? ???????? ?????? ????????
)
)
*/
// ???????? ???????? ?? ????????? ?? ?????, ????????? ???????? ?????????? ????????
$removedValue = $storage->remove('a.b1');
print_r($removedValue);
/*
Array
(
[0] => 1
[1] => 2
[2] => 3
)
*/
print_r($storage->get());
/*
Array
(
[a] => Array
(
[b2] => 5
[new] => ???????? ?????? ????????
[new_another] => ??? ???? ???????? ?????? ????????
)
)
*/
// ??????? ???????? ??????????????? ????????
try {
$storage->remove('a.?');
} catch(\yii\base\Exception $e) {
var_dump($e->getMessage());
/string(39) "key 'a.?' is not exist in user storage"/
}
Files (5) |
File | Role | Description | ||
---|---|---|---|---|
src (1 file) | ||||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Read me |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.