Skip to content

Commit

Permalink
Merge pull request #3 from daniellienert/feature/enable-nested
Browse files Browse the repository at this point in the history
FEATURE: Enable store and receive in nested arrays
  • Loading branch information
dimaip authored Dec 9, 2017
2 parents dcb8386 + a981275 commit 2d3eb7a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
18 changes: 9 additions & 9 deletions Classes/Psmb/Registry/Service/RegistryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
namespace Psmb\Registry\Service;

use Neos\Flow\Annotations as Flow;
use Neos\Utility\Arrays;

/**
* Global regsitry of misc stuff
* Global registry of misc stuff
*
* @Flow\Scope("singleton")
*/
Expand All @@ -13,24 +14,23 @@ class RegistryService {
/**
* @var array
*/
protected $registry;
protected $registry = [];

/**
* @param string $name
* @param string $path
* @return mixed
*/
public function getRegister($name)
public function getRegister(string $path)
{
return isset($this->registry[$name]) ? $this->registry[$name] : null;
return Arrays::getValueByPath($this->registry, $path);
}

/**
* @param string $name
* @param string $path
* @param mixed $value
*/
public function setRegister($name, $value)
public function setRegister(string $path, $value)
{
$this->registry[$name] = $value;
$this->registry = Arrays::setValueByPath($this->registry, $path, $value);
}

}
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

This package provides you with a registry service and an Eel helper to get and set values on it.

Installation: `composer require psmb/registry`
## Installation

Example:
`composer require psmb/registry`

## Usage

#### Example

```
root = T:Collection {
Expand All @@ -17,3 +21,12 @@ root = T:Collection {
}
}
```

The following methods are available:

* **set(key, value):** Sets a value by key
* **get(key):** Returns a value by key
* **increment(key):** Increment a value by key
* **decrement(key):** Derement a value by key

A key can consist of a single string or a path, separated with dots which addresses a value in a nested array.

0 comments on commit 2d3eb7a

Please sign in to comment.