/** * Gather all entities in a given directory * * Assumes PSR-0/4 compliant entity class names, and an appropriate auto-loader is installed. * * @param string $dir Directory to scan * @param string $namespace PSR base namespace for the directory * @param string $regex Filter for file matching * @return string[] */ public function locateEntities($dir, $namespace, $regex = '/^.+\\.php$/i') { $dir = str_replace('\\', '/', $dir); if (substr($dir, -1) != '/') { $dir .= '/'; } $base_len = strlen($dir); $namespace = str_replace('/', '\\', $namespace); if (substr($namespace, -1) != '\\') { $namespace .= '\\'; } $normaliser = $this->getNormaliser(); $iterator = new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir)), $regex, \RecursiveRegexIterator::GET_MATCH); $out = []; foreach ($iterator as $fn => $data) { $suffix = str_replace('/', '\\', substr($fn, $base_len)); $class = $normaliser($namespace . $suffix); if (!class_exists($class)) { continue; } if ($this->entity_manager) { try { $this->entity_manager->getMapper()->getEntityMetadata($class); } catch (\Exception $e) { continue; } } $out[] = $class; } return $out; }