1 | <?php |
||
47 | class GenericAuthor implements AuthorInterface |
||
48 | { |
||
49 | /** |
||
50 | * Name |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | private $name; |
||
55 | /** |
||
56 | * Email address |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | private $email; |
||
61 | /** |
||
62 | * URL |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | private $url; |
||
67 | |||
68 | /** |
||
69 | * Generic author constructor |
||
70 | * |
||
71 | * @param string $name Name |
||
72 | * @param string $email Email address |
||
73 | * @param string $url URL |
||
74 | */ |
||
75 | 6 | public function __construct($name, $email = null, $url = null) |
|
81 | |||
82 | /** |
||
83 | * Unserialize the string representation of this property |
||
84 | * |
||
85 | * @param string $str Serialized property |
||
86 | * @return SerializablePropertyInterface Property |
||
87 | * @throws InvalidArgumentException If the generic author is invalid |
||
88 | */ |
||
89 | 6 | public static function unserialize($str) |
|
90 | { |
||
91 | // If the author serialization is invalid |
||
92 | 6 | if (!strlen(trim($str)) || |
|
93 | 6 | !preg_match("%^([^\<]+)?(?:\s+\<([^\>]+)\>)?(?:\s+\(([^\)]+)\))?$%", $str, $author) |
|
94 | 6 | ) { |
|
95 | throw new InvalidArgumentException( |
||
96 | sprintf('Invalid generic author "%s"', $str), |
||
97 | InvalidArgumentException::INVALID_GENERIC_AUTHOR |
||
98 | ); |
||
99 | } |
||
100 | |||
101 | 6 | $author = array_pad($author, 4, null); |
|
102 | 6 | return new static($author[1], $author[2], $author[3]); |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * Return a signature uniquely representing this author |
||
107 | * |
||
108 | * @return string Author signature |
||
109 | */ |
||
110 | 5 | public function getSignature() |
|
114 | |||
115 | /** |
||
116 | * Serialize the property |
||
117 | * |
||
118 | * @return mixed Property serialization |
||
119 | */ |
||
120 | 7 | public function serialize() |
|
134 | } |
||
135 |