NameUtil::MAX_ENTITY_NAME_LENGTH; } public function nameIsNotAllowed(string $name): bool { if (in_array($name, self::ENTITY_TYPE_FORBIDDEN_NAME_LIST)) { return true; } if (in_array(strtolower($name), NameUtil::RESERVED_WORLD_LIST)) { return true; } if ($name !== Util::normalizeScopeName($name)) { return true; } return false; } public function nameIsUsed(string $name): bool { if ($this->metadata->get(['scopes', $name])) { return true; } if ($this->metadata->get(['entityDefs', $name])) { return true; } if ($this->metadata->get(['clientDefs', $name])) { return true; } if ($this->relationshipExists($name)) { return true; } if ($this->controllerExists($name)) { return true; } if ($this->serviceFactory->checkExists($name)) { return true; } if ($this->routeExists($name)) { return true; } return false; } private function routeExists(string $name): bool { foreach ($this->routeUtil->getFullList() as $route) { if ( $route->getRoute() === '/' . $name || str_starts_with($route->getRoute(), '/' . $name . '/') ) { return true; } } return false; } private function controllerExists(string $name): bool { $controllerClassName = 'Espo\\Custom\\Controllers\\' . Util::normalizeClassName($name); if (class_exists($controllerClassName)) { return true; } foreach ($this->metadata->getModuleList() as $moduleName) { $controllerClassName = 'Espo\\Modules\\' . $moduleName . '\\Controllers\\' . Util::normalizeClassName($name); if (class_exists($controllerClassName)) { return true; } } $controllerClassName = 'Espo\\Controllers\\' . Util::normalizeClassName($name); if (class_exists($controllerClassName)) { return true; } return false; } public function relationshipExists(string $name): bool { /** @var string[] $scopeList */ $scopeList = array_keys($this->metadata->get(['scopes'], [])); foreach ($scopeList as $entityType) { $relationsDefs = $this->entityManager ->getMetadata() ->get($entityType, 'relations'); if (empty($relationsDefs)) { continue; } foreach ($relationsDefs as $item) { if (empty($item['type']) || empty($item['relationName'])) { continue; } if ( $item['type'] === Entity::MANY_MANY && ucfirst($item['relationName']) === ucfirst($name) ) { return true; } } } return false; } }