Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291068

Port AnnotatedClassDiscovery to PSR-4

$
0
0

See also
#1971198-142: [meta] Drupal and PSR-0/PSR-4 Class Loading
#2033501: Explore Krautoload as a solution for PSR-4 class loading

When we switch to PSR-4, some stuff in AnnotatedClassDiscovery will need to change.
This may also imply some changes in plugin managers.

AnnotatedClassDiscovery takes an array of namespaces, each with the associated PSR-0 root paths.
With PSR-4, the associated path for a namespace has a different meaning than in PSR-0. We should no longer refer to it as a "root path".

AnnotatedClassDiscovery does then determine the plugin namespaces, by appending \\Plugin\\$subdir to each namespace.
With PSR-0, the root paths for those sub-namespaces are the same as for the parent.
With PSR-4, associated paths of the sub-namespaces are NOT the same as for the parent.

PSR-0:

<?php
   
foreach ($this->rootNamespacesIterator as $namespace => $dirs) {
     
$namespace = "$namespace\\Plugin\\views\\{$this->type}";
     
$plugin_namespaces[$namespace] = (array) $dirs;
    }
?>

PSR-4:

<?php
   
foreach ($this->rootNamespacesIterator as $namespace => $dirs) {
     
$namespace = "$namespace\\Plugin\\views\\{$this->type}";
      foreach ((array)
$dirs as $dir) {
       
$plugin_namespaces[$namespace][] = $dir . '/Plugin/views/'. $this->type;
      }
    }
?>

There is a number of places where this would need to change.
This is all technically possible, but makes our lifes slightly more difficult.

The other problem is Doctrine's AnnotationRegistry.
This class is "final", and it is meant to be used only with static methods.
And it has PSR-0 hardcoded.

AnnotationRegistry is wired up with "annotation namespaces", which is another one of those namespace arrays.
And sometimes we want to get some of the root namespaces into the annotation namespaces..

So, to summarize, we have two problems:
- Doctrine's AnnotationRegistry and its hardcoding of PSR-0.
- More complicated building of sub-namespace lists. (which we will survive)


Viewing all articles
Browse latest Browse all 291068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>