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

ENH Performance optimisations #10083

Closed
Closed
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
22 changes: 7 additions & 15 deletions src/Core/Injector/InjectionCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,21 @@

namespace SilverStripe\Core\Injector;

use ReflectionClass;
use ReflectionException;

/**
* A class for creating new objects by the injector.
*/
class InjectionCreator implements Factory
{

public function create($class, array $params = [])
{
try {
$reflector = new ReflectionClass($class);
} catch (ReflectionException $e) {
throw new InjectorNotFoundException($e);
if (!class_exists($class)) {
throw new InjectorNotFoundException(sprintf('Class "%s" does not exist', $class));
}

if (count($params)) {
// Remove named keys to ensure that PHP7 and PHP8 interpret these the same way
$params = array_values($params);
return $reflector->newInstanceArgs($params);
if (empty($params)) {
return new $class();
}

return $reflector->newInstance();
// Remove named keys to ensure that PHP7 and PHP8 interpret these the same way
$args = array_values($params);
return new $class(...$args);
}
}