Skip to content

Commit

Permalink
cache
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammetsafak committed Nov 23, 2022
1 parent 0125ca2 commit 03a0cf3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Exception/ParameterBagInvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <[email protected]>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 1.1.1
* @version 1.1.2
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
15 changes: 13 additions & 2 deletions src/ParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <[email protected]>
* @copyright Copyright © 2022 InitPHP
* @license http://initphp.github.io/license.txt MIT
* @version 1.1.1
* @version 1.1.2
* @link https://www.muhammetsafak.com.tr
*/

Expand All @@ -32,6 +32,7 @@
use function is_bool;
use function array_map;
use function array_change_key_case;
use function array_key_exists;

class ParameterBag implements ParameterBagInterface
{
Expand All @@ -44,6 +45,9 @@ class ParameterBag implements ParameterBagInterface
'separator' => '.',
];

/** @var array */
private $_PBCache = [];

public function __construct(array $data = [], array $options = [])
{
if(!empty($data)){
Expand Down Expand Up @@ -106,7 +110,7 @@ public function has(string $key): bool
if($this->_PBOptions['isMulti'] && strpos($key, $this->_PBOptions['separator']) !== FALSE){
return ($this->multiSubParameterGet($key) !== '__InitPHPP@r@m£t£rB@gN0tF0undV@lu€__');
}
return isset($this->_PBStack[$key]);
return isset($this->_PBStack[$key]) || array_key_exists($key, $this->_PBStack);
}

/**
Expand All @@ -115,6 +119,9 @@ public function has(string $key): bool
public function get(string $key, $default = null)
{
$key = $this->getKey($key);
if(isset($this->_PBCache[$key])){
return $this->_PBCache[$key];
}
if($this->_PBOptions['isMulti'] !== FALSE && strpos($key, $this->_PBOptions['separator']) !== FALSE){
$value = $this->multiSubParameterGet($key);
return ($value !== '__InitPHPP@r@m£t£rB@gN0tF0undV@lu€__') ? $value : $default;
Expand All @@ -131,6 +138,7 @@ public function set(string $key, $value): ParameterBagInterface
if(is_array($value)){
$value = $this->arrayChangeKeyCaseLower($value);
}
$this->_PBCache[$key] = $value;
if($this->_PBOptions['isMulti'] !== FALSE && strpos($key, $this->_PBOptions['separator']) !== FALSE){
$split = explode($this->_PBOptions['separator'], $key);
$id = $split[0];
Expand All @@ -149,6 +157,9 @@ public function remove(string ...$keys): ParameterBagInterface
{
foreach ($keys as $key) {
$key = $this->getKey($key);
if(array_key_exists($key, $this->_PBCache)){
unset($this->_PBCache[$key]);
}
if($this->_PBOptions['isMulti'] !== FALSE && strpos($key, $this->_PBOptions['separator']) !== FALSE){
$split = explode($this->_PBOptions['separator'], $key);
$id = $keys[0];
Expand Down
2 changes: 1 addition & 1 deletion src/ParameterBagInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <[email protected]>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 1.1.1
* @version 1.1.2
* @link https://www.muhammetsafak.com.tr
*/

Expand Down

0 comments on commit 03a0cf3

Please sign in to comment.