mirror of
https://github.com/getgrav/grav.git
synced 2025-12-05 15:29:57 +01:00
Optimize Grav Services stage for speed
This commit is contained in:
@@ -399,40 +399,15 @@ class Grav extends Container
|
||||
{
|
||||
foreach (self::$diMap as $serviceKey => $serviceClass) {
|
||||
if (\is_int($serviceKey)) {
|
||||
$this->registerServiceProvider($serviceClass);
|
||||
$this->register(new $serviceClass);
|
||||
} else {
|
||||
$this->registerService($serviceKey, $serviceClass);
|
||||
$this[$serviceKey] = function ($c) use ($serviceClass) {
|
||||
return new $serviceClass($c);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a service provider with the container.
|
||||
*
|
||||
* @param string $serviceClass
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerServiceProvider($serviceClass)
|
||||
{
|
||||
$this->register(new $serviceClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a service with the container.
|
||||
*
|
||||
* @param string $serviceKey
|
||||
* @param string $serviceClass
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerService($serviceKey, $serviceClass)
|
||||
{
|
||||
$this[$serviceKey] = function ($c) use ($serviceClass) {
|
||||
return new $serviceClass($c);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This attempts to find media, other files, and download them
|
||||
*
|
||||
|
||||
@@ -12,14 +12,11 @@ use Grav\Common\Grav;
|
||||
|
||||
abstract class ProcessorBase
|
||||
{
|
||||
/**
|
||||
* @var Grav
|
||||
*/
|
||||
/** @var Grav */
|
||||
protected $container;
|
||||
|
||||
public function __construct(Grav $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ class AssetsServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['assets'] = new Assets();
|
||||
$container['assets'] = function () {
|
||||
return new Assets();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ class ErrorServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
public function register(Container $container)
|
||||
{
|
||||
$errors = new Errors;
|
||||
$container['errors'] = $errors;
|
||||
$container['errors'] = new Errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,7 @@ class InflectorServiceProvider implements ServiceProviderInterface
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['inflector'] = function () {
|
||||
$inflector = new Inflector();
|
||||
|
||||
return $inflector;
|
||||
return new Inflector();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ class SchedulerServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['scheduler'] = new Scheduler();
|
||||
$container['scheduler'] = function () {
|
||||
return new Scheduler();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user