@@ -29,7 +29,7 @@ steps of configuration.
2929
3030 $config = new Configuration;
3131 $config->setMetadataCache($metadataCache);
32- $driverImpl = new AttributeDriver(['/path/to/lib/MyProject/Entities'], true );
32+ $driverImpl = new AttributeDriver(['/path/to/lib/MyProject/Entities']);
3333 $config->setMetadataDriverImpl($driverImpl);
3434 $config->setQueryCache($queryCache);
3535
@@ -96,15 +96,59 @@ The attribute driver can be injected in the ``Doctrine\ORM\Configuration``:
9696 <?php
9797 use Doctrine\ORM\Mapping\Driver\AttributeDriver;
9898
99- $driverImpl = new AttributeDriver(['/path/to/lib/MyProject/Entities'], true );
99+ $driverImpl = new AttributeDriver(['/path/to/lib/MyProject/Entities']);
100100 $config->setMetadataDriverImpl($driverImpl);
101101
102102 The path information to the entities is required for the attribute
103103driver, because otherwise mass-operations on all entities through
104- the console could not work correctly. All of metadata drivers
105- accept either a single directory as a string or an array of
106- directories. With this feature a single driver can support multiple
107- directories of Entities.
104+ the console could not work correctly. Metadata drivers can accept either
105+ a single directory as a string or an array of directories.
106+
107+ AttributeDriver also accepts ``Doctrine\Persistence\Mapping\Driver\ClassLocator ``,
108+ allowing one to customize file discovery logic. You may choose to use Symfony Finder, or
109+ utilize directory scan with ``FileClassLocator::createFromDirectories() ``:
110+
111+ .. code-block :: php
112+
113+ <?php
114+ use Doctrine\ORM\Mapping\Driver\AttributeDriver;
115+ use Doctrine\Persistence\Mapping\Driver\FileClassLocator;
116+
117+ $paths = ['/path/to/lib/MyProject/Entities'];
118+ $classLocator = FileClassLocator::createFromDirectories($paths);
119+
120+ $driverImpl = new AttributeDriver($classLocator);
121+ $config->setMetadataDriverImpl($driverImpl);
122+
123+ With this feature, you're empowered to provide a fine-grained iterator of only necessary
124+ files to the Driver. For example, if you are using Vertical Slice architecture, you can
125+ exclude ``*Test.php ``, ``*Controller.php ``, ``*Service.php ``, etc.:
126+
127+ .. code-block :: php
128+
129+ <?php
130+ use Symfony\Component\Finder\Finder;
131+
132+ $finder = new Finder()->files()->in($paths)
133+ ->name('*.php')
134+ ->notName(['*Test.php', '*Controller.php', '*Service.php']);
135+
136+ $classLocator = new FileClassLocator($finder);
137+
138+ If you know the list of class names you want to track, use
139+ ``Doctrine\Persistence\Mapping\Driver\ClassNames ``:
140+
141+ .. code-block :: php
142+
143+ <?php
144+ use Doctrine\Persistence\Mapping\Driver\ClassNames;
145+ use App\Entity\{Article, Book};
146+
147+ $entityClasses = [Article::class, Book::class];
148+ $classLocator = new ClassNames($entityClasses);
149+
150+ $driverImpl = new AttributeDriver($classLocator);
151+ $config->setMetadataDriverImpl($driverImpl);
108152
109153 Metadata Cache (**RECOMMENDED **)
110154~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments