-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Implement concept for artifact migration
- Loading branch information
1 parent
fad9ebf
commit c07aa8a
Showing
52 changed files
with
2,137 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Composer package "cpsit/project-builder". | ||
* | ||
* Copyright (C) 2023 Elias Häußler <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace CPSIT\ProjectBuilder\Builder\Artifact\Migration; | ||
|
||
use CPSIT\ProjectBuilder\Helper; | ||
|
||
use function is_callable; | ||
|
||
/** | ||
* BaseVersion. | ||
* | ||
* @author Elias Häußler <[email protected]> | ||
* @license GPL-3.0-or-later | ||
*/ | ||
abstract class BaseVersion implements Version | ||
{ | ||
/** | ||
* @param array<string, mixed> $artifact | ||
* @param non-empty-string $path | ||
* @param non-empty-string|null $targetPath | ||
*/ | ||
protected function remapValue( | ||
array &$artifact, | ||
string $path, | ||
string $targetPath = null, | ||
mixed $newValue = null, | ||
): void { | ||
$currentValue = Helper\ArrayHelper::getValueByPath($artifact, $path); | ||
|
||
if (is_callable($newValue)) { | ||
$newValue = $newValue($currentValue); | ||
} elseif (null === $newValue) { | ||
$newValue = $currentValue; | ||
} | ||
|
||
if (null === $targetPath) { | ||
Helper\ArrayHelper::setValueByPath($artifact, $path, $newValue); | ||
} else { | ||
Helper\ArrayHelper::setValueByPath($artifact, $targetPath, $newValue); | ||
Helper\ArrayHelper::removeByPath($artifact, $path); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Composer package "cpsit/project-builder". | ||
* | ||
* Copyright (C) 2023 Elias Häußler <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace CPSIT\ProjectBuilder\Builder\Artifact\Migration; | ||
|
||
/** | ||
* Version. | ||
* | ||
* @author Elias Häußler <[email protected]> | ||
* @license GPL-3.0-or-later | ||
* | ||
* @internal | ||
*/ | ||
interface Version | ||
{ | ||
/** | ||
* @param array<string, mixed> $artifact | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function migrate(array $artifact): array; | ||
|
||
public static function getSourceVersion(): int; | ||
|
||
public static function getTargetVersion(): int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Composer package "cpsit/project-builder". | ||
* | ||
* Copyright (C) 2023 Elias Häußler <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace CPSIT\ProjectBuilder\Builder\Artifact\Migration; | ||
|
||
/** | ||
* Version1. | ||
* | ||
* @author Elias Häußler <[email protected]> | ||
* @license GPL-3.0-or-later | ||
*/ | ||
final class Version1 extends BaseVersion | ||
{ | ||
public function migrate(array $artifact): array | ||
{ | ||
// Silent migration from artifact.file to artifact.path | ||
// since this was wrong implemented in the first place | ||
$this->remapValue( | ||
$artifact, | ||
'artifact.file', | ||
'artifact.path', | ||
); | ||
|
||
return $artifact; | ||
} | ||
|
||
public static function getSourceVersion(): int | ||
{ | ||
return 1; | ||
} | ||
|
||
public static function getTargetVersion(): int | ||
{ | ||
return 1; | ||
} | ||
} |
Oops, something went wrong.