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

NEW Allow use of new AnnotationTransformer for configuration #9006

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
45 changes: 38 additions & 7 deletions src/Core/Config/CoreConfigFactory.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<?php
<?php declare(strict_types=1);

namespace SilverStripe\Core\Config;

use Psr\SimpleCache\CacheInterface;
use SilverStripe\Config\Collections\CachedConfigCollection;
use SilverStripe\Config\Collections\DeltaConfigCollection;
use SilverStripe\Config\Collections\MemoryConfigCollection;
use SilverStripe\Config\Transformer\AnnotationTransformer;
use SilverStripe\Config\Transformer\AnnotationTransformer\AnnotationDefinitionInterface;
use SilverStripe\Config\Transformer\PrivateStaticTransformer;
use SilverStripe\Config\Transformer\YamlTransformer;
use SilverStripe\Core\Cache\CacheFactory;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\AnnotationTransformer\InjectableDefinition;
use SilverStripe\Core\Config\Middleware\ExtensionMiddleware;
use SilverStripe\Core\Config\Middleware\InheritanceMiddleware;
use SilverStripe\Core\Environment;
Expand Down Expand Up @@ -88,7 +92,8 @@ public function createCore()
// Transform
$config->transform([
$this->buildStaticTransformer(),
$this->buildYamlTransformer()
$this->buildYamlTransformer(),
$this->buildAnnotationTransformer(),
]);

return $config;
Expand Down Expand Up @@ -118,11 +123,7 @@ protected function buildYamlTransformer()
*/
public function buildStaticTransformer()
{
return new PrivateStaticTransformer(function () {
return ClassLoader::inst()
->getManifest()
->getClassNames();
});
return new PrivateStaticTransformer($this->getClassResolver());
}

/**
Expand Down Expand Up @@ -184,4 +185,34 @@ function ($name, $value = null) use ($envvarset, $constantdefined) {
return ModuleLoader::inst()->getManifest()->moduleExists($module);
});
}

public function buildAnnotationTransformer(): AnnotationTransformer
{
return new AnnotationTransformer(
$this->getClassResolver(),
$this->getAnnotationDefinitions()
);
}

/**
* @return callable
*/
protected function getClassResolver(): callable
{
return function () {
return ClassLoader::inst()
->getManifest()
->getClassNames();
};
}

/**
* @return AnnotationDefinitionInterface[]
*/
protected function getAnnotationDefinitions(): array
{
return array_map(function($className) {
return new $className;
}, ClassInfo::implementorsOf(AnnotationDefinitionInterface::class));
}
}