Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass config($class) performance impact #131

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
27 changes: 6 additions & 21 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* An array of handlers for getting/setting the values.
*
* @var list<BaseHandler>
* @var BaseHandler[]
*/
private array $handlers = [];

Expand Down Expand Up @@ -52,7 +52,7 @@
*/
public function get(string $key, ?string $context = null)
{
[$class, $property, $config] = $this->prepareClassAndProperty($key);
[$class, $property] = $this->prepareClassAndProperty($key);

// Check each of our handlers
foreach ($this->handlers as $handler) {
Expand All @@ -61,12 +61,7 @@
}
}

// If no contextual value was found then fall back to general
if ($context !== null) {
return $this->get($key);
}

return $config->{$property} ?? null;
return config($class)?->{$property} ?? null;

Check failure on line 64 in src/Settings.php

View workflow job for this annotation

GitHub Actions / phpstan / PHP 7.4 Static Analysis

Syntax error, unexpected T_OBJECT_OPERATOR on line 64
}

/**
Expand Down Expand Up @@ -117,7 +112,7 @@
/**
* Returns the handler that is set to store values.
*
* @return list<BaseHandler>
* @return BaseHandler[]
*
* @throws RuntimeException
*/
Expand All @@ -141,7 +136,7 @@
/**
* Analyzes the given key and breaks it into the class.field parts.
*
* @return list<string>
* @return string[]
*
* @throws InvalidArgumentException
*/
Expand All @@ -163,16 +158,6 @@
*/
private function prepareClassAndProperty(string $key): array
{
[$class, $property] = $this->parseDotSyntax($key);

$config = config($class);

// Use a fully qualified class name if the
// config file was found.
if ($config !== null) {
$class = get_class($config);
}

return [$class, $property, $config];
return $this->parseDotSyntax($key);
}
}
Loading