Optimize Grav Services stage for speed

This commit is contained in:
Matias Griese
2018-10-12 13:57:11 +03:00
parent 776d1419c1
commit 049f84a52a
6 changed files with 13 additions and 40 deletions

View File

@@ -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
*

View File

@@ -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;
}
}

View File

@@ -16,6 +16,8 @@ class AssetsServiceProvider implements ServiceProviderInterface
{
public function register(Container $container)
{
$container['assets'] = new Assets();
$container['assets'] = function () {
return new Assets();
};
}
}

View File

@@ -16,7 +16,6 @@ class ErrorServiceProvider implements ServiceProviderInterface
{
public function register(Container $container)
{
$errors = new Errors;
$container['errors'] = $errors;
$container['errors'] = new Errors;
}
}

View File

@@ -17,9 +17,7 @@ class InflectorServiceProvider implements ServiceProviderInterface
public function register(Container $container)
{
$container['inflector'] = function () {
$inflector = new Inflector();
return $inflector;
return new Inflector();
};
}
}

View File

@@ -16,6 +16,8 @@ class SchedulerServiceProvider implements ServiceProviderInterface
{
public function register(Container $container)
{
$container['scheduler'] = new Scheduler();
$container['scheduler'] = function () {
return new Scheduler();
};
}
}