From 547f6954db7d4759c8e84ca5f1af91a7d8ef10de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr> Date: Wed, 23 Mar 2022 15:45:05 +0100 Subject: [PATCH] =?UTF-8?q?Nouvelle=20m=C3=A9thode=20isImportedProperty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Service/SchemaService.php | 36 +++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Service/SchemaService.php b/src/Service/SchemaService.php index ffb6e00..692bcc4 100644 --- a/src/Service/SchemaService.php +++ b/src/Service/SchemaService.php @@ -147,7 +147,7 @@ class SchemaService extends AbstractService * * @return string[] */ - public function getImportViews() + public function getImportViews(): array { $sql = "SELECT view_name FROM USER_VIEWS WHERE view_name LIKE 'SRC_%'"; $stmt = $this->getEntityManager()->getConnection()->query($sql); @@ -167,7 +167,7 @@ class SchemaService extends AbstractService * @param string $tableName * @param string $columnName */ - public function hasColumn($tableName, $columnName) + public function hasColumn(string $tableName, string $columnName): bool { $sql = " SELECT @@ -188,7 +188,7 @@ class SchemaService extends AbstractService /** * Retourne les colonnes concernées par l'import pour une table donnée */ - public function getImportCols($tableName) + public function getImportCols($tableName): array { if (!array_key_exists($tableName, $this->importColsCache)) { $sql = " @@ -216,18 +216,18 @@ class SchemaService extends AbstractService /** * Détecte si une propriété d'une classe est importable ou non * - * @param string|\stdClass $className + * @param object|string $entity * @param string $fieldName * * @return bool */ - public function isImportedProperty($className, string $fieldName): bool + public function isImportedProperty(object|string $entity, string $fieldName): bool { - if (is_object($className)){ - $className = get_class($className); + if (is_object($entity)){ + $entity = get_class($entity); } - $metadata = $this->getEntityManager()->getClassMetadata($className); + $metadata = $this->getEntityManager()->getClassMetadata($entity); $tableName = $metadata->getTableName(); @@ -242,4 +242,24 @@ class SchemaService extends AbstractService return in_array($columnName, $importCols); } + + + + /** + * @param object|string $entity + * + * @return bool + */ + public function isImportedEntity(object|string $entity): bool + { + if (is_object($entity)){ + $entity = get_class($entity); + } + + $metadata = $this->getEntityManager()->getClassMetadata($entity); + + $tableName = $metadata->getTableName(); + + return in_array($tableName, $this->getImportTables()); + } } \ No newline at end of file -- GitLab