PHP code example of dkorzhenkov / model-with-preset-data
1. Go to this page and download the library: Download dkorzhenkov/model-with-preset-data library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dkorzhenkov / model-with-preset-data example snippets
use DKorzhenkov\ModelWithPresetData\AbstractModelWithPresetData;
use DKorzhenkov\ModelWithPresetData\Traits\ToArrayExceptNullWithJsonSerializeTrait;
use Symfony\Component\Validator\Constraints as Assert;
class Message extends AbstractModelWithPresetData implements \JsonSerializable
{
use ToArrayExceptNullWithJsonSerializeTrait;
protected string $chatUuid;
protected string $text;
protected function getRules(array $data): Assert\Collection
{
return new Assert\Collection([
'fields' => [
'chatUuid' => [
new Assert\Type(['type' => 'string']),
new Assert\NotBlank(),
new Assert\Uuid(),
],
'text' => [
new Assert\Type(['type' => 'string']),
new Assert\NotBlank(),
],
],
]);
}
}
$apiClient->pushMessage(new Message([
'chatUuid' => 'fa100d98-c260-4787-80b5-14c561034288',
'text' => 'test',
]));