Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/Handlers/ArrayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public function get(string $class, string $property, ?string $context = null)
return $this->getStored($class, $property, $context);
}

public function getAll(?string $class, ?string $context = null)
{
return $this->getAllStored($class, $context);
}

public function set(string $class, string $property, $value = null, ?string $context = null)
{
$this->setStored($class, $property, $value, $context);
Expand Down Expand Up @@ -98,6 +103,48 @@ protected function getStored(string $class, string $property, ?string $context)
: $this->parseValue(...$this->contexts[$context][$class][$property]);
}

/**
* Retrieves all values from storage.
*
* @return mixed|null
*/
protected function getAllStored(?string $class, ?string $context)
{
$properties = null;

if ($context === null) {
if ($class === null) {
$properties = $this->general;
} elseif (isset($this->general[$class])) {
$properties = $this->general[$class];
}
} elseif (isset($this->contexts[$context])) {
if ($class === null) {
$properties = $this->contexts[$context];
} elseif (isset($this->contexts[$context][$class])) {
$properties = $this->contexts[$context][$class];
}
}

if ($properties === null) {
return null;
}

if ($class === null) {
foreach ($properties as &$c) {
foreach ($c as &$p) {
$p = $this->parseValue(...$p);
}
}
} else {
foreach ($properties as &$p) {
$p = $this->parseValue(...$p);
}
}

return $properties;
}

/**
* Adds values to storage.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ abstract public function has(string $class, string $property, ?string $context =
*/
abstract public function get(string $class, string $property, ?string $context = null);

/**
* Returns all values from the handler, if stored.
*
* @return mixed
*/
abstract public function getAll(?string $class, ?string $context = null);

/**
* If the Handler supports saving values, it
* MUST override this method to provide that functionality.
Expand Down
10 changes: 10 additions & 0 deletions src/Handlers/DatabaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public function get(string $class, string $property, ?string $context = null)
return $this->getStored($class, $property, $context);
}

/**
* Retrieve all values from the database.
*
* @return mixed|null
*/
public function getAll(?string $class, ?string $context = null)
{
return $this->getAllStored($class, $context);
}

/**
* Stores values into the database for later retrieval.
*
Expand Down
22 changes: 22 additions & 0 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ public function get(string $key, ?string $context = null)
return $config->{$property} ?? null;
}

/**
* Retrieve all values from any handler
* file.arg.optionalArg
*/
public function getAll(?string $key = null, ?string $context = null): array
{
if ($key !== null) {
[$class] = $this->prepareClassAndProperty($key . '.');
} else {
$class = null;
}

$properties = [];

// Add handlers
foreach ($this->handlers as $handler) {
$properties[$handler::class] = $handler->getAll($class, $context);
}

return $properties;
}

/**
* Save a value to the writable handler for later retrieval.
*
Expand Down
Loading