2014-09-07 00:33:46 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\FormData;
|
|
|
|
|
2014-09-09 19:38:16 +02:00
|
|
|
class UserEditFormData implements \Szurubooru\IValidatable
|
2014-09-07 00:33:46 +02:00
|
|
|
{
|
|
|
|
public $userName;
|
|
|
|
public $email;
|
|
|
|
public $accessRank;
|
|
|
|
public $password;
|
|
|
|
public $avatarStyle;
|
2014-09-07 14:50:16 +02:00
|
|
|
public $browsingSettings;
|
2014-09-07 00:33:46 +02:00
|
|
|
|
|
|
|
public function __construct($inputReader = null)
|
|
|
|
{
|
|
|
|
if ($inputReader !== null)
|
|
|
|
{
|
|
|
|
$this->userName = $inputReader->userName;
|
|
|
|
$this->email = $inputReader->email;
|
|
|
|
$this->password = $inputReader->password;
|
|
|
|
$this->accessRank = $inputReader->accessRank;
|
|
|
|
$this->avatarStyle = $inputReader->avatarStyle;
|
|
|
|
$this->avatarContent = $inputReader->avatarContent;
|
2014-09-07 14:50:16 +02:00
|
|
|
$this->browsingSettings = $inputReader->browsingSettings;
|
2014-09-07 00:33:46 +02:00
|
|
|
}
|
|
|
|
}
|
2014-09-09 19:38:16 +02:00
|
|
|
|
|
|
|
public function validate(\Szurubooru\Validator $validator)
|
|
|
|
{
|
|
|
|
if ($this->userName !== null)
|
|
|
|
$this->validator->validateUserName($formData->userName);
|
|
|
|
|
|
|
|
if ($formData->password !== null)
|
|
|
|
$this->validator->validatePassword($formData->password);
|
|
|
|
|
|
|
|
if ($formData->email !== null)
|
|
|
|
$this->validator->validateEmail($formData->email);
|
|
|
|
|
|
|
|
if ($formData->browsingSettings !== null)
|
|
|
|
{
|
|
|
|
if (!is_string($formData->browsingSettings))
|
|
|
|
throw new \InvalidArgumentException('Browsing settings must be stringified JSON.');
|
|
|
|
else if (strlen($formData->browsingSettings) > 2000)
|
|
|
|
throw new \InvalidArgumentException('Stringified browsing settings can have at most 2000 characters.');
|
|
|
|
}
|
|
|
|
}
|
2014-09-07 00:33:46 +02:00
|
|
|
}
|