Skip to content

Commit af98c05

Browse files
committed
updated source code \_o-o_/
1 parent d68ad7f commit af98c05

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ for this i made some helper functions that allow you to remove variables from th
4343

4444
- `Typed\purge()` will delete every reference registered in the repository, you can call this function at the end of every request/response cycle in a web application per example.
4545
- `Typed\clean(string $namespace = 'default')` this function will delete every reference to a typed variable in a specific namespace as shown in the example above, its recommended to use a unique namespace every time you use typed variables and call `clean()` to ensure there's no memory leak.
46-
- `Typed\delete(mixed $value, string $namespace = 'default')` this function will delete the last created reference to typed variable with the given value in a specific namespace. example :
46+
- `Typed\filter(mixed $value, string $namespace = 'default')` this function will delete the every created reference to a typed variable with the given value in a specific namespace.
47+
- `Typed\delete(mixed $value, string $namespace = 'default')` similar to what `Typed\filter` does, this function allows you to delete the last created reference to a typed variable with the given value in a specific namespace. example :
4748
```php
4849
<?php declare(strict_types=1);
4950

src/Typed/Repository.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,16 @@ public static function purge(): void
5555
*/
5656
public static function filter($value, string $namespace): void
5757
{
58-
foreach (static::$variables as $ns) {
59-
if ($namespace !== $ns) {
60-
continue;
61-
}
58+
if (!array_key_exists($namespace, static::$variables)) {
59+
return;
60+
}
6261

63-
/**
64-
* @var VariableInterface $var
65-
*/
66-
foreach ($ns as $i => $var) {
67-
if ($var->getValue() === $value) {
68-
unset(static::$variables[$ns][$i]);
69-
}
62+
/**
63+
* @var VariableInterface $var
64+
*/
65+
foreach (static::$variables[$namespace] as $i => $var) {
66+
if ($var->getValue() === $value) {
67+
unset(static::$variables[$namespace][$i]);
7068
}
7169
}
7270
}

0 commit comments

Comments
 (0)