D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
usr
/
local
/
psa
/
admin
/
plib
/
modules
/
rest-api
/
v2
/
externals
/
Entity
/
Filename :
ExtensionInstallRequest.php
back
Copy
<?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace PleskExt\RestApi\v2\Entity; use PleskRestApi\JMS\Serializer\Annotation\Type; use PleskRestApi\Symfony\Component\Validator\Constraints as Assert; use PleskRestApi\Symfony\Component\Validator\Context\ExecutionContextInterface; class ExtensionInstallRequest { /** * Installation by Identifier. * * @Type("string") * @var string */ public $id; /** * Installation by URL. * * @Assert\Url() * @Type("string") * @var string */ public $url; /** * Installation by File. * * @Type("string") * @var string */ public $file; /** * @Assert\Callback */ public function validate(ExecutionContextInterface $context, $payload) { $types = ['id', 'url', 'file']; $choosenType = null; foreach ($types as $type) { if (!empty($this->{$type})) { if ($choosenType !== null) { $context->buildViolation("Only the one method of installation should be chosen")->atPath($type)->addViolation(); } $choosenType = $type; } } if ($choosenType === null) { $context->buildViolation("You need choose method of installation")->addViolation(); } } }