From a9ee0cb6d231ca84f9622ff1eb1ced6581a91578 Mon Sep 17 00:00:00 2001 From: rldhont Date: Fri, 4 Jul 2025 20:42:49 +0200 Subject: [PATCH 1/4] PHP: Well deprecate lizmapRepository class The lizmapRepository class now extends \Lizmap\Project\Repository. --- .../lizmap/classes/lizmapRepository.class.php | 180 +----------------- .../modules/lizmap/lib/Project/Repository.php | 9 +- 2 files changed, 8 insertions(+), 181 deletions(-) diff --git a/lizmap/modules/lizmap/classes/lizmapRepository.class.php b/lizmap/modules/lizmap/classes/lizmapRepository.class.php index 757e23beec..48dfb5dd43 100644 --- a/lizmap/modules/lizmap/classes/lizmapRepository.class.php +++ b/lizmap/modules/lizmap/classes/lizmapRepository.class.php @@ -1,8 +1,5 @@ array( - 'fieldType' => 'text', - 'required' => true, - ), - 'label' => array( - 'fieldType' => 'text', - 'required' => true, - ), - 'allowUserDefinedThemes' => array( - 'fieldType' => 'checkbox', - 'required' => false, - ), - 'accessControlAllowOrigin' => array( - 'fieldType' => 'text', - 'required' => false, - ), - ); - - /** - * @var Repository The repository instance - */ - protected $repo; - - /** - * lizmapRepository Constructor - * Do not call it, if you want to instanciate a lizmapRepository, you should - * do it with the lizmapServices::getLizmapRepository method. - * - * @param string $key the name of the repository - * @param array $data the repository data - * @param string $varPath the configuration files folder path - * @param mixed $context - * @param mixed $services - */ - public function __construct($key, $data, $varPath, $context, $services) - { - $this->repo = new Repository($key, $data, $varPath, $context, $services); - } - - public function getKey() - { - return $this->repo->getKey(); - } - - public function getPath() - { - return $this->repo->getPath(); - } - - public function getOriginalPath() - { - return $this->repo->getOriginalPath(); - } - - public function getLabel() - { - return $this->repo->getLabel(); - } - - public function allowUserDefinedThemes() - { - return $this->repo->allowUserDefinedThemes(); - } - - public static function getProperties() - { - return self::$properties; - } - - public static function getRepoProperties() - { - return self::$propertiesOptions; - } - - public function getPropertiesOptions() - { - return $this->repo::getPropertiesOptions(); - } - - public function getData($key) - { - return $this->repo->getData($key); - } - - /** - * Update a repository in a \Jelix\IniFile\IniModifier object. - * - * @param array $data the repository data - * @param IniModifier $ini the object to edit the ini file - * - * @return bool true if there is at least one valid data in $data - */ - public function update($data, $ini) - { - return $this->repo->update($data, $ini); - } - - /** - * Get a project by key. - * - * @param string $key the project key - * @param bool $keepReference if we need to keep reference in projectInstances - * - * @return null|Project null if it does not exist - */ - public function getProject($key, $keepReference = true) - { - return $this->repo->getProject($key, $keepReference); - } - - /** - * Get the repository projects. - * - * @return Project[] - */ - public function getProjects() - { - return $this->repo->getProjects(); - } - - /** - * Get the repository projects metadata. - * - * @param bool $checkAcl If the ACL must be checked, according to the current user, default to true - * - * @return ProjectMetadata[] - */ - public function getProjectsMetadata($checkAcl = true) - { - return $this->repo->getProjectsMetadata($checkAcl); - } - - public function getProjectsMainData() - { - return $this->repo->getProjectsMainData(); - } - - /** - * Return the value of the Access-Control-Allow-Origin HTTP header. - * - * @param $referer The referer - * - * @return string the value of the ACAO header. If empty, the header should not be set. - */ - public function getACAOHeaderValue($referer) - { - return $this->repo->getACAOHeaderValue($referer); - } - - public function hasValidPath() - { - return $this->repo->getPath() !== false; - } -} +class lizmapRepository extends Repository {} diff --git a/lizmap/modules/lizmap/lib/Project/Repository.php b/lizmap/modules/lizmap/lib/Project/Repository.php index f7ce0ab4b8..7535e767a7 100644 --- a/lizmap/modules/lizmap/lib/Project/Repository.php +++ b/lizmap/modules/lizmap/lib/Project/Repository.php @@ -215,14 +215,19 @@ public function getOriginalPath() return $this->data['path']; } + public function hasValidPath(): bool + { + return $this->getPath() !== false; + } + public static function getProperties() { return self::$properties; } - public function getRepoProperties() + public static function getRepoProperties() { - return self::$properties; + return self::$propertiesOptions; } public static function getPropertiesOptions() From 0f4f7b75abd62ce2b1acd992a3ed7d90a5eb5a35 Mon Sep 17 00:00:00 2001 From: rldhont Date: Sun, 6 Jul 2025 10:20:39 +0200 Subject: [PATCH 2/4] PHP: docstring and lint Repository --- .../modules/lizmap/lib/Project/Repository.php | 77 +++++++++++++++---- tests/units/classes/Project/ProjectTest.php | 4 +- 2 files changed, 64 insertions(+), 17 deletions(-) diff --git a/lizmap/modules/lizmap/lib/Project/Repository.php b/lizmap/modules/lizmap/lib/Project/Repository.php index 7535e767a7..f5235e1575 100644 --- a/lizmap/modules/lizmap/lib/Project/Repository.php +++ b/lizmap/modules/lizmap/lib/Project/Repository.php @@ -18,7 +18,9 @@ class Repository { /** - * services properties. + * Repository properties. + * + * @var string[] */ private static $properties = array( 'label', @@ -28,7 +30,11 @@ class Repository ); /** - * services properties options. + * Repository properties options. + * + * @var array> + * + * @phpstan-var array */ private static $propertiesOptions = array( 'label' => array( @@ -51,26 +57,38 @@ class Repository /** * Lizmap repository key. + * + * @var string */ private $key = ''; /** * Lizmap repository configuration data. + * + * @var array */ private $data = array(); /** - * @var Project[] list of projects. keys are projects names + * @var array list of projects instances. keys are projects names */ protected $projectInstances = array(); /** * The configuration files folder path. + * + * @var string */ private $varPath = ''; + /** + * @var \lizmapServices + */ protected $services; + /** + * @var AppContextInterface + */ protected $appContext; /** @@ -103,7 +121,7 @@ public function __construct($key, $data, $varPath, $services, $appContext) /** * @return string the technical name of the repository */ - public function getKey() + public function getKey(): string { return $this->key; } @@ -113,7 +131,7 @@ public function getKey() * * @return string the repository label */ - public function getLabel() + public function getLabel(): string { return $this->getData('label'); } @@ -123,7 +141,7 @@ public function getLabel() * * @return bool true if it is allowed */ - public function allowUserDefinedThemes() + public function allowUserDefinedThemes(): bool { $value = $this->getData('allowUserDefinedThemes'); if (empty($value)) { @@ -147,7 +165,7 @@ public function allowUserDefinedThemes() * * @return string the value of the ACAO header. If empty, the header should not be set. */ - public function getACAOHeaderValue($referer) + public function getACAOHeaderValue($referer): string { $origins = $this->getData('accessControlAllowOrigin'); if (!$origins || $referer == '') { @@ -173,6 +191,9 @@ public function getACAOHeaderValue($referer) return ''; } + /** + * @var null|string the cleaned path of the repository, with a trailing slash + */ protected $cleanedPath; /** @@ -210,27 +231,51 @@ public function getPath() return $this->cleanedPath; } - public function getOriginalPath() + /** + * Get the original path. + */ + public function getOriginalPath(): string { return $this->data['path']; } + /** + * Check if the repository has a valid path. + */ public function hasValidPath(): bool { return $this->getPath() !== false; } - public static function getProperties() + /** + * Get the list of properties of a repository. + * + * @return string[] + */ + public static function getProperties(): array { return self::$properties; } - public static function getRepoProperties() + /** + * Get theR repository properties options. + * + * @return array + * + * @deprecated + * @see self::getPropertiesOptions() + */ + public static function getRepoProperties(): array { return self::$propertiesOptions; } - public static function getPropertiesOptions() + /** + * Get theR repository properties options. + * + * @return array + */ + public static function getPropertiesOptions(): array { return self::$propertiesOptions; } @@ -259,7 +304,7 @@ public function getData($key) * * @return bool true if there is at least one valid data in $data */ - public function update($data, $ini) + public function update($data, $ini): bool { // Set section $section = 'repository:'.$this->key; @@ -291,6 +336,8 @@ public function update($data, $ini) * @param bool $keepReference if we need to keep reference in the repository property projectInstances * * @return null|Project null if it does not exist + * + * @throws UnknownLizmapProjectException if the project does not exist */ public function getProject($key, $keepReference = true) { @@ -320,7 +367,7 @@ public function getProject($key, $keepReference = true) * * @return Project[] */ - public function getProjects() + public function getProjects(): array { $projects = array(); $dir = $this->getPath(); @@ -370,7 +417,7 @@ public function getProjects() * * @return ProjectMetadata[] */ - public function getProjectsMetadata($checkAcl = true) + public function getProjectsMetadata($checkAcl = true): array { $data = array(); $dir = $this->getPath(); @@ -422,7 +469,7 @@ public function getProjectsMetadata($checkAcl = true) * * @return ProjectMainData[] */ - public function getProjectsMainData() + public function getProjectsMainData(): array { $data = array(); $dir = $this->getPath(); diff --git a/tests/units/classes/Project/ProjectTest.php b/tests/units/classes/Project/ProjectTest.php index 6e04b76130..80cdcfc951 100644 --- a/tests/units/classes/Project/ProjectTest.php +++ b/tests/units/classes/Project/ProjectTest.php @@ -96,7 +96,7 @@ public function testGetRelativeQgisPath($relative, $root, $file, $expectedPath): null ); $proj = new ProjectForTests(); - $proj->setRepo(new Project\Repository(null, array('path' => ''), null, null, null)); + $proj->setRepo(new Project\Repository('key', array('path' => ''), null, null, null)); $proj->setServices($services); $proj->setFile($file, 0, 0); $path = $proj->getRelativeQgisPath(); @@ -218,7 +218,7 @@ public function testHasEditionLayers($editionLayers, $acl, $unset, $expectedRet) $eLayers->{$key} = clone $obj; } $config = new Project\ProjectConfig((object) array('editionLayers' => $eLayers)); - $rep = new Project\Repository(null, array(), null, null, null); + $rep = new Project\Repository('key', array(), null, null, null); $context = new ContextForTests(); $context->setResult($acl); $proj = new ProjectForTests($context); From 3955d4fa253a8b68641fcec0cefccd984e6c6774 Mon Sep 17 00:00:00 2001 From: rldhont Date: Sun, 6 Jul 2025 14:53:42 +0200 Subject: [PATCH 3/4] Does not use lizmapRepository any more --- .../admin_api/controllers/project_rest.classic.php | 9 +++++---- lizmap/modules/lizmap/classes/lizmap.class.php | 10 +++++----- lizmap/modules/lizmap/classes/lizmapServices.class.php | 7 ++++--- lizmap/modules/lizmap/controllers/edition.classic.php | 3 ++- lizmap/modules/lizmap/controllers/service.classic.php | 3 ++- phpstan-baseline.neon | 5 ----- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lizmap/modules/admin_api/controllers/project_rest.classic.php b/lizmap/modules/admin_api/controllers/project_rest.classic.php index 69455cfab7..e32cc402d7 100644 --- a/lizmap/modules/admin_api/controllers/project_rest.classic.php +++ b/lizmap/modules/admin_api/controllers/project_rest.classic.php @@ -10,6 +10,7 @@ */ use Lizmap\App\VersionTools; +use Lizmap\Project\Repository; use LizmapApi\ApiException; use LizmapApi\Credentials; use LizmapApi\Error; @@ -65,8 +66,8 @@ public function get(): object /** * Return a list of available projects and their basic information. * - * @param jResponseJson $rep response to fill - * @param lizmapRepository $repo repository + * @param jResponseJson $rep response to fill + * @param Repository $repo repository * * @return object a JSON response object containing projects */ @@ -91,8 +92,8 @@ protected function getProjList($rep, $repo) /** * Return detailed information and user rights. * - * @param jResponseJson $rep response to fill - * @param lizmapRepository $repo repository + * @param jResponseJson $rep response to fill + * @param Repository $repo repository * * @return object a JSON response object containing a specific repository with rights */ diff --git a/lizmap/modules/lizmap/classes/lizmap.class.php b/lizmap/modules/lizmap/classes/lizmap.class.php index d9de577829..633a20874f 100644 --- a/lizmap/modules/lizmap/classes/lizmap.class.php +++ b/lizmap/modules/lizmap/classes/lizmap.class.php @@ -36,7 +36,7 @@ class lizmap protected static $repositories = array(); /** - * @var lizmapRepository[] list of repository instances. keys are repository names + * @var Repository[] list of repository instances. keys are repository names */ protected static $repositoryInstances = array(); @@ -166,8 +166,8 @@ public static function getRepositoryPropertiesOptions() /** * Get the jForm for a repository. * - * @param null|lizmapRepository $rep - * @param jFormsBase $form + * @param null|Repository $rep + * @param jFormsBase $form * * @return jFormsBase */ @@ -259,7 +259,7 @@ public static function constructRepositoryForm($rep, $form) * * @param string $key Key of the repository to get * - * @return null|lizmapRepository + * @return null|Repository */ public static function getRepository($key) { @@ -286,7 +286,7 @@ public static function getRepository($key) * @param string $key the repository name * @param array $data list of properties for the repository * - * @return null|lizmapRepository + * @return null|Repository */ public static function createRepository($key, $data) { diff --git a/lizmap/modules/lizmap/classes/lizmapServices.class.php b/lizmap/modules/lizmap/classes/lizmapServices.class.php index 663d49e269..fc84f31975 100644 --- a/lizmap/modules/lizmap/classes/lizmapServices.class.php +++ b/lizmap/modules/lizmap/classes/lizmapServices.class.php @@ -1,5 +1,6 @@ varPath, $this, $this->appContext); + return new Repository($key, $data, $this->varPath, $this, $this->appContext); } } diff --git a/lizmap/modules/lizmap/controllers/edition.classic.php b/lizmap/modules/lizmap/controllers/edition.classic.php index 69d73d48dd..304dde8e5c 100644 --- a/lizmap/modules/lizmap/controllers/edition.classic.php +++ b/lizmap/modules/lizmap/controllers/edition.classic.php @@ -14,6 +14,7 @@ use GuzzleHttp\Psr7\Utils as Psr7Utils; use Lizmap\Form; use Lizmap\Project\Project; +use Lizmap\Project\Repository; use Lizmap\Project\UnknownLizmapProjectException; use Lizmap\Request\WFSRequest; @@ -22,7 +23,7 @@ class editionCtrl extends jController /** @var null|Project */ private $project; - /** @var lizmapRepository */ + /** @var null|Repository */ private $repository; /** @var string layer id in the QGIS project file */ diff --git a/lizmap/modules/lizmap/controllers/service.classic.php b/lizmap/modules/lizmap/controllers/service.classic.php index a2c609ac15..8c1c4902a4 100644 --- a/lizmap/modules/lizmap/controllers/service.classic.php +++ b/lizmap/modules/lizmap/controllers/service.classic.php @@ -5,6 +5,7 @@ use Lizmap\App\ControllerTools; use Lizmap\Project\Project; +use Lizmap\Project\Repository; use Lizmap\Project\UnknownLizmapProjectException; use Lizmap\Request\Proxy; use Lizmap\Request\WFSRequest; @@ -30,7 +31,7 @@ class serviceCtrl extends jController protected $project; /** - * @var null|lizmapRepository + * @var null|Repository */ protected $repository; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e772f7ad4a..5a8d8f5aef 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -105,11 +105,6 @@ parameters: count: 1 path: lizmap/modules/lizmap/classes/lizmapOGCRequest.class.php - - - message: "#^Method lizmapServices\\:\\:getLizmapRepository\\(\\) should return lizmapRepository but returns false\\.$#" - count: 1 - path: lizmap/modules/lizmap/classes/lizmapServices.class.php - - message: "#^Strict comparison using \\=\\=\\= between int\\|false and '1' will always evaluate to false\\.$#" count: 1 From 709f9a20c028bac473dd111a0091f1b7f25bbbdf Mon Sep 17 00:00:00 2001 From: rldhont Date: Thu, 28 Aug 2025 12:11:36 +0200 Subject: [PATCH 4/4] PHP: Remove lizmapRepository classe --- .../lizmap/classes/lizmapRepository.class.php | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 lizmap/modules/lizmap/classes/lizmapRepository.class.php diff --git a/lizmap/modules/lizmap/classes/lizmapRepository.class.php b/lizmap/modules/lizmap/classes/lizmapRepository.class.php deleted file mode 100644 index 48dfb5dd43..0000000000 --- a/lizmap/modules/lizmap/classes/lizmapRepository.class.php +++ /dev/null @@ -1,20 +0,0 @@ -