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)
|
2014-09-10 17:42:39 +02:00
|
|
|
$validator->validateUserName($this->userName);
|
2014-09-09 19:38:16 +02:00
|
|
|
|
2014-09-10 17:42:39 +02:00
|
|
|
if ($this->password !== null)
|
|
|
|
$validator->validatePassword($this->password);
|
2014-09-09 19:38:16 +02:00
|
|
|
|
2014-09-10 17:42:39 +02:00
|
|
|
if ($this->email !== null)
|
|
|
|
$validator->validateEmail($this->email);
|
2014-09-09 19:38:16 +02:00
|
|
|
|
2014-09-10 17:42:39 +02:00
|
|
|
if ($this->browsingSettings !== null)
|
2014-09-09 19:38:16 +02:00
|
|
|
{
|
2014-09-10 17:42:39 +02:00
|
|
|
if (!is_string($this->browsingSettings))
|
2014-09-09 19:38:16 +02:00
|
|
|
throw new \InvalidArgumentException('Browsing settings must be stringified JSON.');
|
2014-09-10 17:42:39 +02:00
|
|
|
else if (strlen($this->browsingSettings) > 2000)
|
2014-09-09 19:38:16 +02:00
|
|
|
throw new \InvalidArgumentException('Stringified browsing settings can have at most 2000 characters.');
|
|
|
|
}
|
|
|
|
}
|
2014-09-07 00:33:46 +02:00
|
|
|
}
|