forked from alekseykuleshov/rocket-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAvatar.php
100 lines (86 loc) · 1.79 KB
/
Avatar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace ATDev\RocketChat\Users;
/**
* User new avatar class
*/
abstract class Avatar
{
/** @var boolean Indicates if source is file or domain */
const IS_FILE = null;
/** @var string Source of new avatar, domain or file */
private $source;
/** @var string|null Error message, empty if no error, some text if any */
private $error;
/**
* Class constructor
*
* @param string|null $source
*/
public function __construct($source = null)
{
if (!empty($source)) {
$this->setSource($source);
}
}
/**
* Sets source of new user avatar
*
* @param string $source
*
* @return \ATDev\RocketChat\Users\Avatar
*/
public function setSource($source)
{
if (!(is_null($source) || is_string($source))) {
$this->setError("Invalid avatar source");
} else {
$this->source = $source;
}
return $this;
}
/**
* Gets source of new user avatar
*
* @return string
*/
public function getSource()
{
return $this->source;
}
/**
* Gets error
*
* @return string
*/
public function getError()
{
return $this->error;
}
/**
* Sets error
*
* @param string $error
*
* @return \ATDev\RocketChat\Users\Avatar
*/
private function setError($error)
{
$this->error = $error;
}
}
/**
* User new avatar from file class
*/
class AvatarFromFile extends Avatar
{
/** @var boolean Indicates if source is file or domain */
const IS_FILE = true;
}
/**
* User new avatar from domain class
*/
class AvatarFromDomain extends Avatar
{
/** @var boolean Indicates if source is file or domain */
const IS_FILE = false;
}