diff --git a/composer.json b/composer.json index 3f4dc30..990257f 100644 --- a/composer.json +++ b/composer.json @@ -12,14 +12,17 @@ "symfony/filesystem": "^7.0", "symfony/process": "^7.0", "symfony/http-client": "^7.0", - "phpseclib/phpseclib": "^3.0" + "symfony/property-access": "^7.0", + "phpseclib/phpseclib": "^3.0", + "phpdocumentor/reflection-docblock": "^5.3" }, "require-dev": { "phpunit/phpunit": "^11.0", "phpstan/phpstan": "^1.10", "rector/rector": "^1.0", "mockery/mockery": "^1.3", - "friendsofphp/php-cs-fixer": "^3.13" + "friendsofphp/php-cs-fixer": "^3.13", + "symfony/var-dumper": "^7.0" }, "license": "MIT", "authors": [ diff --git a/composer.lock b/composer.lock index 6891483..6a2073b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,55 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "68eecfad1f6488da5efaa5cc65127ed6", + "content-hash": "fb39170dae439e70e7897689f54dbe8b", "packages": [ + { + "name": "doctrine/deprecations", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/doctrine/deprecations.git", + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9", + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" + }, + "suggest": { + "psr/log": "Allows logging deprecations via PSR-3 logger implementation" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", + "homepage": "https://www.doctrine-project.org/", + "support": { + "issues": "https://github.com/doctrine/deprecations/issues", + "source": "https://github.com/doctrine/deprecations/tree/1.1.3" + }, + "time": "2024-01-30T19:34:25+00:00" + }, { "name": "paragonie/constant_time_encoding", "version": "v2.6.3", @@ -123,6 +170,174 @@ }, "time": "2020-10-15T08:29:30+00:00" }, + { + "name": "phpdocumentor/reflection-common", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b", + "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-2.x": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", + "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x" + }, + "time": "2020-06-27T09:03:43+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "5.3.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", + "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "php": "^7.2 || ^8.0", + "phpdocumentor/reflection-common": "^2.2", + "phpdocumentor/type-resolver": "^1.3", + "webmozart/assert": "^1.9.1" + }, + "require-dev": { + "mockery/mockery": "~1.3.2", + "psalm/phar": "^4.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + }, + { + "name": "Jaap van Otterdijk", + "email": "account@ijaap.nl" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0" + }, + "time": "2021-10-19T17:43:47+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "1.8.2", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "153ae662783729388a584b4361f2545e4d841e3c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/153ae662783729388a584b4361f2545e4d841e3c", + "reference": "153ae662783729388a584b4361f2545e4d841e3c", + "shasum": "" + }, + "require": { + "doctrine/deprecations": "^1.0", + "php": "^7.3 || ^8.0", + "phpdocumentor/reflection-common": "^2.0", + "phpstan/phpdoc-parser": "^1.13" + }, + "require-dev": { + "ext-tokenizer": "*", + "phpbench/phpbench": "^1.2", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-phpunit": "^1.1", + "phpunit/phpunit": "^9.5", + "rector/rector": "^0.13.9", + "vimeo/psalm": "^4.25" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-1.x": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "support": { + "issues": "https://github.com/phpDocumentor/TypeResolver/issues", + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.2" + }, + "time": "2024-02-23T11:10:43+00:00" + }, { "name": "phpseclib/phpseclib", "version": "3.0.37", @@ -233,6 +448,53 @@ ], "time": "2024-03-03T02:14:58+00:00" }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.26.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "231e3186624c03d7e7c890ec662b81e6b0405227" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/231e3186624c03d7e7c890ec662b81e6b0405227", + "reference": "231e3186624c03d7e7c890ec662b81e6b0405227", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.26.0" + }, + "time": "2024-02-23T16:05:55+00:00" + }, { "name": "psr/container", "version": "2.0.2", @@ -1389,6 +1651,165 @@ ], "time": "2024-02-22T20:27:20+00:00" }, + { + "name": "symfony/property-access", + "version": "v7.0.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/property-access.git", + "reference": "44e3746d4de8d0961a44ee332c74dd0918266127" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/property-access/zipball/44e3746d4de8d0961a44ee332c74dd0918266127", + "reference": "44e3746d4de8d0961a44ee332c74dd0918266127", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/property-info": "^6.4|^7.0" + }, + "require-dev": { + "symfony/cache": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\PropertyAccess\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides functions to read and write from/to an object or array using a simple string notation", + "homepage": "https://symfony.com", + "keywords": [ + "access", + "array", + "extraction", + "index", + "injection", + "object", + "property", + "property-path", + "reflection" + ], + "support": { + "source": "https://github.com/symfony/property-access/tree/v7.0.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-02-16T13:44:10+00:00" + }, + { + "name": "symfony/property-info", + "version": "v7.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/property-info.git", + "reference": "e160f92ea827243abf2dbf36b8460b1377194406" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/property-info/zipball/e160f92ea827243abf2dbf36b8460b1377194406", + "reference": "e160f92ea827243abf2dbf36b8460b1377194406", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/string": "^6.4|^7.0" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "<5.2", + "phpdocumentor/type-resolver": "<1.5.1", + "symfony/dependency-injection": "<6.4", + "symfony/serializer": "<6.4" + }, + "require-dev": { + "phpdocumentor/reflection-docblock": "^5.2", + "phpstan/phpdoc-parser": "^1.0", + "symfony/cache": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/serializer": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\PropertyInfo\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kévin Dunglas", + "email": "dunglas@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Extracts information about PHP class' properties using metadata of popular sources", + "homepage": "https://symfony.com", + "keywords": [ + "doctrine", + "phpdoc", + "property", + "symfony", + "type", + "validator" + ], + "support": { + "source": "https://github.com/symfony/property-info/tree/v7.0.3" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-01-23T15:02:46+00:00" + }, { "name": "symfony/serializer", "version": "v7.0.4", @@ -1722,6 +2143,64 @@ } ], "time": "2024-01-23T15:02:46+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.11.0", + "source": { + "type": "git", + "url": "https://github.com/webmozarts/assert.git", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "php": "^7.2 || ^8.0" + }, + "conflict": { + "phpstan/phpstan": "<0.12.20", + "vimeo/psalm": "<4.6.1 || 4.6.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.5.13" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.10-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.11.0" + }, + "time": "2022-06-03T18:03:27+00:00" } ], "packages-dev": [ @@ -4217,6 +4696,89 @@ ], "time": "2024-01-23T15:02:46+00:00" }, + { + "name": "symfony/var-dumper", + "version": "v7.0.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-dumper.git", + "reference": "e03ad7c1535e623edbb94c22cc42353e488c6670" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/e03ad7c1535e623edbb94c22cc42353e488c6670", + "reference": "e03ad7c1535e623edbb94c22cc42353e488c6670", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/console": "<6.4" + }, + "require-dev": { + "ext-iconv": "*", + "symfony/console": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/process": "^6.4|^7.0", + "symfony/uid": "^6.4|^7.0", + "twig/twig": "^3.0.4" + }, + "bin": [ + "Resources/bin/var-dump-server" + ], + "type": "library", + "autoload": { + "files": [ + "Resources/functions/dump.php" + ], + "psr-4": { + "Symfony\\Component\\VarDumper\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides mechanisms for walking through any arbitrary PHP variable", + "homepage": "https://symfony.com", + "keywords": [ + "debug", + "dump" + ], + "support": { + "source": "https://github.com/symfony/var-dumper/tree/v7.0.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-02-15T11:33:06+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.3", diff --git a/src/Automate/Command/LocalDeployCommand.php b/src/Automate/Command/LocalDeployCommand.php index 7cd11ab..3a693e0 100644 --- a/src/Automate/Command/LocalDeployCommand.php +++ b/src/Automate/Command/LocalDeployCommand.php @@ -31,7 +31,7 @@ )] class LocalDeployCommand extends BaseCommand { - protected function configure() + protected function configure(): void { $this ->addArgument('path', InputArgument::REQUIRED, "Project's local path") diff --git a/src/Automate/Configuration.php b/src/Automate/Configuration.php index bbe5df4..a966c20 100644 --- a/src/Automate/Configuration.php +++ b/src/Automate/Configuration.php @@ -75,7 +75,7 @@ private function addPlatformsNode(): NodeDefinition ->arrayPrototype() ->children() ->scalarNode('default_branch')->isRequired()->cannotBeEmpty()->end() - ->integerNode('max_releases')->end() + ->integerNode('max_releases')->defaultValue(5)->end() ->append($this->addServersNode()) ->end() ->end(); @@ -98,7 +98,7 @@ private function addServersNode(): NodeDefinition ->scalarNode('ssh_key')->cannotBeEmpty()->end() ->scalarNode('path')->isRequired()->cannotBeEmpty()->end() ->scalarNode('shared_path')->cannotBeEmpty()->end() - ->integerNode('port')->end() + ->integerNode('port')->defaultValue(22)->end() ->end() ->end(); } diff --git a/src/Automate/Loader.php b/src/Automate/Loader.php index 34cf0d9..755eade 100644 --- a/src/Automate/Loader.php +++ b/src/Automate/Loader.php @@ -12,11 +12,12 @@ namespace Automate; use Automate\Model\Project; -use Automate\Serializer\CommandDenormalizer; -use Automate\Serializer\PlatformDenormalizer; -use Automate\Serializer\ProjectDenormalizer; -use Automate\Serializer\ServerDenormalizer; use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; +use Symfony\Component\Serializer\Encoder\YamlEncoder; +use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter; +use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; +use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; use Symfony\Component\Yaml\Yaml; @@ -43,13 +44,26 @@ public function load(string $path): Project $processedConfiguration = $processor->processConfiguration($configuration, [$data]); - $serializer = new Serializer([ - new ProjectDenormalizer(), - new PlatformDenormalizer(), - new ServerDenormalizer(), - new CommandDenormalizer(), - ]); + foreach ($processedConfiguration['platforms'] as $platformName => $platform) { + $processedConfiguration['platforms'][$platformName]['name'] = $platformName; + foreach ($platform['servers'] as $serverName => $server) { + $processedConfiguration['platforms'][$platformName]['servers'][$serverName]['name'] = $serverName; + } + } + + return $this->getSerializer()->denormalize($processedConfiguration, Project::class); + } + + private function getSerializer(): Serializer + { + $objectNormalizer = new ObjectNormalizer( + nameConverter: new CamelCaseToSnakeCaseNameConverter(), + propertyTypeExtractor: new PhpDocExtractor() + ); - return $serializer->denormalize($processedConfiguration, Project::class); + return new Serializer( + [$objectNormalizer, new ArrayDenormalizer()], + [new YamlEncoder()] + ); } } diff --git a/src/Automate/Model/Command.php b/src/Automate/Model/Command.php index 5ca6dc6..cd6f11f 100644 --- a/src/Automate/Model/Command.php +++ b/src/Automate/Model/Command.php @@ -11,17 +11,16 @@ namespace Automate\Model; -/** - * Command configuration. - */ class Command { - private ?string $cmd = null; - /** - * @var null|string[] + * @param null|string[] $only */ - private ?array $only = null; + public function __construct( + private ?string $cmd = null, + private ?array $only = null, + ) { + } public function getCmd(): ?string { diff --git a/src/Automate/Model/Platform.php b/src/Automate/Model/Platform.php index 3502e02..7c787c6 100644 --- a/src/Automate/Model/Platform.php +++ b/src/Automate/Model/Platform.php @@ -11,25 +11,19 @@ namespace Automate\Model; -/** - * Platform configuration. - */ class Platform { - private ?string $name = null; - - private ?string $defaultBranch = null; - - private ?int $maxReleases = null; - /** - * @var Server[] + * @param array $servers */ - private ?array $servers = null; + public function __construct( + private ?string $name = null, + private ?string $defaultBranch = null, + private ?int $maxReleases = null, + private ?array $servers = null, + ) { + } - /** - * @return ?string - */ public function getName(): ?string { return $this->name; diff --git a/src/Automate/Model/Project.php b/src/Automate/Model/Project.php index 3f8f7d4..19047f4 100644 --- a/src/Automate/Model/Project.php +++ b/src/Automate/Model/Project.php @@ -11,47 +11,28 @@ namespace Automate\Model; -/** - * Project configuration. - */ class Project { - private ?string $repository = null; - - /** - * @var string[] - */ - private array $sharedFiles = []; - - /** - * @var string[] - */ - private array $sharedFolders = []; - - /** - * @var Command[] - */ - private array $preDeploy = []; - /** - * @var Command[] - */ - private array $onDeploy = []; - - /** - * @var Command[] - */ - private array $postDeploy = []; - - /** - * @var array - */ - private array $plugins = []; - - /** - * @var Platform[] - */ - private array $platforms = []; + * @param string[] $sharedFiles + * @param string[] $sharedFolders + * @param Command[] $preDeploy + * @param Command[] $onDeploy + * @param Command[] $postDeploy + * @param array $plugins + * @param array $platforms + */ + public function __construct( + private ?string $repository = null, + private array $sharedFiles = [], + private array $sharedFolders = [], + private array $preDeploy = [], + private array $onDeploy = [], + private array $postDeploy = [], + private array $plugins = [], + private array $platforms = [], + ) { + } public function getRepository(): ?string { diff --git a/src/Automate/Model/Server.php b/src/Automate/Model/Server.php index c8cb235..b1f12d7 100644 --- a/src/Automate/Model/Server.php +++ b/src/Automate/Model/Server.php @@ -11,26 +11,19 @@ namespace Automate\Model; -/** - * Server configuration. - */ class Server { - private ?string $name = null; - - private ?string $host = null; - - private ?string $user = null; - - private ?string $sshKey = null; - - private ?string $password = null; - - private ?string $path = null; - - private ?string $sharedPath = null; - - private ?int $port = null; + public function __construct( + private ?string $name = null, + private ?string $host = null, + private ?string $user = null, + private ?string $sshKey = null, + private ?string $password = null, + private ?string $path = null, + private ?string $sharedPath = null, + private ?int $port = null, + ) { + } public function getName(): ?string { diff --git a/src/Automate/Serializer/AbstractDenormalizer.php b/src/Automate/Serializer/AbstractDenormalizer.php deleted file mode 100644 index 2f03056..0000000 --- a/src/Automate/Serializer/AbstractDenormalizer.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Automate\Serializer; - -use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; -use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; -use Symfony\Component\Serializer\Normalizer\NormalizerInterface; - -abstract class AbstractDenormalizer implements DenormalizerInterface, NormalizerAwareInterface -{ - protected DenormalizerInterface|NormalizerInterface $normalizer; - - /** - * @param array $data - */ - protected function extractValue(array $data, string $key, mixed $default = null): mixed - { - return $data[$key] ?? $default; - } - - public function setNormalizer(NormalizerInterface $normalizer): void - { - $this->normalizer = $normalizer; - } -} diff --git a/src/Automate/Serializer/CommandDenormalizer.php b/src/Automate/Serializer/CommandDenormalizer.php deleted file mode 100644 index 4224c76..0000000 --- a/src/Automate/Serializer/CommandDenormalizer.php +++ /dev/null @@ -1,52 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Automate\Serializer; - -use Automate\Model\Command; -use Automate\Model\Project; - -/** - * Project Denormalizer. - * - * @see http://symfony.com/doc/current/components/serializer.html - */ -class CommandDenormalizer extends AbstractDenormalizer -{ - /** - * @param array $context - */ - public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed - { - $command = new Command(); - - $command - ->setCmd($this->extractValue($data, 'cmd')) - ->setOnly($this->extractValue($data, 'only')); - - return $command; - } - - /** - * @param array $context - */ - public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool - { - return Command::class === $type; - } - - public function getSupportedTypes(?string $format): array - { - return [ - Command::class => true, - ]; - } -} diff --git a/src/Automate/Serializer/PlatformDenormalizer.php b/src/Automate/Serializer/PlatformDenormalizer.php deleted file mode 100644 index baa16e1..0000000 --- a/src/Automate/Serializer/PlatformDenormalizer.php +++ /dev/null @@ -1,62 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Automate\Serializer; - -use Automate\Model\Platform; -use Automate\Model\Server; - -/** - * Platform Denormalizer. - * - * @see http://symfony.com/doc/current/components/serializer.html - */ -class PlatformDenormalizer extends AbstractDenormalizer -{ - /** - * @param array $context - */ - public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed - { - $platform = new Platform(); - - $platform - ->setName($this->extractValue($data, 'name')) - ->setDefaultBranch($this->extractValue($data, 'default_branch')) - ->setMaxReleases($this->extractValue($data, 'max_releases', 5)); - - $servers = $this->extractValue($data, 'servers', []); - - foreach ($servers as $name => $serverData) { - $serverData['name'] = $name; - $server = $this->normalizer->denormalize($serverData, Server::class); - - $platform->addServer($server); - } - - return $platform; - } - - /** - * @param array $context - */ - public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool - { - return Platform::class === $type; - } - - public function getSupportedTypes(?string $format): array - { - return [ - Platform::class => true, - ]; - } -} diff --git a/src/Automate/Serializer/ProjectDenormalizer.php b/src/Automate/Serializer/ProjectDenormalizer.php deleted file mode 100644 index 7116c81..0000000 --- a/src/Automate/Serializer/ProjectDenormalizer.php +++ /dev/null @@ -1,84 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Automate\Serializer; - -use Automate\Model\Command; -use Automate\Model\Platform; -use Automate\Model\Project; - -/** - * Project Denormalizer. - * - * @see http://symfony.com/doc/current/components/serializer.html - */ -class ProjectDenormalizer extends AbstractDenormalizer -{ - /** - * @param array $context - */ - public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed - { - $project = new Project(); - - $project - ->setRepository($this->extractValue($data, 'repository')) - ->setSharedFiles($this->extractValue($data, 'shared_files', [])) - ->setSharedFolders($this->extractValue($data, 'shared_folders', [])) - ->setPreDeploy($this->extractCommands($data, 'pre_deploy')) - ->setOnDeploy($this->extractCommands($data, 'on_deploy')) - ->setPostDeploy($this->extractCommands($data, 'post_deploy')) - ->setPlugins($this->extractValue($data, 'plugins', [])); - - $platforms = $this->extractValue($data, 'platforms', []); - - foreach ($platforms as $name => $platformData) { - $platformData['name'] = $name; - $platform = $this->normalizer->denormalize($platformData, Platform::class); - - $project->addPlatform($platform); - } - - return $project; - } - - /** - * @param string[] $data - * - * @return Command[] - */ - public function extractCommands(array $data, string $hookName): array - { - $commands = []; - - $data = $this->extractValue($data, $hookName, []); - foreach ($data as $item) { - $commands[] = $this->normalizer->denormalize($item, Command::class); - } - - return $commands; - } - - /** - * @param array $context - */ - public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool - { - return Project::class === $type; - } - - public function getSupportedTypes(?string $format): array - { - return [ - Project::class => true, - ]; - } -} diff --git a/src/Automate/Serializer/ServerDenormalizer.php b/src/Automate/Serializer/ServerDenormalizer.php deleted file mode 100644 index 7ce3020..0000000 --- a/src/Automate/Serializer/ServerDenormalizer.php +++ /dev/null @@ -1,57 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Automate\Serializer; - -use Automate\Model\Server; - -/** - * Server Denormalizer. - * - * @see http://symfony.com/doc/current/components/serializer.html - */ -class ServerDenormalizer extends AbstractDenormalizer -{ - /** - * @param array $context - */ - public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed - { - $server = new Server(); - - $server - ->setName($this->extractValue($data, 'name')) - ->setHost($this->extractValue($data, 'host')) - ->setUser($this->extractValue($data, 'user')) - ->setSshKey($this->extractValue($data, 'ssh_key')) - ->setPassword($this->extractValue($data, 'password', '')) - ->setPath($this->extractValue($data, 'path')) - ->setSharedPath($this->extractValue($data, 'shared_path')) - ->setPort($this->extractValue($data, 'port', 22)); - - return $server; - } - - /** - * @param array $context - */ - public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool - { - return Server::class === $type; - } - - public function getSupportedTypes(?string $format): array - { - return [ - Server::class => true, - ]; - } -}