@@ -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
@@ -154,15 +154,59 @@ The attribute driver can be injected in the ``Doctrine\ORM\Configuration``:
154154 <?php
155155 use Doctrine\ORM\Mapping\Driver\AttributeDriver;
156156
157- $driverImpl = new AttributeDriver(['/path/to/lib/MyProject/Entities'], true );
157+ $driverImpl = new AttributeDriver(['/path/to/lib/MyProject/Entities']);
158158 $config->setMetadataDriverImpl($driverImpl);
159159
160160 The path information to the entities is required for the attribute
161161driver, because otherwise mass-operations on all entities through
162- the console could not work correctly. All of metadata drivers
163- accept either a single directory as a string or an array of
164- directories. With this feature a single driver can support multiple
165- directories of Entities.
162+ the console could not work correctly. Metadata drivers can accept either
163+ a single directory as a string or an array of directories.
164+
165+ AttributeDriver also accepts ``Doctrine\Persistence\Mapping\Driver\ClassLocator ``,
166+ allowing one to customize file discovery logic. You may choose to use Symfony Finder, or
167+ utilize directory scan with ``FileClassLocator::createFromDirectories() ``:
168+
169+ .. code-block :: php
170+
171+ <?php
172+ use Doctrine\ORM\Mapping\Driver\AttributeDriver;
173+ use Doctrine\Persistence\Mapping\Driver\FileClassLocator;
174+
175+ $paths = ['/path/to/lib/MyProject/Entities'];
176+ $classLocator = FileClassLocator::createFromDirectories($paths);
177+
178+ $driverImpl = new AttributeDriver($classLocator);
179+ $config->setMetadataDriverImpl($driverImpl);
180+
181+ With this feature, you're empowered to provide a fine-grained iterator of only necessary
182+ files to the Driver. For example, if you are using Vertical Slice architecture, you can
183+ exclude ``*Test.php ``, ``*Controller.php ``, ``*Service.php ``, etc.:
184+
185+ .. code-block :: php
186+
187+ <?php
188+ use Symfony\Component\Finder\Finder;
189+
190+ $finder = new Finder()->files()->in($paths)
191+ ->name('*.php')
192+ ->notName(['*Test.php', '*Controller.php', '*Service.php']);
193+
194+ $classLocator = new FileClassLocator($finder);
195+
196+ If you know the list of class names you want to track, use
197+ ``Doctrine\Persistence\Mapping\Driver\ClassNames ``:
198+
199+ .. code-block :: php
200+
201+ <?php
202+ use Doctrine\Persistence\Mapping\Driver\ClassNames;
203+ use App\Entity\{Article, Book};
204+
205+ $entityClasses = [Article::class, Book::class];
206+ $classLocator = new ClassNames($entityClasses);
207+
208+ $driverImpl = new AttributeDriver($classLocator);
209+ $config->setMetadataDriverImpl($driverImpl);
166210
167211 Metadata Cache (**RECOMMENDED **)
168212~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments