Start implementing Trello API service

Implement name of system to import
Implement need validate data
Fix allowed system list
Start implementing Trello API service

Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
Vitor Mattos
2021-07-24 20:26:34 -03:00
committed by Julius Härtl
parent c7a37ea425
commit 202ea30090
14 changed files with 219 additions and 38 deletions

View File

@@ -67,7 +67,7 @@ class BoardImportService {
private $system = '';
/** @var null|ABoardImportService */
private $systemInstance;
/** @var string[] */
/** @var array */
private $allowedSystems = [];
/**
* Data object created from config JSON
@@ -142,7 +142,9 @@ class BoardImportService {
}
public function validateSystem(): void {
if (!in_array($this->getSystem(), $this->getAllowedImportSystems())) {
$allowedSystems = $this->getAllowedImportSystems();
$allowedSystems = array_column($allowedSystems, 'internalName');
if (!in_array($this->getSystem(), $allowedSystems)) {
throw new NotFoundException('Invalid system');
}
}
@@ -173,9 +175,23 @@ class BoardImportService {
}
return true;
});
$allowedSystems = array_map(function ($name) {
preg_match('/\/BoardImport(?<system>\w+)Service\.php$/', $name, $matches);
return lcfirst($matches['system']);
$allowedSystems = array_map(function ($filename) {
preg_match('/\/(?<class>BoardImport(?<system>\w+)Service)\.php$/', $filename, $matches);
$className = 'OCA\Deck\Service\\'.$matches['class'];
if (!class_exists($className)) {
/** @psalm-suppress UnresolvableInclude */
require_once $name;
}
/** @psalm-suppress InvalidPropertyFetch */
$name = $className::$name;
if (empty($name)) {
$name = lcfirst($matches['system']);
}
return [
'name' => $name,
'class' => $className,
'internalName' => lcfirst($matches['system'])
];
}, $allowedSystems);
$this->allowedSystems = array_values($allowedSystems);
}