Skip to content

Commit

Permalink
updated source code \_o-o_/
Browse files Browse the repository at this point in the history
  • Loading branch information
azjezz committed Jan 14, 2019
1 parent d68ad7f commit af98c05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ for this i made some helper functions that allow you to remove variables from th

- `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.
- `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.
- `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 :
- `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.
- `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 :
```php
<?php declare(strict_types=1);

Expand Down
20 changes: 9 additions & 11 deletions src/Typed/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,16 @@ public static function purge(): void
*/
public static function filter($value, string $namespace): void
{
foreach (static::$variables as $ns) {
if ($namespace !== $ns) {
continue;
}
if (!array_key_exists($namespace, static::$variables)) {
return;
}

/**
* @var VariableInterface $var
*/
foreach ($ns as $i => $var) {
if ($var->getValue() === $value) {
unset(static::$variables[$ns][$i]);
}
/**
* @var VariableInterface $var
*/
foreach (static::$variables[$namespace] as $i => $var) {
if ($var->getValue() === $value) {
unset(static::$variables[$namespace][$i]);
}
}
}
Expand Down

0 comments on commit af98c05

Please sign in to comment.