@@ -31,555 +31,555 @@ |
||
| 31 | 31 | |
| 32 | 32 | class Notification implements INotification { |
| 33 | 33 | |
| 34 | - /** @var IValidator */ |
|
| 35 | - protected $richValidator; |
|
| 36 | - |
|
| 37 | - /** @var string */ |
|
| 38 | - protected $app; |
|
| 39 | - |
|
| 40 | - /** @var string */ |
|
| 41 | - protected $user; |
|
| 42 | - |
|
| 43 | - /** @var \DateTime */ |
|
| 44 | - protected $dateTime; |
|
| 45 | - |
|
| 46 | - /** @var string */ |
|
| 47 | - protected $objectType; |
|
| 48 | - |
|
| 49 | - /** @var string */ |
|
| 50 | - protected $objectId; |
|
| 51 | - |
|
| 52 | - /** @var string */ |
|
| 53 | - protected $subject; |
|
| 54 | - |
|
| 55 | - /** @var array */ |
|
| 56 | - protected $subjectParameters; |
|
| 57 | - |
|
| 58 | - /** @var string */ |
|
| 59 | - protected $subjectParsed; |
|
| 60 | - |
|
| 61 | - /** @var string */ |
|
| 62 | - protected $subjectRich; |
|
| 63 | - |
|
| 64 | - /** @var array */ |
|
| 65 | - protected $subjectRichParameters; |
|
| 66 | - |
|
| 67 | - /** @var string */ |
|
| 68 | - protected $message; |
|
| 69 | - |
|
| 70 | - /** @var array */ |
|
| 71 | - protected $messageParameters; |
|
| 72 | - |
|
| 73 | - /** @var string */ |
|
| 74 | - protected $messageParsed; |
|
| 75 | - |
|
| 76 | - /** @var string */ |
|
| 77 | - protected $messageRich; |
|
| 78 | - |
|
| 79 | - /** @var array */ |
|
| 80 | - protected $messageRichParameters; |
|
| 81 | - |
|
| 82 | - /** @var string */ |
|
| 83 | - protected $link; |
|
| 84 | - |
|
| 85 | - /** @var string */ |
|
| 86 | - protected $icon; |
|
| 87 | - |
|
| 88 | - /** @var array */ |
|
| 89 | - protected $actions; |
|
| 90 | - |
|
| 91 | - /** @var array */ |
|
| 92 | - protected $actionsParsed; |
|
| 93 | - |
|
| 94 | - /** @var bool */ |
|
| 95 | - protected $hasPrimaryAction; |
|
| 96 | - |
|
| 97 | - /** @var bool */ |
|
| 98 | - protected $hasPrimaryParsedAction; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Constructor |
|
| 102 | - * |
|
| 103 | - * @param IValidator $richValidator |
|
| 104 | - */ |
|
| 105 | - public function __construct(IValidator $richValidator) { |
|
| 106 | - $this->richValidator = $richValidator; |
|
| 107 | - $this->app = ''; |
|
| 108 | - $this->user = ''; |
|
| 109 | - $this->dateTime = new \DateTime(); |
|
| 110 | - $this->dateTime->setTimestamp(0); |
|
| 111 | - $this->objectType = ''; |
|
| 112 | - $this->objectId = ''; |
|
| 113 | - $this->subject = ''; |
|
| 114 | - $this->subjectParameters = []; |
|
| 115 | - $this->subjectParsed = ''; |
|
| 116 | - $this->subjectRich = ''; |
|
| 117 | - $this->subjectRichParameters = []; |
|
| 118 | - $this->message = ''; |
|
| 119 | - $this->messageParameters = []; |
|
| 120 | - $this->messageParsed = ''; |
|
| 121 | - $this->messageRich = ''; |
|
| 122 | - $this->messageRichParameters = []; |
|
| 123 | - $this->link = ''; |
|
| 124 | - $this->icon = ''; |
|
| 125 | - $this->actions = []; |
|
| 126 | - $this->actionsParsed = []; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @param string $app |
|
| 131 | - * @return $this |
|
| 132 | - * @throws \InvalidArgumentException if the app id is invalid |
|
| 133 | - * @since 8.2.0 |
|
| 134 | - */ |
|
| 135 | - public function setApp($app) { |
|
| 136 | - if (!is_string($app) || $app === '' || isset($app[32])) { |
|
| 137 | - throw new \InvalidArgumentException('The given app name is invalid'); |
|
| 138 | - } |
|
| 139 | - $this->app = $app; |
|
| 140 | - return $this; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @return string |
|
| 145 | - * @since 8.2.0 |
|
| 146 | - */ |
|
| 147 | - public function getApp() { |
|
| 148 | - return $this->app; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param string $user |
|
| 153 | - * @return $this |
|
| 154 | - * @throws \InvalidArgumentException if the user id is invalid |
|
| 155 | - * @since 8.2.0 |
|
| 156 | - */ |
|
| 157 | - public function setUser($user) { |
|
| 158 | - if (!is_string($user) || $user === '' || isset($user[64])) { |
|
| 159 | - throw new \InvalidArgumentException('The given user id is invalid'); |
|
| 160 | - } |
|
| 161 | - $this->user = $user; |
|
| 162 | - return $this; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @return string |
|
| 167 | - * @since 8.2.0 |
|
| 168 | - */ |
|
| 169 | - public function getUser() { |
|
| 170 | - return $this->user; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * @param \DateTime $dateTime |
|
| 175 | - * @return $this |
|
| 176 | - * @throws \InvalidArgumentException if the $dateTime is invalid |
|
| 177 | - * @since 9.0.0 |
|
| 178 | - */ |
|
| 179 | - public function setDateTime(\DateTime $dateTime) { |
|
| 180 | - if ($dateTime->getTimestamp() === 0) { |
|
| 181 | - throw new \InvalidArgumentException('The given date time is invalid'); |
|
| 182 | - } |
|
| 183 | - $this->dateTime = $dateTime; |
|
| 184 | - return $this; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @return \DateTime |
|
| 189 | - * @since 9.0.0 |
|
| 190 | - */ |
|
| 191 | - public function getDateTime() { |
|
| 192 | - return $this->dateTime; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param string $type |
|
| 197 | - * @param string $id |
|
| 198 | - * @return $this |
|
| 199 | - * @throws \InvalidArgumentException if the object type or id is invalid |
|
| 200 | - * @since 8.2.0 - 9.0.0: Type of $id changed to string |
|
| 201 | - */ |
|
| 202 | - public function setObject($type, $id) { |
|
| 203 | - if (!is_string($type) || $type === '' || isset($type[64])) { |
|
| 204 | - throw new \InvalidArgumentException('The given object type is invalid'); |
|
| 205 | - } |
|
| 206 | - $this->objectType = $type; |
|
| 207 | - |
|
| 208 | - if (!is_int($id) && (!is_string($id) || $id === '' || isset($id[64]))) { |
|
| 209 | - throw new \InvalidArgumentException('The given object id is invalid'); |
|
| 210 | - } |
|
| 211 | - $this->objectId = (string) $id; |
|
| 212 | - return $this; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @return string |
|
| 217 | - * @since 8.2.0 |
|
| 218 | - */ |
|
| 219 | - public function getObjectType() { |
|
| 220 | - return $this->objectType; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @return string |
|
| 225 | - * @since 8.2.0 - 9.0.0: Return type changed to string |
|
| 226 | - */ |
|
| 227 | - public function getObjectId() { |
|
| 228 | - return $this->objectId; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @param string $subject |
|
| 233 | - * @param array $parameters |
|
| 234 | - * @return $this |
|
| 235 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
| 236 | - * @since 8.2.0 |
|
| 237 | - */ |
|
| 238 | - public function setSubject($subject, array $parameters = []) { |
|
| 239 | - if (!is_string($subject) || $subject === '' || isset($subject[64])) { |
|
| 240 | - throw new \InvalidArgumentException('The given subject is invalid'); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $this->subject = $subject; |
|
| 244 | - $this->subjectParameters = $parameters; |
|
| 245 | - |
|
| 246 | - return $this; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @return string |
|
| 251 | - * @since 8.2.0 |
|
| 252 | - */ |
|
| 253 | - public function getSubject() { |
|
| 254 | - return $this->subject; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @return string[] |
|
| 259 | - * @since 8.2.0 |
|
| 260 | - */ |
|
| 261 | - public function getSubjectParameters() { |
|
| 262 | - return $this->subjectParameters; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @param string $subject |
|
| 267 | - * @return $this |
|
| 268 | - * @throws \InvalidArgumentException if the subject is invalid |
|
| 269 | - * @since 8.2.0 |
|
| 270 | - */ |
|
| 271 | - public function setParsedSubject($subject) { |
|
| 272 | - if (!is_string($subject) || $subject === '') { |
|
| 273 | - throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
| 274 | - } |
|
| 275 | - $this->subjectParsed = $subject; |
|
| 276 | - return $this; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @return string |
|
| 281 | - * @since 8.2.0 |
|
| 282 | - */ |
|
| 283 | - public function getParsedSubject() { |
|
| 284 | - return $this->subjectParsed; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @param string $subject |
|
| 289 | - * @param array $parameters |
|
| 290 | - * @return $this |
|
| 291 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
| 292 | - * @since 11.0.0 |
|
| 293 | - */ |
|
| 294 | - public function setRichSubject($subject, array $parameters = []) { |
|
| 295 | - if (!is_string($subject) || $subject === '') { |
|
| 296 | - throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - $this->subjectRich = $subject; |
|
| 300 | - $this->subjectRichParameters = $parameters; |
|
| 301 | - |
|
| 302 | - return $this; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * @return string |
|
| 307 | - * @since 11.0.0 |
|
| 308 | - */ |
|
| 309 | - public function getRichSubject() { |
|
| 310 | - return $this->subjectRich; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @return array[] |
|
| 315 | - * @since 11.0.0 |
|
| 316 | - */ |
|
| 317 | - public function getRichSubjectParameters() { |
|
| 318 | - return $this->subjectRichParameters; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * @param string $message |
|
| 323 | - * @param array $parameters |
|
| 324 | - * @return $this |
|
| 325 | - * @throws \InvalidArgumentException if the message or parameters are invalid |
|
| 326 | - * @since 8.2.0 |
|
| 327 | - */ |
|
| 328 | - public function setMessage($message, array $parameters = []) { |
|
| 329 | - if (!is_string($message) || $message === '' || isset($message[64])) { |
|
| 330 | - throw new \InvalidArgumentException('The given message is invalid'); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - $this->message = $message; |
|
| 334 | - $this->messageParameters = $parameters; |
|
| 335 | - |
|
| 336 | - return $this; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * @return string |
|
| 341 | - * @since 8.2.0 |
|
| 342 | - */ |
|
| 343 | - public function getMessage() { |
|
| 344 | - return $this->message; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * @return string[] |
|
| 349 | - * @since 8.2.0 |
|
| 350 | - */ |
|
| 351 | - public function getMessageParameters() { |
|
| 352 | - return $this->messageParameters; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * @param string $message |
|
| 357 | - * @return $this |
|
| 358 | - * @throws \InvalidArgumentException if the message is invalid |
|
| 359 | - * @since 8.2.0 |
|
| 360 | - */ |
|
| 361 | - public function setParsedMessage($message) { |
|
| 362 | - if (!is_string($message) || $message === '') { |
|
| 363 | - throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
| 364 | - } |
|
| 365 | - $this->messageParsed = $message; |
|
| 366 | - return $this; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @return string |
|
| 371 | - * @since 8.2.0 |
|
| 372 | - */ |
|
| 373 | - public function getParsedMessage() { |
|
| 374 | - return $this->messageParsed; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @param string $message |
|
| 379 | - * @param array $parameters |
|
| 380 | - * @return $this |
|
| 381 | - * @throws \InvalidArgumentException if the message or parameters are invalid |
|
| 382 | - * @since 11.0.0 |
|
| 383 | - */ |
|
| 384 | - public function setRichMessage($message, array $parameters = []) { |
|
| 385 | - if (!is_string($message) || $message === '') { |
|
| 386 | - throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - $this->messageRich = $message; |
|
| 390 | - $this->messageRichParameters = $parameters; |
|
| 391 | - |
|
| 392 | - return $this; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * @return string |
|
| 397 | - * @since 11.0.0 |
|
| 398 | - */ |
|
| 399 | - public function getRichMessage() { |
|
| 400 | - return $this->messageRich; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * @return array[] |
|
| 405 | - * @since 11.0.0 |
|
| 406 | - */ |
|
| 407 | - public function getRichMessageParameters() { |
|
| 408 | - return $this->messageRichParameters; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * @param string $link |
|
| 413 | - * @return $this |
|
| 414 | - * @throws \InvalidArgumentException if the link is invalid |
|
| 415 | - * @since 8.2.0 |
|
| 416 | - */ |
|
| 417 | - public function setLink($link) { |
|
| 418 | - if (!is_string($link) || $link === '' || isset($link[4000])) { |
|
| 419 | - throw new \InvalidArgumentException('The given link is invalid'); |
|
| 420 | - } |
|
| 421 | - $this->link = $link; |
|
| 422 | - return $this; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * @return string |
|
| 427 | - * @since 8.2.0 |
|
| 428 | - */ |
|
| 429 | - public function getLink() { |
|
| 430 | - return $this->link; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * @param string $icon |
|
| 435 | - * @return $this |
|
| 436 | - * @throws \InvalidArgumentException if the icon is invalid |
|
| 437 | - * @since 11.0.0 |
|
| 438 | - */ |
|
| 439 | - public function setIcon($icon) { |
|
| 440 | - if (!is_string($icon) || $icon === '' || isset($icon[4000])) { |
|
| 441 | - throw new \InvalidArgumentException('The given icon is invalid'); |
|
| 442 | - } |
|
| 443 | - $this->icon = $icon; |
|
| 444 | - return $this; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * @return string |
|
| 449 | - * @since 11.0.0 |
|
| 450 | - */ |
|
| 451 | - public function getIcon() { |
|
| 452 | - return $this->icon; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * @return IAction |
|
| 457 | - * @since 8.2.0 |
|
| 458 | - */ |
|
| 459 | - public function createAction() { |
|
| 460 | - return new Action(); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * @param IAction $action |
|
| 465 | - * @return $this |
|
| 466 | - * @throws \InvalidArgumentException if the action is invalid |
|
| 467 | - * @since 8.2.0 |
|
| 468 | - */ |
|
| 469 | - public function addAction(IAction $action) { |
|
| 470 | - if (!$action->isValid()) { |
|
| 471 | - throw new \InvalidArgumentException('The given action is invalid'); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - if ($action->isPrimary()) { |
|
| 475 | - if ($this->hasPrimaryAction) { |
|
| 476 | - throw new \InvalidArgumentException('The notification already has a primary action'); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - $this->hasPrimaryAction = true; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - $this->actions[] = $action; |
|
| 483 | - return $this; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * @return IAction[] |
|
| 488 | - * @since 8.2.0 |
|
| 489 | - */ |
|
| 490 | - public function getActions() { |
|
| 491 | - return $this->actions; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * @param IAction $action |
|
| 496 | - * @return $this |
|
| 497 | - * @throws \InvalidArgumentException if the action is invalid |
|
| 498 | - * @since 8.2.0 |
|
| 499 | - */ |
|
| 500 | - public function addParsedAction(IAction $action) { |
|
| 501 | - if (!$action->isValidParsed()) { |
|
| 502 | - throw new \InvalidArgumentException('The given parsed action is invalid'); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - if ($action->isPrimary()) { |
|
| 506 | - if ($this->hasPrimaryParsedAction) { |
|
| 507 | - throw new \InvalidArgumentException('The notification already has a primary action'); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - $this->hasPrimaryParsedAction = true; |
|
| 511 | - |
|
| 512 | - // Make sure the primary action is always the first one |
|
| 513 | - array_unshift($this->actionsParsed, $action); |
|
| 514 | - } else { |
|
| 515 | - $this->actionsParsed[] = $action; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - return $this; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * @return IAction[] |
|
| 523 | - * @since 8.2.0 |
|
| 524 | - */ |
|
| 525 | - public function getParsedActions() { |
|
| 526 | - return $this->actionsParsed; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * @return bool |
|
| 531 | - * @since 8.2.0 |
|
| 532 | - */ |
|
| 533 | - public function isValid() { |
|
| 534 | - return |
|
| 535 | - $this->isValidCommon() |
|
| 536 | - && |
|
| 537 | - $this->getSubject() !== '' |
|
| 538 | - ; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * @return bool |
|
| 543 | - * @since 8.2.0 |
|
| 544 | - */ |
|
| 545 | - public function isValidParsed() { |
|
| 546 | - if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) { |
|
| 547 | - try { |
|
| 548 | - $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters()); |
|
| 549 | - } catch (InvalidObjectExeption $e) { |
|
| 550 | - return false; |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) { |
|
| 555 | - try { |
|
| 556 | - $this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters()); |
|
| 557 | - } catch (InvalidObjectExeption $e) { |
|
| 558 | - return false; |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return |
|
| 563 | - $this->isValidCommon() |
|
| 564 | - && |
|
| 565 | - $this->getParsedSubject() !== '' |
|
| 566 | - ; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * @return bool |
|
| 571 | - */ |
|
| 572 | - protected function isValidCommon() { |
|
| 573 | - return |
|
| 574 | - $this->getApp() !== '' |
|
| 575 | - && |
|
| 576 | - $this->getUser() !== '' |
|
| 577 | - && |
|
| 578 | - $this->getDateTime()->getTimestamp() !== 0 |
|
| 579 | - && |
|
| 580 | - $this->getObjectType() !== '' |
|
| 581 | - && |
|
| 582 | - $this->getObjectId() !== '' |
|
| 583 | - ; |
|
| 584 | - } |
|
| 34 | + /** @var IValidator */ |
|
| 35 | + protected $richValidator; |
|
| 36 | + |
|
| 37 | + /** @var string */ |
|
| 38 | + protected $app; |
|
| 39 | + |
|
| 40 | + /** @var string */ |
|
| 41 | + protected $user; |
|
| 42 | + |
|
| 43 | + /** @var \DateTime */ |
|
| 44 | + protected $dateTime; |
|
| 45 | + |
|
| 46 | + /** @var string */ |
|
| 47 | + protected $objectType; |
|
| 48 | + |
|
| 49 | + /** @var string */ |
|
| 50 | + protected $objectId; |
|
| 51 | + |
|
| 52 | + /** @var string */ |
|
| 53 | + protected $subject; |
|
| 54 | + |
|
| 55 | + /** @var array */ |
|
| 56 | + protected $subjectParameters; |
|
| 57 | + |
|
| 58 | + /** @var string */ |
|
| 59 | + protected $subjectParsed; |
|
| 60 | + |
|
| 61 | + /** @var string */ |
|
| 62 | + protected $subjectRich; |
|
| 63 | + |
|
| 64 | + /** @var array */ |
|
| 65 | + protected $subjectRichParameters; |
|
| 66 | + |
|
| 67 | + /** @var string */ |
|
| 68 | + protected $message; |
|
| 69 | + |
|
| 70 | + /** @var array */ |
|
| 71 | + protected $messageParameters; |
|
| 72 | + |
|
| 73 | + /** @var string */ |
|
| 74 | + protected $messageParsed; |
|
| 75 | + |
|
| 76 | + /** @var string */ |
|
| 77 | + protected $messageRich; |
|
| 78 | + |
|
| 79 | + /** @var array */ |
|
| 80 | + protected $messageRichParameters; |
|
| 81 | + |
|
| 82 | + /** @var string */ |
|
| 83 | + protected $link; |
|
| 84 | + |
|
| 85 | + /** @var string */ |
|
| 86 | + protected $icon; |
|
| 87 | + |
|
| 88 | + /** @var array */ |
|
| 89 | + protected $actions; |
|
| 90 | + |
|
| 91 | + /** @var array */ |
|
| 92 | + protected $actionsParsed; |
|
| 93 | + |
|
| 94 | + /** @var bool */ |
|
| 95 | + protected $hasPrimaryAction; |
|
| 96 | + |
|
| 97 | + /** @var bool */ |
|
| 98 | + protected $hasPrimaryParsedAction; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Constructor |
|
| 102 | + * |
|
| 103 | + * @param IValidator $richValidator |
|
| 104 | + */ |
|
| 105 | + public function __construct(IValidator $richValidator) { |
|
| 106 | + $this->richValidator = $richValidator; |
|
| 107 | + $this->app = ''; |
|
| 108 | + $this->user = ''; |
|
| 109 | + $this->dateTime = new \DateTime(); |
|
| 110 | + $this->dateTime->setTimestamp(0); |
|
| 111 | + $this->objectType = ''; |
|
| 112 | + $this->objectId = ''; |
|
| 113 | + $this->subject = ''; |
|
| 114 | + $this->subjectParameters = []; |
|
| 115 | + $this->subjectParsed = ''; |
|
| 116 | + $this->subjectRich = ''; |
|
| 117 | + $this->subjectRichParameters = []; |
|
| 118 | + $this->message = ''; |
|
| 119 | + $this->messageParameters = []; |
|
| 120 | + $this->messageParsed = ''; |
|
| 121 | + $this->messageRich = ''; |
|
| 122 | + $this->messageRichParameters = []; |
|
| 123 | + $this->link = ''; |
|
| 124 | + $this->icon = ''; |
|
| 125 | + $this->actions = []; |
|
| 126 | + $this->actionsParsed = []; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @param string $app |
|
| 131 | + * @return $this |
|
| 132 | + * @throws \InvalidArgumentException if the app id is invalid |
|
| 133 | + * @since 8.2.0 |
|
| 134 | + */ |
|
| 135 | + public function setApp($app) { |
|
| 136 | + if (!is_string($app) || $app === '' || isset($app[32])) { |
|
| 137 | + throw new \InvalidArgumentException('The given app name is invalid'); |
|
| 138 | + } |
|
| 139 | + $this->app = $app; |
|
| 140 | + return $this; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @return string |
|
| 145 | + * @since 8.2.0 |
|
| 146 | + */ |
|
| 147 | + public function getApp() { |
|
| 148 | + return $this->app; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param string $user |
|
| 153 | + * @return $this |
|
| 154 | + * @throws \InvalidArgumentException if the user id is invalid |
|
| 155 | + * @since 8.2.0 |
|
| 156 | + */ |
|
| 157 | + public function setUser($user) { |
|
| 158 | + if (!is_string($user) || $user === '' || isset($user[64])) { |
|
| 159 | + throw new \InvalidArgumentException('The given user id is invalid'); |
|
| 160 | + } |
|
| 161 | + $this->user = $user; |
|
| 162 | + return $this; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @return string |
|
| 167 | + * @since 8.2.0 |
|
| 168 | + */ |
|
| 169 | + public function getUser() { |
|
| 170 | + return $this->user; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * @param \DateTime $dateTime |
|
| 175 | + * @return $this |
|
| 176 | + * @throws \InvalidArgumentException if the $dateTime is invalid |
|
| 177 | + * @since 9.0.0 |
|
| 178 | + */ |
|
| 179 | + public function setDateTime(\DateTime $dateTime) { |
|
| 180 | + if ($dateTime->getTimestamp() === 0) { |
|
| 181 | + throw new \InvalidArgumentException('The given date time is invalid'); |
|
| 182 | + } |
|
| 183 | + $this->dateTime = $dateTime; |
|
| 184 | + return $this; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @return \DateTime |
|
| 189 | + * @since 9.0.0 |
|
| 190 | + */ |
|
| 191 | + public function getDateTime() { |
|
| 192 | + return $this->dateTime; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param string $type |
|
| 197 | + * @param string $id |
|
| 198 | + * @return $this |
|
| 199 | + * @throws \InvalidArgumentException if the object type or id is invalid |
|
| 200 | + * @since 8.2.0 - 9.0.0: Type of $id changed to string |
|
| 201 | + */ |
|
| 202 | + public function setObject($type, $id) { |
|
| 203 | + if (!is_string($type) || $type === '' || isset($type[64])) { |
|
| 204 | + throw new \InvalidArgumentException('The given object type is invalid'); |
|
| 205 | + } |
|
| 206 | + $this->objectType = $type; |
|
| 207 | + |
|
| 208 | + if (!is_int($id) && (!is_string($id) || $id === '' || isset($id[64]))) { |
|
| 209 | + throw new \InvalidArgumentException('The given object id is invalid'); |
|
| 210 | + } |
|
| 211 | + $this->objectId = (string) $id; |
|
| 212 | + return $this; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @return string |
|
| 217 | + * @since 8.2.0 |
|
| 218 | + */ |
|
| 219 | + public function getObjectType() { |
|
| 220 | + return $this->objectType; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @return string |
|
| 225 | + * @since 8.2.0 - 9.0.0: Return type changed to string |
|
| 226 | + */ |
|
| 227 | + public function getObjectId() { |
|
| 228 | + return $this->objectId; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @param string $subject |
|
| 233 | + * @param array $parameters |
|
| 234 | + * @return $this |
|
| 235 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
| 236 | + * @since 8.2.0 |
|
| 237 | + */ |
|
| 238 | + public function setSubject($subject, array $parameters = []) { |
|
| 239 | + if (!is_string($subject) || $subject === '' || isset($subject[64])) { |
|
| 240 | + throw new \InvalidArgumentException('The given subject is invalid'); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $this->subject = $subject; |
|
| 244 | + $this->subjectParameters = $parameters; |
|
| 245 | + |
|
| 246 | + return $this; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @return string |
|
| 251 | + * @since 8.2.0 |
|
| 252 | + */ |
|
| 253 | + public function getSubject() { |
|
| 254 | + return $this->subject; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @return string[] |
|
| 259 | + * @since 8.2.0 |
|
| 260 | + */ |
|
| 261 | + public function getSubjectParameters() { |
|
| 262 | + return $this->subjectParameters; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @param string $subject |
|
| 267 | + * @return $this |
|
| 268 | + * @throws \InvalidArgumentException if the subject is invalid |
|
| 269 | + * @since 8.2.0 |
|
| 270 | + */ |
|
| 271 | + public function setParsedSubject($subject) { |
|
| 272 | + if (!is_string($subject) || $subject === '') { |
|
| 273 | + throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
| 274 | + } |
|
| 275 | + $this->subjectParsed = $subject; |
|
| 276 | + return $this; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @return string |
|
| 281 | + * @since 8.2.0 |
|
| 282 | + */ |
|
| 283 | + public function getParsedSubject() { |
|
| 284 | + return $this->subjectParsed; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @param string $subject |
|
| 289 | + * @param array $parameters |
|
| 290 | + * @return $this |
|
| 291 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
| 292 | + * @since 11.0.0 |
|
| 293 | + */ |
|
| 294 | + public function setRichSubject($subject, array $parameters = []) { |
|
| 295 | + if (!is_string($subject) || $subject === '') { |
|
| 296 | + throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + $this->subjectRich = $subject; |
|
| 300 | + $this->subjectRichParameters = $parameters; |
|
| 301 | + |
|
| 302 | + return $this; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * @return string |
|
| 307 | + * @since 11.0.0 |
|
| 308 | + */ |
|
| 309 | + public function getRichSubject() { |
|
| 310 | + return $this->subjectRich; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * @return array[] |
|
| 315 | + * @since 11.0.0 |
|
| 316 | + */ |
|
| 317 | + public function getRichSubjectParameters() { |
|
| 318 | + return $this->subjectRichParameters; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * @param string $message |
|
| 323 | + * @param array $parameters |
|
| 324 | + * @return $this |
|
| 325 | + * @throws \InvalidArgumentException if the message or parameters are invalid |
|
| 326 | + * @since 8.2.0 |
|
| 327 | + */ |
|
| 328 | + public function setMessage($message, array $parameters = []) { |
|
| 329 | + if (!is_string($message) || $message === '' || isset($message[64])) { |
|
| 330 | + throw new \InvalidArgumentException('The given message is invalid'); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + $this->message = $message; |
|
| 334 | + $this->messageParameters = $parameters; |
|
| 335 | + |
|
| 336 | + return $this; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * @return string |
|
| 341 | + * @since 8.2.0 |
|
| 342 | + */ |
|
| 343 | + public function getMessage() { |
|
| 344 | + return $this->message; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * @return string[] |
|
| 349 | + * @since 8.2.0 |
|
| 350 | + */ |
|
| 351 | + public function getMessageParameters() { |
|
| 352 | + return $this->messageParameters; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * @param string $message |
|
| 357 | + * @return $this |
|
| 358 | + * @throws \InvalidArgumentException if the message is invalid |
|
| 359 | + * @since 8.2.0 |
|
| 360 | + */ |
|
| 361 | + public function setParsedMessage($message) { |
|
| 362 | + if (!is_string($message) || $message === '') { |
|
| 363 | + throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
| 364 | + } |
|
| 365 | + $this->messageParsed = $message; |
|
| 366 | + return $this; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @return string |
|
| 371 | + * @since 8.2.0 |
|
| 372 | + */ |
|
| 373 | + public function getParsedMessage() { |
|
| 374 | + return $this->messageParsed; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @param string $message |
|
| 379 | + * @param array $parameters |
|
| 380 | + * @return $this |
|
| 381 | + * @throws \InvalidArgumentException if the message or parameters are invalid |
|
| 382 | + * @since 11.0.0 |
|
| 383 | + */ |
|
| 384 | + public function setRichMessage($message, array $parameters = []) { |
|
| 385 | + if (!is_string($message) || $message === '') { |
|
| 386 | + throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + $this->messageRich = $message; |
|
| 390 | + $this->messageRichParameters = $parameters; |
|
| 391 | + |
|
| 392 | + return $this; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * @return string |
|
| 397 | + * @since 11.0.0 |
|
| 398 | + */ |
|
| 399 | + public function getRichMessage() { |
|
| 400 | + return $this->messageRich; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * @return array[] |
|
| 405 | + * @since 11.0.0 |
|
| 406 | + */ |
|
| 407 | + public function getRichMessageParameters() { |
|
| 408 | + return $this->messageRichParameters; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * @param string $link |
|
| 413 | + * @return $this |
|
| 414 | + * @throws \InvalidArgumentException if the link is invalid |
|
| 415 | + * @since 8.2.0 |
|
| 416 | + */ |
|
| 417 | + public function setLink($link) { |
|
| 418 | + if (!is_string($link) || $link === '' || isset($link[4000])) { |
|
| 419 | + throw new \InvalidArgumentException('The given link is invalid'); |
|
| 420 | + } |
|
| 421 | + $this->link = $link; |
|
| 422 | + return $this; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * @return string |
|
| 427 | + * @since 8.2.0 |
|
| 428 | + */ |
|
| 429 | + public function getLink() { |
|
| 430 | + return $this->link; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * @param string $icon |
|
| 435 | + * @return $this |
|
| 436 | + * @throws \InvalidArgumentException if the icon is invalid |
|
| 437 | + * @since 11.0.0 |
|
| 438 | + */ |
|
| 439 | + public function setIcon($icon) { |
|
| 440 | + if (!is_string($icon) || $icon === '' || isset($icon[4000])) { |
|
| 441 | + throw new \InvalidArgumentException('The given icon is invalid'); |
|
| 442 | + } |
|
| 443 | + $this->icon = $icon; |
|
| 444 | + return $this; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * @return string |
|
| 449 | + * @since 11.0.0 |
|
| 450 | + */ |
|
| 451 | + public function getIcon() { |
|
| 452 | + return $this->icon; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * @return IAction |
|
| 457 | + * @since 8.2.0 |
|
| 458 | + */ |
|
| 459 | + public function createAction() { |
|
| 460 | + return new Action(); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * @param IAction $action |
|
| 465 | + * @return $this |
|
| 466 | + * @throws \InvalidArgumentException if the action is invalid |
|
| 467 | + * @since 8.2.0 |
|
| 468 | + */ |
|
| 469 | + public function addAction(IAction $action) { |
|
| 470 | + if (!$action->isValid()) { |
|
| 471 | + throw new \InvalidArgumentException('The given action is invalid'); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + if ($action->isPrimary()) { |
|
| 475 | + if ($this->hasPrimaryAction) { |
|
| 476 | + throw new \InvalidArgumentException('The notification already has a primary action'); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + $this->hasPrimaryAction = true; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + $this->actions[] = $action; |
|
| 483 | + return $this; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * @return IAction[] |
|
| 488 | + * @since 8.2.0 |
|
| 489 | + */ |
|
| 490 | + public function getActions() { |
|
| 491 | + return $this->actions; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * @param IAction $action |
|
| 496 | + * @return $this |
|
| 497 | + * @throws \InvalidArgumentException if the action is invalid |
|
| 498 | + * @since 8.2.0 |
|
| 499 | + */ |
|
| 500 | + public function addParsedAction(IAction $action) { |
|
| 501 | + if (!$action->isValidParsed()) { |
|
| 502 | + throw new \InvalidArgumentException('The given parsed action is invalid'); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + if ($action->isPrimary()) { |
|
| 506 | + if ($this->hasPrimaryParsedAction) { |
|
| 507 | + throw new \InvalidArgumentException('The notification already has a primary action'); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + $this->hasPrimaryParsedAction = true; |
|
| 511 | + |
|
| 512 | + // Make sure the primary action is always the first one |
|
| 513 | + array_unshift($this->actionsParsed, $action); |
|
| 514 | + } else { |
|
| 515 | + $this->actionsParsed[] = $action; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + return $this; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * @return IAction[] |
|
| 523 | + * @since 8.2.0 |
|
| 524 | + */ |
|
| 525 | + public function getParsedActions() { |
|
| 526 | + return $this->actionsParsed; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * @return bool |
|
| 531 | + * @since 8.2.0 |
|
| 532 | + */ |
|
| 533 | + public function isValid() { |
|
| 534 | + return |
|
| 535 | + $this->isValidCommon() |
|
| 536 | + && |
|
| 537 | + $this->getSubject() !== '' |
|
| 538 | + ; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * @return bool |
|
| 543 | + * @since 8.2.0 |
|
| 544 | + */ |
|
| 545 | + public function isValidParsed() { |
|
| 546 | + if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) { |
|
| 547 | + try { |
|
| 548 | + $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters()); |
|
| 549 | + } catch (InvalidObjectExeption $e) { |
|
| 550 | + return false; |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) { |
|
| 555 | + try { |
|
| 556 | + $this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters()); |
|
| 557 | + } catch (InvalidObjectExeption $e) { |
|
| 558 | + return false; |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return |
|
| 563 | + $this->isValidCommon() |
|
| 564 | + && |
|
| 565 | + $this->getParsedSubject() !== '' |
|
| 566 | + ; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * @return bool |
|
| 571 | + */ |
|
| 572 | + protected function isValidCommon() { |
|
| 573 | + return |
|
| 574 | + $this->getApp() !== '' |
|
| 575 | + && |
|
| 576 | + $this->getUser() !== '' |
|
| 577 | + && |
|
| 578 | + $this->getDateTime()->getTimestamp() !== 0 |
|
| 579 | + && |
|
| 580 | + $this->getObjectType() !== '' |
|
| 581 | + && |
|
| 582 | + $this->getObjectId() !== '' |
|
| 583 | + ; |
|
| 584 | + } |
|
| 585 | 585 | } |
@@ -27,148 +27,148 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Action implements IAction { |
| 29 | 29 | |
| 30 | - /** @var string */ |
|
| 31 | - protected $label; |
|
| 32 | - |
|
| 33 | - /** @var string */ |
|
| 34 | - protected $labelParsed; |
|
| 35 | - |
|
| 36 | - /** @var string */ |
|
| 37 | - protected $link; |
|
| 38 | - |
|
| 39 | - /** @var string */ |
|
| 40 | - protected $requestType; |
|
| 41 | - |
|
| 42 | - /** @var string */ |
|
| 43 | - protected $icon; |
|
| 44 | - |
|
| 45 | - /** @var bool */ |
|
| 46 | - protected $primary; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Constructor |
|
| 50 | - */ |
|
| 51 | - public function __construct() { |
|
| 52 | - $this->label = ''; |
|
| 53 | - $this->labelParsed = ''; |
|
| 54 | - $this->link = ''; |
|
| 55 | - $this->requestType = ''; |
|
| 56 | - $this->primary = false; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param string $label |
|
| 61 | - * @return $this |
|
| 62 | - * @throws \InvalidArgumentException if the label is invalid |
|
| 63 | - * @since 8.2.0 |
|
| 64 | - */ |
|
| 65 | - public function setLabel($label) { |
|
| 66 | - if (!is_string($label) || $label === '' || isset($label[32])) { |
|
| 67 | - throw new \InvalidArgumentException('The given label is invalid'); |
|
| 68 | - } |
|
| 69 | - $this->label = $label; |
|
| 70 | - return $this; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @return string |
|
| 75 | - * @since 8.2.0 |
|
| 76 | - */ |
|
| 77 | - public function getLabel() { |
|
| 78 | - return $this->label; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param string $label |
|
| 83 | - * @return $this |
|
| 84 | - * @throws \InvalidArgumentException if the label is invalid |
|
| 85 | - * @since 8.2.0 |
|
| 86 | - */ |
|
| 87 | - public function setParsedLabel($label) { |
|
| 88 | - if (!is_string($label) || $label === '') { |
|
| 89 | - throw new \InvalidArgumentException('The given parsed label is invalid'); |
|
| 90 | - } |
|
| 91 | - $this->labelParsed = $label; |
|
| 92 | - return $this; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @return string |
|
| 97 | - * @since 8.2.0 |
|
| 98 | - */ |
|
| 99 | - public function getParsedLabel() { |
|
| 100 | - return $this->labelParsed; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param $primary bool |
|
| 105 | - * @return $this |
|
| 106 | - * @throws \InvalidArgumentException if $primary is invalid |
|
| 107 | - * @since 9.0.0 |
|
| 108 | - */ |
|
| 109 | - public function setPrimary($primary) { |
|
| 110 | - if (!is_bool($primary)) { |
|
| 111 | - throw new \InvalidArgumentException('The given primary option is invalid'); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $this->primary = $primary; |
|
| 115 | - return $this; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @return bool |
|
| 120 | - * @since 9.0.0 |
|
| 121 | - */ |
|
| 122 | - public function isPrimary() { |
|
| 123 | - return $this->primary; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @param string $link |
|
| 128 | - * @param string $requestType |
|
| 129 | - * @return $this |
|
| 130 | - * @throws \InvalidArgumentException if the link is invalid |
|
| 131 | - * @since 8.2.0 |
|
| 132 | - */ |
|
| 133 | - public function setLink($link, $requestType) { |
|
| 134 | - if (!is_string($link) || $link === '' || isset($link[256])) { |
|
| 135 | - throw new \InvalidArgumentException('The given link is invalid'); |
|
| 136 | - } |
|
| 137 | - if (!in_array($requestType, ['GET', 'POST', 'PUT', 'DELETE'], true)) { |
|
| 138 | - throw new \InvalidArgumentException('The given request type is invalid'); |
|
| 139 | - } |
|
| 140 | - $this->link = $link; |
|
| 141 | - $this->requestType = $requestType; |
|
| 142 | - return $this; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @return string |
|
| 147 | - * @since 8.2.0 |
|
| 148 | - */ |
|
| 149 | - public function getLink() { |
|
| 150 | - return $this->link; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @return string |
|
| 155 | - * @since 8.2.0 |
|
| 156 | - */ |
|
| 157 | - public function getRequestType() { |
|
| 158 | - return $this->requestType; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @return bool |
|
| 163 | - */ |
|
| 164 | - public function isValid() { |
|
| 165 | - return $this->label !== '' && $this->link !== ''; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @return bool |
|
| 170 | - */ |
|
| 171 | - public function isValidParsed() { |
|
| 172 | - return $this->labelParsed !== '' && $this->link !== ''; |
|
| 173 | - } |
|
| 30 | + /** @var string */ |
|
| 31 | + protected $label; |
|
| 32 | + |
|
| 33 | + /** @var string */ |
|
| 34 | + protected $labelParsed; |
|
| 35 | + |
|
| 36 | + /** @var string */ |
|
| 37 | + protected $link; |
|
| 38 | + |
|
| 39 | + /** @var string */ |
|
| 40 | + protected $requestType; |
|
| 41 | + |
|
| 42 | + /** @var string */ |
|
| 43 | + protected $icon; |
|
| 44 | + |
|
| 45 | + /** @var bool */ |
|
| 46 | + protected $primary; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Constructor |
|
| 50 | + */ |
|
| 51 | + public function __construct() { |
|
| 52 | + $this->label = ''; |
|
| 53 | + $this->labelParsed = ''; |
|
| 54 | + $this->link = ''; |
|
| 55 | + $this->requestType = ''; |
|
| 56 | + $this->primary = false; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param string $label |
|
| 61 | + * @return $this |
|
| 62 | + * @throws \InvalidArgumentException if the label is invalid |
|
| 63 | + * @since 8.2.0 |
|
| 64 | + */ |
|
| 65 | + public function setLabel($label) { |
|
| 66 | + if (!is_string($label) || $label === '' || isset($label[32])) { |
|
| 67 | + throw new \InvalidArgumentException('The given label is invalid'); |
|
| 68 | + } |
|
| 69 | + $this->label = $label; |
|
| 70 | + return $this; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @return string |
|
| 75 | + * @since 8.2.0 |
|
| 76 | + */ |
|
| 77 | + public function getLabel() { |
|
| 78 | + return $this->label; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param string $label |
|
| 83 | + * @return $this |
|
| 84 | + * @throws \InvalidArgumentException if the label is invalid |
|
| 85 | + * @since 8.2.0 |
|
| 86 | + */ |
|
| 87 | + public function setParsedLabel($label) { |
|
| 88 | + if (!is_string($label) || $label === '') { |
|
| 89 | + throw new \InvalidArgumentException('The given parsed label is invalid'); |
|
| 90 | + } |
|
| 91 | + $this->labelParsed = $label; |
|
| 92 | + return $this; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @return string |
|
| 97 | + * @since 8.2.0 |
|
| 98 | + */ |
|
| 99 | + public function getParsedLabel() { |
|
| 100 | + return $this->labelParsed; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param $primary bool |
|
| 105 | + * @return $this |
|
| 106 | + * @throws \InvalidArgumentException if $primary is invalid |
|
| 107 | + * @since 9.0.0 |
|
| 108 | + */ |
|
| 109 | + public function setPrimary($primary) { |
|
| 110 | + if (!is_bool($primary)) { |
|
| 111 | + throw new \InvalidArgumentException('The given primary option is invalid'); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $this->primary = $primary; |
|
| 115 | + return $this; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @return bool |
|
| 120 | + * @since 9.0.0 |
|
| 121 | + */ |
|
| 122 | + public function isPrimary() { |
|
| 123 | + return $this->primary; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @param string $link |
|
| 128 | + * @param string $requestType |
|
| 129 | + * @return $this |
|
| 130 | + * @throws \InvalidArgumentException if the link is invalid |
|
| 131 | + * @since 8.2.0 |
|
| 132 | + */ |
|
| 133 | + public function setLink($link, $requestType) { |
|
| 134 | + if (!is_string($link) || $link === '' || isset($link[256])) { |
|
| 135 | + throw new \InvalidArgumentException('The given link is invalid'); |
|
| 136 | + } |
|
| 137 | + if (!in_array($requestType, ['GET', 'POST', 'PUT', 'DELETE'], true)) { |
|
| 138 | + throw new \InvalidArgumentException('The given request type is invalid'); |
|
| 139 | + } |
|
| 140 | + $this->link = $link; |
|
| 141 | + $this->requestType = $requestType; |
|
| 142 | + return $this; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @return string |
|
| 147 | + * @since 8.2.0 |
|
| 148 | + */ |
|
| 149 | + public function getLink() { |
|
| 150 | + return $this->link; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @return string |
|
| 155 | + * @since 8.2.0 |
|
| 156 | + */ |
|
| 157 | + public function getRequestType() { |
|
| 158 | + return $this->requestType; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @return bool |
|
| 163 | + */ |
|
| 164 | + public function isValid() { |
|
| 165 | + return $this->label !== '' && $this->link !== ''; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @return bool |
|
| 170 | + */ |
|
| 171 | + public function isValidParsed() { |
|
| 172 | + return $this->labelParsed !== '' && $this->link !== ''; |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -146,7 +146,7 @@ |
||
| 146 | 146 | throw new \InvalidArgumentException('The given notifier information is invalid'); |
| 147 | 147 | } |
| 148 | 148 | if (isset($this->notifiersInfo[$notifier['id']])) { |
| 149 | - throw new \InvalidArgumentException('The given notifier ID ' . $notifier['id'] . ' is already in use'); |
|
| 149 | + throw new \InvalidArgumentException('The given notifier ID '.$notifier['id'].' is already in use'); |
|
| 150 | 150 | } |
| 151 | 151 | $this->notifiersInfo[$notifier['id']] = $notifier['name']; |
| 152 | 152 | } |
@@ -32,237 +32,237 @@ |
||
| 32 | 32 | use OCP\RichObjectStrings\IValidator; |
| 33 | 33 | |
| 34 | 34 | class Manager implements IManager { |
| 35 | - /** @var IValidator */ |
|
| 36 | - protected $validator; |
|
| 37 | - |
|
| 38 | - /** @var IApp[] */ |
|
| 39 | - protected $apps; |
|
| 40 | - |
|
| 41 | - /** @var INotifier[] */ |
|
| 42 | - protected $notifiers; |
|
| 43 | - |
|
| 44 | - /** @var array[] */ |
|
| 45 | - protected $notifiersInfo; |
|
| 46 | - |
|
| 47 | - /** @var \Closure[] */ |
|
| 48 | - protected $appsClosures; |
|
| 49 | - |
|
| 50 | - /** @var \Closure[] */ |
|
| 51 | - protected $notifiersClosures; |
|
| 52 | - |
|
| 53 | - /** @var \Closure[] */ |
|
| 54 | - protected $notifiersInfoClosures; |
|
| 55 | - |
|
| 56 | - /** @var bool */ |
|
| 57 | - protected $preparingPushNotification; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Manager constructor. |
|
| 61 | - * |
|
| 62 | - * @param IValidator $validator |
|
| 63 | - */ |
|
| 64 | - public function __construct(IValidator $validator) { |
|
| 65 | - $this->validator = $validator; |
|
| 66 | - $this->apps = []; |
|
| 67 | - $this->notifiers = []; |
|
| 68 | - $this->notifiersInfo = []; |
|
| 69 | - $this->appsClosures = []; |
|
| 70 | - $this->notifiersClosures = []; |
|
| 71 | - $this->notifiersInfoClosures = []; |
|
| 72 | - $this->preparingPushNotification = false; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param \Closure $service The service must implement IApp, otherwise a |
|
| 77 | - * \InvalidArgumentException is thrown later |
|
| 78 | - * @since 8.2.0 |
|
| 79 | - */ |
|
| 80 | - public function registerApp(\Closure $service) { |
|
| 81 | - $this->appsClosures[] = $service; |
|
| 82 | - $this->apps = []; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param \Closure $service The service must implement INotifier, otherwise a |
|
| 87 | - * \InvalidArgumentException is thrown later |
|
| 88 | - * @param \Closure $info An array with the keys 'id' and 'name' containing |
|
| 89 | - * the app id and the app name |
|
| 90 | - * @since 8.2.0 - Parameter $info was added in 9.0.0 |
|
| 91 | - */ |
|
| 92 | - public function registerNotifier(\Closure $service, \Closure $info) { |
|
| 93 | - $this->notifiersClosures[] = $service; |
|
| 94 | - $this->notifiersInfoClosures[] = $info; |
|
| 95 | - $this->notifiers = []; |
|
| 96 | - $this->notifiersInfo = []; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return IApp[] |
|
| 101 | - */ |
|
| 102 | - protected function getApps(): array { |
|
| 103 | - if (!empty($this->apps)) { |
|
| 104 | - return $this->apps; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $this->apps = []; |
|
| 108 | - foreach ($this->appsClosures as $closure) { |
|
| 109 | - $app = $closure(); |
|
| 110 | - if (!($app instanceof IApp)) { |
|
| 111 | - throw new \InvalidArgumentException('The given notification app does not implement the IApp interface'); |
|
| 112 | - } |
|
| 113 | - $this->apps[] = $app; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return $this->apps; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return INotifier[] |
|
| 121 | - */ |
|
| 122 | - protected function getNotifiers(): array { |
|
| 123 | - if (!empty($this->notifiers)) { |
|
| 124 | - return $this->notifiers; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $this->notifiers = []; |
|
| 128 | - foreach ($this->notifiersClosures as $closure) { |
|
| 129 | - $notifier = $closure(); |
|
| 130 | - if (!($notifier instanceof INotifier)) { |
|
| 131 | - throw new \InvalidArgumentException('The given notifier does not implement the INotifier interface'); |
|
| 132 | - } |
|
| 133 | - $this->notifiers[] = $notifier; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $this->notifiers; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @return array[] |
|
| 141 | - */ |
|
| 142 | - public function listNotifiers(): array { |
|
| 143 | - if (!empty($this->notifiersInfo)) { |
|
| 144 | - return $this->notifiersInfo; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $this->notifiersInfo = []; |
|
| 148 | - foreach ($this->notifiersInfoClosures as $closure) { |
|
| 149 | - $notifier = $closure(); |
|
| 150 | - if (!\is_array($notifier) || \count($notifier) !== 2 || !isset($notifier['id'], $notifier['name'])) { |
|
| 151 | - throw new \InvalidArgumentException('The given notifier information is invalid'); |
|
| 152 | - } |
|
| 153 | - if (isset($this->notifiersInfo[$notifier['id']])) { |
|
| 154 | - throw new \InvalidArgumentException('The given notifier ID ' . $notifier['id'] . ' is already in use'); |
|
| 155 | - } |
|
| 156 | - $this->notifiersInfo[$notifier['id']] = $notifier['name']; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return $this->notifiersInfo; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @return INotification |
|
| 164 | - * @since 8.2.0 |
|
| 165 | - */ |
|
| 166 | - public function createNotification(): INotification { |
|
| 167 | - return new Notification($this->validator); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @return bool |
|
| 172 | - * @since 8.2.0 |
|
| 173 | - */ |
|
| 174 | - public function hasNotifiers(): bool { |
|
| 175 | - return !empty($this->notifiersClosures); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @param bool $preparingPushNotification |
|
| 180 | - * @since 14.0.0 |
|
| 181 | - */ |
|
| 182 | - public function setPreparingPushNotification($preparingPushNotification) { |
|
| 183 | - $this->preparingPushNotification = $preparingPushNotification; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @return bool |
|
| 188 | - * @since 14.0.0 |
|
| 189 | - */ |
|
| 190 | - public function isPreparingPushNotification(): bool { |
|
| 191 | - return $this->preparingPushNotification; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @param INotification $notification |
|
| 196 | - * @throws \InvalidArgumentException When the notification is not valid |
|
| 197 | - * @since 8.2.0 |
|
| 198 | - */ |
|
| 199 | - public function notify(INotification $notification) { |
|
| 200 | - if (!$notification->isValid()) { |
|
| 201 | - throw new \InvalidArgumentException('The given notification is invalid'); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $apps = $this->getApps(); |
|
| 205 | - |
|
| 206 | - foreach ($apps as $app) { |
|
| 207 | - try { |
|
| 208 | - $app->notify($notification); |
|
| 209 | - } catch (\InvalidArgumentException $e) { |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param INotification $notification |
|
| 216 | - * @param string $languageCode The code of the language that should be used to prepare the notification |
|
| 217 | - * @return INotification |
|
| 218 | - * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
| 219 | - * @since 8.2.0 |
|
| 220 | - */ |
|
| 221 | - public function prepare(INotification $notification, $languageCode): INotification { |
|
| 222 | - $notifiers = $this->getNotifiers(); |
|
| 223 | - |
|
| 224 | - foreach ($notifiers as $notifier) { |
|
| 225 | - try { |
|
| 226 | - $notification = $notifier->prepare($notification, $languageCode); |
|
| 227 | - } catch (\InvalidArgumentException $e) { |
|
| 228 | - continue; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - if (!($notification instanceof INotification) || !$notification->isValidParsed()) { |
|
| 232 | - throw new \InvalidArgumentException('The given notification has not been handled'); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if (!($notification instanceof INotification) || !$notification->isValidParsed()) { |
|
| 237 | - throw new \InvalidArgumentException('The given notification has not been handled'); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - return $notification; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @param INotification $notification |
|
| 245 | - */ |
|
| 246 | - public function markProcessed(INotification $notification) { |
|
| 247 | - $apps = $this->getApps(); |
|
| 248 | - |
|
| 249 | - foreach ($apps as $app) { |
|
| 250 | - $app->markProcessed($notification); |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @param INotification $notification |
|
| 256 | - * @return int |
|
| 257 | - */ |
|
| 258 | - public function getCount(INotification $notification): int { |
|
| 259 | - $apps = $this->getApps(); |
|
| 260 | - |
|
| 261 | - $count = 0; |
|
| 262 | - foreach ($apps as $app) { |
|
| 263 | - $count += $app->getCount($notification); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return $count; |
|
| 267 | - } |
|
| 35 | + /** @var IValidator */ |
|
| 36 | + protected $validator; |
|
| 37 | + |
|
| 38 | + /** @var IApp[] */ |
|
| 39 | + protected $apps; |
|
| 40 | + |
|
| 41 | + /** @var INotifier[] */ |
|
| 42 | + protected $notifiers; |
|
| 43 | + |
|
| 44 | + /** @var array[] */ |
|
| 45 | + protected $notifiersInfo; |
|
| 46 | + |
|
| 47 | + /** @var \Closure[] */ |
|
| 48 | + protected $appsClosures; |
|
| 49 | + |
|
| 50 | + /** @var \Closure[] */ |
|
| 51 | + protected $notifiersClosures; |
|
| 52 | + |
|
| 53 | + /** @var \Closure[] */ |
|
| 54 | + protected $notifiersInfoClosures; |
|
| 55 | + |
|
| 56 | + /** @var bool */ |
|
| 57 | + protected $preparingPushNotification; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Manager constructor. |
|
| 61 | + * |
|
| 62 | + * @param IValidator $validator |
|
| 63 | + */ |
|
| 64 | + public function __construct(IValidator $validator) { |
|
| 65 | + $this->validator = $validator; |
|
| 66 | + $this->apps = []; |
|
| 67 | + $this->notifiers = []; |
|
| 68 | + $this->notifiersInfo = []; |
|
| 69 | + $this->appsClosures = []; |
|
| 70 | + $this->notifiersClosures = []; |
|
| 71 | + $this->notifiersInfoClosures = []; |
|
| 72 | + $this->preparingPushNotification = false; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param \Closure $service The service must implement IApp, otherwise a |
|
| 77 | + * \InvalidArgumentException is thrown later |
|
| 78 | + * @since 8.2.0 |
|
| 79 | + */ |
|
| 80 | + public function registerApp(\Closure $service) { |
|
| 81 | + $this->appsClosures[] = $service; |
|
| 82 | + $this->apps = []; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param \Closure $service The service must implement INotifier, otherwise a |
|
| 87 | + * \InvalidArgumentException is thrown later |
|
| 88 | + * @param \Closure $info An array with the keys 'id' and 'name' containing |
|
| 89 | + * the app id and the app name |
|
| 90 | + * @since 8.2.0 - Parameter $info was added in 9.0.0 |
|
| 91 | + */ |
|
| 92 | + public function registerNotifier(\Closure $service, \Closure $info) { |
|
| 93 | + $this->notifiersClosures[] = $service; |
|
| 94 | + $this->notifiersInfoClosures[] = $info; |
|
| 95 | + $this->notifiers = []; |
|
| 96 | + $this->notifiersInfo = []; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return IApp[] |
|
| 101 | + */ |
|
| 102 | + protected function getApps(): array { |
|
| 103 | + if (!empty($this->apps)) { |
|
| 104 | + return $this->apps; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $this->apps = []; |
|
| 108 | + foreach ($this->appsClosures as $closure) { |
|
| 109 | + $app = $closure(); |
|
| 110 | + if (!($app instanceof IApp)) { |
|
| 111 | + throw new \InvalidArgumentException('The given notification app does not implement the IApp interface'); |
|
| 112 | + } |
|
| 113 | + $this->apps[] = $app; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return $this->apps; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return INotifier[] |
|
| 121 | + */ |
|
| 122 | + protected function getNotifiers(): array { |
|
| 123 | + if (!empty($this->notifiers)) { |
|
| 124 | + return $this->notifiers; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $this->notifiers = []; |
|
| 128 | + foreach ($this->notifiersClosures as $closure) { |
|
| 129 | + $notifier = $closure(); |
|
| 130 | + if (!($notifier instanceof INotifier)) { |
|
| 131 | + throw new \InvalidArgumentException('The given notifier does not implement the INotifier interface'); |
|
| 132 | + } |
|
| 133 | + $this->notifiers[] = $notifier; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $this->notifiers; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return array[] |
|
| 141 | + */ |
|
| 142 | + public function listNotifiers(): array { |
|
| 143 | + if (!empty($this->notifiersInfo)) { |
|
| 144 | + return $this->notifiersInfo; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $this->notifiersInfo = []; |
|
| 148 | + foreach ($this->notifiersInfoClosures as $closure) { |
|
| 149 | + $notifier = $closure(); |
|
| 150 | + if (!\is_array($notifier) || \count($notifier) !== 2 || !isset($notifier['id'], $notifier['name'])) { |
|
| 151 | + throw new \InvalidArgumentException('The given notifier information is invalid'); |
|
| 152 | + } |
|
| 153 | + if (isset($this->notifiersInfo[$notifier['id']])) { |
|
| 154 | + throw new \InvalidArgumentException('The given notifier ID ' . $notifier['id'] . ' is already in use'); |
|
| 155 | + } |
|
| 156 | + $this->notifiersInfo[$notifier['id']] = $notifier['name']; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return $this->notifiersInfo; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @return INotification |
|
| 164 | + * @since 8.2.0 |
|
| 165 | + */ |
|
| 166 | + public function createNotification(): INotification { |
|
| 167 | + return new Notification($this->validator); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @return bool |
|
| 172 | + * @since 8.2.0 |
|
| 173 | + */ |
|
| 174 | + public function hasNotifiers(): bool { |
|
| 175 | + return !empty($this->notifiersClosures); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @param bool $preparingPushNotification |
|
| 180 | + * @since 14.0.0 |
|
| 181 | + */ |
|
| 182 | + public function setPreparingPushNotification($preparingPushNotification) { |
|
| 183 | + $this->preparingPushNotification = $preparingPushNotification; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @return bool |
|
| 188 | + * @since 14.0.0 |
|
| 189 | + */ |
|
| 190 | + public function isPreparingPushNotification(): bool { |
|
| 191 | + return $this->preparingPushNotification; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @param INotification $notification |
|
| 196 | + * @throws \InvalidArgumentException When the notification is not valid |
|
| 197 | + * @since 8.2.0 |
|
| 198 | + */ |
|
| 199 | + public function notify(INotification $notification) { |
|
| 200 | + if (!$notification->isValid()) { |
|
| 201 | + throw new \InvalidArgumentException('The given notification is invalid'); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $apps = $this->getApps(); |
|
| 205 | + |
|
| 206 | + foreach ($apps as $app) { |
|
| 207 | + try { |
|
| 208 | + $app->notify($notification); |
|
| 209 | + } catch (\InvalidArgumentException $e) { |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param INotification $notification |
|
| 216 | + * @param string $languageCode The code of the language that should be used to prepare the notification |
|
| 217 | + * @return INotification |
|
| 218 | + * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
| 219 | + * @since 8.2.0 |
|
| 220 | + */ |
|
| 221 | + public function prepare(INotification $notification, $languageCode): INotification { |
|
| 222 | + $notifiers = $this->getNotifiers(); |
|
| 223 | + |
|
| 224 | + foreach ($notifiers as $notifier) { |
|
| 225 | + try { |
|
| 226 | + $notification = $notifier->prepare($notification, $languageCode); |
|
| 227 | + } catch (\InvalidArgumentException $e) { |
|
| 228 | + continue; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + if (!($notification instanceof INotification) || !$notification->isValidParsed()) { |
|
| 232 | + throw new \InvalidArgumentException('The given notification has not been handled'); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if (!($notification instanceof INotification) || !$notification->isValidParsed()) { |
|
| 237 | + throw new \InvalidArgumentException('The given notification has not been handled'); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + return $notification; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @param INotification $notification |
|
| 245 | + */ |
|
| 246 | + public function markProcessed(INotification $notification) { |
|
| 247 | + $apps = $this->getApps(); |
|
| 248 | + |
|
| 249 | + foreach ($apps as $app) { |
|
| 250 | + $app->markProcessed($notification); |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @param INotification $notification |
|
| 256 | + * @return int |
|
| 257 | + */ |
|
| 258 | + public function getCount(INotification $notification): int { |
|
| 259 | + $apps = $this->getApps(); |
|
| 260 | + |
|
| 261 | + $count = 0; |
|
| 262 | + foreach ($apps as $app) { |
|
| 263 | + $count += $app->getCount($notification); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return $count; |
|
| 267 | + } |
|
| 268 | 268 | } |
@@ -30,25 +30,25 @@ |
||
| 30 | 30 | parent::__construct($iterator); |
| 31 | 31 | |
| 32 | 32 | $appFolders = \OC::$APPSROOTS; |
| 33 | - foreach($appFolders as $key => $appFolder) { |
|
| 33 | + foreach ($appFolders as $key => $appFolder) { |
|
| 34 | 34 | $appFolders[$key] = rtrim($appFolder['path'], '/'); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $excludedFolders = [ |
| 38 | - rtrim($root . '/data', '/'), |
|
| 39 | - rtrim($root . '/themes', '/'), |
|
| 40 | - rtrim($root . '/config', '/'), |
|
| 41 | - rtrim($root . '/apps', '/'), |
|
| 42 | - rtrim($root . '/assets', '/'), |
|
| 43 | - rtrim($root . '/lost+found', '/'), |
|
| 38 | + rtrim($root.'/data', '/'), |
|
| 39 | + rtrim($root.'/themes', '/'), |
|
| 40 | + rtrim($root.'/config', '/'), |
|
| 41 | + rtrim($root.'/apps', '/'), |
|
| 42 | + rtrim($root.'/assets', '/'), |
|
| 43 | + rtrim($root.'/lost+found', '/'), |
|
| 44 | 44 | // Ignore folders generated by updater since the updater is replaced |
| 45 | 45 | // after the integrity check is run. |
| 46 | 46 | // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
| 47 | - rtrim($root . '/updater', '/'), |
|
| 48 | - rtrim($root . '/_oc_upgrade', '/'), |
|
| 47 | + rtrim($root.'/updater', '/'), |
|
| 48 | + rtrim($root.'/_oc_upgrade', '/'), |
|
| 49 | 49 | ]; |
| 50 | 50 | $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
| 51 | - if($customDataDir !== '') { |
|
| 51 | + if ($customDataDir !== '') { |
|
| 52 | 52 | $excludedFolders[] = rtrim($customDataDir, '/'); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -25,45 +25,45 @@ |
||
| 25 | 25 | namespace OC\IntegrityCheck\Iterator; |
| 26 | 26 | |
| 27 | 27 | class ExcludeFoldersByPathFilterIterator extends \RecursiveFilterIterator { |
| 28 | - private $excludedFolders; |
|
| 28 | + private $excludedFolders; |
|
| 29 | 29 | |
| 30 | - public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
| 31 | - parent::__construct($iterator); |
|
| 30 | + public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
| 31 | + parent::__construct($iterator); |
|
| 32 | 32 | |
| 33 | - $appFolders = \OC::$APPSROOTS; |
|
| 34 | - foreach($appFolders as $key => $appFolder) { |
|
| 35 | - $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
| 36 | - } |
|
| 33 | + $appFolders = \OC::$APPSROOTS; |
|
| 34 | + foreach($appFolders as $key => $appFolder) { |
|
| 35 | + $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $excludedFolders = [ |
|
| 39 | - rtrim($root . '/data', '/'), |
|
| 40 | - rtrim($root . '/themes', '/'), |
|
| 41 | - rtrim($root . '/config', '/'), |
|
| 42 | - rtrim($root . '/apps', '/'), |
|
| 43 | - rtrim($root . '/assets', '/'), |
|
| 44 | - rtrim($root . '/lost+found', '/'), |
|
| 45 | - // Ignore folders generated by updater since the updater is replaced |
|
| 46 | - // after the integrity check is run. |
|
| 47 | - // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
| 48 | - rtrim($root . '/updater', '/'), |
|
| 49 | - rtrim($root . '/_oc_upgrade', '/'), |
|
| 50 | - ]; |
|
| 51 | - $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
| 52 | - if($customDataDir !== '') { |
|
| 53 | - $excludedFolders[] = rtrim($customDataDir, '/'); |
|
| 54 | - } |
|
| 38 | + $excludedFolders = [ |
|
| 39 | + rtrim($root . '/data', '/'), |
|
| 40 | + rtrim($root . '/themes', '/'), |
|
| 41 | + rtrim($root . '/config', '/'), |
|
| 42 | + rtrim($root . '/apps', '/'), |
|
| 43 | + rtrim($root . '/assets', '/'), |
|
| 44 | + rtrim($root . '/lost+found', '/'), |
|
| 45 | + // Ignore folders generated by updater since the updater is replaced |
|
| 46 | + // after the integrity check is run. |
|
| 47 | + // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
| 48 | + rtrim($root . '/updater', '/'), |
|
| 49 | + rtrim($root . '/_oc_upgrade', '/'), |
|
| 50 | + ]; |
|
| 51 | + $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
| 52 | + if($customDataDir !== '') { |
|
| 53 | + $excludedFolders[] = rtrim($customDataDir, '/'); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
| 57 | - } |
|
| 56 | + $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @return bool |
|
| 61 | - */ |
|
| 62 | - public function accept() { |
|
| 63 | - return !\in_array( |
|
| 64 | - $this->current()->getPathName(), |
|
| 65 | - $this->excludedFolders, |
|
| 66 | - true |
|
| 67 | - ); |
|
| 68 | - } |
|
| 59 | + /** |
|
| 60 | + * @return bool |
|
| 61 | + */ |
|
| 62 | + public function accept() { |
|
| 63 | + return !\in_array( |
|
| 64 | + $this->current()->getPathName(), |
|
| 65 | + $this->excludedFolders, |
|
| 66 | + true |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -35,46 +35,46 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | class HintException extends \Exception { |
| 37 | 37 | |
| 38 | - private $hint; |
|
| 38 | + private $hint; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * HintException constructor. |
|
| 42 | - * |
|
| 43 | - * @param string $message The error message. It will be not revealed to the |
|
| 44 | - * the user (unless the hint is empty) and thus |
|
| 45 | - * should be not translated. |
|
| 46 | - * @param string $hint A useful message that is presented to the end |
|
| 47 | - * user. It should be translated, but must not |
|
| 48 | - * contain sensitive data. |
|
| 49 | - * @param int $code |
|
| 50 | - * @param \Exception|null $previous |
|
| 51 | - */ |
|
| 52 | - public function __construct($message, $hint = '', $code = 0, \Exception $previous = null) { |
|
| 53 | - $this->hint = $hint; |
|
| 54 | - parent::__construct($message, $code, $previous); |
|
| 55 | - } |
|
| 40 | + /** |
|
| 41 | + * HintException constructor. |
|
| 42 | + * |
|
| 43 | + * @param string $message The error message. It will be not revealed to the |
|
| 44 | + * the user (unless the hint is empty) and thus |
|
| 45 | + * should be not translated. |
|
| 46 | + * @param string $hint A useful message that is presented to the end |
|
| 47 | + * user. It should be translated, but must not |
|
| 48 | + * contain sensitive data. |
|
| 49 | + * @param int $code |
|
| 50 | + * @param \Exception|null $previous |
|
| 51 | + */ |
|
| 52 | + public function __construct($message, $hint = '', $code = 0, \Exception $previous = null) { |
|
| 53 | + $this->hint = $hint; |
|
| 54 | + parent::__construct($message, $code, $previous); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Returns a string representation of this Exception that includes the error |
|
| 59 | - * code, the message and the hint. |
|
| 60 | - * |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function __toString() { |
|
| 64 | - return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
| 65 | - } |
|
| 57 | + /** |
|
| 58 | + * Returns a string representation of this Exception that includes the error |
|
| 59 | + * code, the message and the hint. |
|
| 60 | + * |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function __toString() { |
|
| 64 | + return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Returns the hint with the intention to be presented to the end user. If |
|
| 69 | - * an empty hint was specified upon instatiation, the message is returned |
|
| 70 | - * instead. |
|
| 71 | - * |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function getHint() { |
|
| 75 | - if (empty($this->hint)) { |
|
| 76 | - return $this->message; |
|
| 77 | - } |
|
| 78 | - return $this->hint; |
|
| 79 | - } |
|
| 67 | + /** |
|
| 68 | + * Returns the hint with the intention to be presented to the end user. If |
|
| 69 | + * an empty hint was specified upon instatiation, the message is returned |
|
| 70 | + * instead. |
|
| 71 | + * |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function getHint() { |
|
| 75 | + if (empty($this->hint)) { |
|
| 76 | + return $this->message; |
|
| 77 | + } |
|
| 78 | + return $this->hint; |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | public function __toString() { |
| 64 | - return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
| 64 | + return __CLASS__.": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -29,136 +29,136 @@ |
||
| 29 | 29 | * capabilities. |
| 30 | 30 | */ |
| 31 | 31 | abstract class Backend implements UserInterface { |
| 32 | - /** |
|
| 33 | - * error code for functions not provided by the user backend |
|
| 34 | - */ |
|
| 35 | - const NOT_IMPLEMENTED = -501; |
|
| 32 | + /** |
|
| 33 | + * error code for functions not provided by the user backend |
|
| 34 | + */ |
|
| 35 | + const NOT_IMPLEMENTED = -501; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * actions that user backends can define |
|
| 39 | - */ |
|
| 40 | - const CREATE_USER = 1; // 1 << 0 |
|
| 41 | - const SET_PASSWORD = 16; // 1 << 4 |
|
| 42 | - const CHECK_PASSWORD = 256; // 1 << 8 |
|
| 43 | - const GET_HOME = 4096; // 1 << 12 |
|
| 44 | - const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
| 45 | - const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
| 46 | - const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
| 47 | - const COUNT_USERS = 268435456; // 1 << 28 |
|
| 37 | + /** |
|
| 38 | + * actions that user backends can define |
|
| 39 | + */ |
|
| 40 | + const CREATE_USER = 1; // 1 << 0 |
|
| 41 | + const SET_PASSWORD = 16; // 1 << 4 |
|
| 42 | + const CHECK_PASSWORD = 256; // 1 << 8 |
|
| 43 | + const GET_HOME = 4096; // 1 << 12 |
|
| 44 | + const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
| 45 | + const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
| 46 | + const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
| 47 | + const COUNT_USERS = 268435456; // 1 << 28 |
|
| 48 | 48 | |
| 49 | - protected $possibleActions = array( |
|
| 50 | - self::CREATE_USER => 'createUser', |
|
| 51 | - self::SET_PASSWORD => 'setPassword', |
|
| 52 | - self::CHECK_PASSWORD => 'checkPassword', |
|
| 53 | - self::GET_HOME => 'getHome', |
|
| 54 | - self::GET_DISPLAYNAME => 'getDisplayName', |
|
| 55 | - self::SET_DISPLAYNAME => 'setDisplayName', |
|
| 56 | - self::PROVIDE_AVATAR => 'canChangeAvatar', |
|
| 57 | - self::COUNT_USERS => 'countUsers', |
|
| 58 | - ); |
|
| 49 | + protected $possibleActions = array( |
|
| 50 | + self::CREATE_USER => 'createUser', |
|
| 51 | + self::SET_PASSWORD => 'setPassword', |
|
| 52 | + self::CHECK_PASSWORD => 'checkPassword', |
|
| 53 | + self::GET_HOME => 'getHome', |
|
| 54 | + self::GET_DISPLAYNAME => 'getDisplayName', |
|
| 55 | + self::SET_DISPLAYNAME => 'setDisplayName', |
|
| 56 | + self::PROVIDE_AVATAR => 'canChangeAvatar', |
|
| 57 | + self::COUNT_USERS => 'countUsers', |
|
| 58 | + ); |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Get all supported actions |
|
| 62 | - * @return int bitwise-or'ed actions |
|
| 63 | - * |
|
| 64 | - * Returns the supported actions as int to be |
|
| 65 | - * compared with self::CREATE_USER etc. |
|
| 66 | - */ |
|
| 67 | - public function getSupportedActions() { |
|
| 68 | - $actions = 0; |
|
| 69 | - foreach($this->possibleActions AS $action => $methodName) { |
|
| 70 | - if(method_exists($this, $methodName)) { |
|
| 71 | - $actions |= $action; |
|
| 72 | - } |
|
| 73 | - } |
|
| 60 | + /** |
|
| 61 | + * Get all supported actions |
|
| 62 | + * @return int bitwise-or'ed actions |
|
| 63 | + * |
|
| 64 | + * Returns the supported actions as int to be |
|
| 65 | + * compared with self::CREATE_USER etc. |
|
| 66 | + */ |
|
| 67 | + public function getSupportedActions() { |
|
| 68 | + $actions = 0; |
|
| 69 | + foreach($this->possibleActions AS $action => $methodName) { |
|
| 70 | + if(method_exists($this, $methodName)) { |
|
| 71 | + $actions |= $action; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - return $actions; |
|
| 76 | - } |
|
| 75 | + return $actions; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Check if backend implements actions |
|
| 80 | - * @param int $actions bitwise-or'ed actions |
|
| 81 | - * @return boolean |
|
| 82 | - * |
|
| 83 | - * Returns the supported actions as int to be |
|
| 84 | - * compared with self::CREATE_USER etc. |
|
| 85 | - */ |
|
| 86 | - public function implementsActions($actions) { |
|
| 87 | - return (bool)($this->getSupportedActions() & $actions); |
|
| 88 | - } |
|
| 78 | + /** |
|
| 79 | + * Check if backend implements actions |
|
| 80 | + * @param int $actions bitwise-or'ed actions |
|
| 81 | + * @return boolean |
|
| 82 | + * |
|
| 83 | + * Returns the supported actions as int to be |
|
| 84 | + * compared with self::CREATE_USER etc. |
|
| 85 | + */ |
|
| 86 | + public function implementsActions($actions) { |
|
| 87 | + return (bool)($this->getSupportedActions() & $actions); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * delete a user |
|
| 92 | - * @param string $uid The username of the user to delete |
|
| 93 | - * @return bool |
|
| 94 | - * |
|
| 95 | - * Deletes a user |
|
| 96 | - */ |
|
| 97 | - public function deleteUser( $uid ) { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 90 | + /** |
|
| 91 | + * delete a user |
|
| 92 | + * @param string $uid The username of the user to delete |
|
| 93 | + * @return bool |
|
| 94 | + * |
|
| 95 | + * Deletes a user |
|
| 96 | + */ |
|
| 97 | + public function deleteUser( $uid ) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Get a list of all users |
|
| 103 | - * |
|
| 104 | - * @param string $search |
|
| 105 | - * @param null|int $limit |
|
| 106 | - * @param null|int $offset |
|
| 107 | - * @return string[] an array of all uids |
|
| 108 | - */ |
|
| 109 | - public function getUsers($search = '', $limit = null, $offset = null) { |
|
| 110 | - return array(); |
|
| 111 | - } |
|
| 101 | + /** |
|
| 102 | + * Get a list of all users |
|
| 103 | + * |
|
| 104 | + * @param string $search |
|
| 105 | + * @param null|int $limit |
|
| 106 | + * @param null|int $offset |
|
| 107 | + * @return string[] an array of all uids |
|
| 108 | + */ |
|
| 109 | + public function getUsers($search = '', $limit = null, $offset = null) { |
|
| 110 | + return array(); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * check if a user exists |
|
| 115 | - * @param string $uid the username |
|
| 116 | - * @return boolean |
|
| 117 | - */ |
|
| 118 | - public function userExists($uid) { |
|
| 119 | - return false; |
|
| 120 | - } |
|
| 113 | + /** |
|
| 114 | + * check if a user exists |
|
| 115 | + * @param string $uid the username |
|
| 116 | + * @return boolean |
|
| 117 | + */ |
|
| 118 | + public function userExists($uid) { |
|
| 119 | + return false; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * get the user's home directory |
|
| 124 | - * @param string $uid the username |
|
| 125 | - * @return boolean |
|
| 126 | - */ |
|
| 127 | - public function getHome($uid) { |
|
| 128 | - return false; |
|
| 129 | - } |
|
| 122 | + /** |
|
| 123 | + * get the user's home directory |
|
| 124 | + * @param string $uid the username |
|
| 125 | + * @return boolean |
|
| 126 | + */ |
|
| 127 | + public function getHome($uid) { |
|
| 128 | + return false; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * get display name of the user |
|
| 133 | - * @param string $uid user ID of the user |
|
| 134 | - * @return string display name |
|
| 135 | - */ |
|
| 136 | - public function getDisplayName($uid) { |
|
| 137 | - return $uid; |
|
| 138 | - } |
|
| 131 | + /** |
|
| 132 | + * get display name of the user |
|
| 133 | + * @param string $uid user ID of the user |
|
| 134 | + * @return string display name |
|
| 135 | + */ |
|
| 136 | + public function getDisplayName($uid) { |
|
| 137 | + return $uid; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Get a list of all display names and user ids. |
|
| 142 | - * |
|
| 143 | - * @param string $search |
|
| 144 | - * @param string|null $limit |
|
| 145 | - * @param string|null $offset |
|
| 146 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 147 | - */ |
|
| 148 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 149 | - $displayNames = array(); |
|
| 150 | - $users = $this->getUsers($search, $limit, $offset); |
|
| 151 | - foreach ( $users as $user) { |
|
| 152 | - $displayNames[$user] = $user; |
|
| 153 | - } |
|
| 154 | - return $displayNames; |
|
| 155 | - } |
|
| 140 | + /** |
|
| 141 | + * Get a list of all display names and user ids. |
|
| 142 | + * |
|
| 143 | + * @param string $search |
|
| 144 | + * @param string|null $limit |
|
| 145 | + * @param string|null $offset |
|
| 146 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 147 | + */ |
|
| 148 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 149 | + $displayNames = array(); |
|
| 150 | + $users = $this->getUsers($search, $limit, $offset); |
|
| 151 | + foreach ( $users as $user) { |
|
| 152 | + $displayNames[$user] = $user; |
|
| 153 | + } |
|
| 154 | + return $displayNames; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * Check if a user list is available or not |
|
| 159 | - * @return boolean if users can be listed or not |
|
| 160 | - */ |
|
| 161 | - public function hasUserListings() { |
|
| 162 | - return false; |
|
| 163 | - } |
|
| 157 | + /** |
|
| 158 | + * Check if a user list is available or not |
|
| 159 | + * @return boolean if users can be listed or not |
|
| 160 | + */ |
|
| 161 | + public function hasUserListings() { |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | 164 | } |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * actions that user backends can define |
| 39 | 39 | */ |
| 40 | - const CREATE_USER = 1; // 1 << 0 |
|
| 41 | - const SET_PASSWORD = 16; // 1 << 4 |
|
| 42 | - const CHECK_PASSWORD = 256; // 1 << 8 |
|
| 43 | - const GET_HOME = 4096; // 1 << 12 |
|
| 44 | - const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
| 45 | - const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
| 46 | - const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
| 47 | - const COUNT_USERS = 268435456; // 1 << 28 |
|
| 40 | + const CREATE_USER = 1; // 1 << 0 |
|
| 41 | + const SET_PASSWORD = 16; // 1 << 4 |
|
| 42 | + const CHECK_PASSWORD = 256; // 1 << 8 |
|
| 43 | + const GET_HOME = 4096; // 1 << 12 |
|
| 44 | + const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
| 45 | + const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
| 46 | + const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
| 47 | + const COUNT_USERS = 268435456; // 1 << 28 |
|
| 48 | 48 | |
| 49 | 49 | protected $possibleActions = array( |
| 50 | 50 | self::CREATE_USER => 'createUser', |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function getSupportedActions() { |
| 68 | 68 | $actions = 0; |
| 69 | - foreach($this->possibleActions AS $action => $methodName) { |
|
| 70 | - if(method_exists($this, $methodName)) { |
|
| 69 | + foreach ($this->possibleActions AS $action => $methodName) { |
|
| 70 | + if (method_exists($this, $methodName)) { |
|
| 71 | 71 | $actions |= $action; |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * compared with self::CREATE_USER etc. |
| 85 | 85 | */ |
| 86 | 86 | public function implementsActions($actions) { |
| 87 | - return (bool)($this->getSupportedActions() & $actions); |
|
| 87 | + return (bool) ($this->getSupportedActions() & $actions); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * |
| 95 | 95 | * Deletes a user |
| 96 | 96 | */ |
| 97 | - public function deleteUser( $uid ) { |
|
| 97 | + public function deleteUser($uid) { |
|
| 98 | 98 | return false; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
| 149 | 149 | $displayNames = array(); |
| 150 | 150 | $users = $this->getUsers($search, $limit, $offset); |
| 151 | - foreach ( $users as $user) { |
|
| 151 | + foreach ($users as $user) { |
|
| 152 | 152 | $displayNames[$user] = $user; |
| 153 | 153 | } |
| 154 | 154 | return $displayNames; |
@@ -26,79 +26,79 @@ |
||
| 26 | 26 | use OCP\Diagnostics\IEvent; |
| 27 | 27 | |
| 28 | 28 | class Event implements IEvent { |
| 29 | - /** |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - protected $id; |
|
| 29 | + /** |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + protected $id; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var float |
|
| 36 | - */ |
|
| 37 | - protected $start; |
|
| 34 | + /** |
|
| 35 | + * @var float |
|
| 36 | + */ |
|
| 37 | + protected $start; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var float |
|
| 41 | - */ |
|
| 42 | - protected $end; |
|
| 39 | + /** |
|
| 40 | + * @var float |
|
| 41 | + */ |
|
| 42 | + protected $end; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - protected $description; |
|
| 44 | + /** |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + protected $description; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param string $id |
|
| 51 | - * @param string $description |
|
| 52 | - * @param float $start |
|
| 53 | - */ |
|
| 54 | - public function __construct($id, $description, $start) { |
|
| 55 | - $this->id = $id; |
|
| 56 | - $this->description = $description; |
|
| 57 | - $this->start = $start; |
|
| 58 | - } |
|
| 49 | + /** |
|
| 50 | + * @param string $id |
|
| 51 | + * @param string $description |
|
| 52 | + * @param float $start |
|
| 53 | + */ |
|
| 54 | + public function __construct($id, $description, $start) { |
|
| 55 | + $this->id = $id; |
|
| 56 | + $this->description = $description; |
|
| 57 | + $this->start = $start; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param float $time |
|
| 62 | - */ |
|
| 63 | - public function end($time) { |
|
| 64 | - $this->end = $time; |
|
| 65 | - } |
|
| 60 | + /** |
|
| 61 | + * @param float $time |
|
| 62 | + */ |
|
| 63 | + public function end($time) { |
|
| 64 | + $this->end = $time; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return float |
|
| 69 | - */ |
|
| 70 | - public function getStart() { |
|
| 71 | - return $this->start; |
|
| 72 | - } |
|
| 67 | + /** |
|
| 68 | + * @return float |
|
| 69 | + */ |
|
| 70 | + public function getStart() { |
|
| 71 | + return $this->start; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public function getId() { |
|
| 78 | - return $this->id; |
|
| 79 | - } |
|
| 74 | + /** |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public function getId() { |
|
| 78 | + return $this->id; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @return string |
|
| 83 | - */ |
|
| 84 | - public function getDescription() { |
|
| 85 | - return $this->description; |
|
| 86 | - } |
|
| 81 | + /** |
|
| 82 | + * @return string |
|
| 83 | + */ |
|
| 84 | + public function getDescription() { |
|
| 85 | + return $this->description; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @return float |
|
| 90 | - */ |
|
| 91 | - public function getEnd() { |
|
| 92 | - return $this->end; |
|
| 93 | - } |
|
| 88 | + /** |
|
| 89 | + * @return float |
|
| 90 | + */ |
|
| 91 | + public function getEnd() { |
|
| 92 | + return $this->end; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * @return float |
|
| 97 | - */ |
|
| 98 | - public function getDuration() { |
|
| 99 | - if (!$this->end) { |
|
| 100 | - $this->end = microtime(true); |
|
| 101 | - } |
|
| 102 | - return $this->end - $this->start; |
|
| 103 | - } |
|
| 95 | + /** |
|
| 96 | + * @return float |
|
| 97 | + */ |
|
| 98 | + public function getDuration() { |
|
| 99 | + if (!$this->end) { |
|
| 100 | + $this->end = microtime(true); |
|
| 101 | + } |
|
| 102 | + return $this->end - $this->start; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | * @return array An array of Tag objects. |
| 51 | 51 | */ |
| 52 | 52 | public function loadTags($owners, $type) { |
| 53 | - if(!is_array($owners)) { |
|
| 53 | + if (!is_array($owners)) { |
|
| 54 | 54 | $owners = array($owners); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
| 57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
| 58 | + . 'WHERE `uid` IN ('.str_repeat('?,', count($owners) - 1).'?) AND `type` = ? ORDER BY `category`'; |
|
| 59 | 59 | return $this->findEntities($sql, array_merge($owners, array($type))); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @return bool |
| 67 | 67 | */ |
| 68 | 68 | public function tagExists($tag) { |
| 69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
| 70 | 70 | . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
| 71 | 71 | try { |
| 72 | 72 | $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
@@ -33,47 +33,47 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class TagMapper extends Mapper { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor. |
|
| 38 | - * |
|
| 39 | - * @param IDBConnection $db Instance of the Db abstraction layer. |
|
| 40 | - */ |
|
| 41 | - public function __construct(IDBConnection $db) { |
|
| 42 | - parent::__construct($db, 'vcategory', Tag::class); |
|
| 43 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor. |
|
| 38 | + * |
|
| 39 | + * @param IDBConnection $db Instance of the Db abstraction layer. |
|
| 40 | + */ |
|
| 41 | + public function __construct(IDBConnection $db) { |
|
| 42 | + parent::__construct($db, 'vcategory', Tag::class); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Load tags from the database. |
|
| 47 | - * |
|
| 48 | - * @param array|string $owners The user(s) whose tags we are going to load. |
|
| 49 | - * @param string $type The type of item for which we are loading tags. |
|
| 50 | - * @return array An array of Tag objects. |
|
| 51 | - */ |
|
| 52 | - public function loadTags($owners, $type) { |
|
| 53 | - if(!is_array($owners)) { |
|
| 54 | - $owners = array($owners); |
|
| 55 | - } |
|
| 45 | + /** |
|
| 46 | + * Load tags from the database. |
|
| 47 | + * |
|
| 48 | + * @param array|string $owners The user(s) whose tags we are going to load. |
|
| 49 | + * @param string $type The type of item for which we are loading tags. |
|
| 50 | + * @return array An array of Tag objects. |
|
| 51 | + */ |
|
| 52 | + public function loadTags($owners, $type) { |
|
| 53 | + if(!is_array($owners)) { |
|
| 54 | + $owners = array($owners); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
| 59 | - return $this->findEntities($sql, array_merge($owners, array($type))); |
|
| 60 | - } |
|
| 57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 58 | + . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
| 59 | + return $this->findEntities($sql, array_merge($owners, array($type))); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Check if a given Tag object already exists in the database. |
|
| 64 | - * |
|
| 65 | - * @param Tag $tag The tag to look for in the database. |
|
| 66 | - * @return bool |
|
| 67 | - */ |
|
| 68 | - public function tagExists($tag) { |
|
| 69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 70 | - . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
| 71 | - try { |
|
| 72 | - $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
| 73 | - } catch (DoesNotExistException $e) { |
|
| 74 | - return false; |
|
| 75 | - } |
|
| 76 | - return true; |
|
| 77 | - } |
|
| 62 | + /** |
|
| 63 | + * Check if a given Tag object already exists in the database. |
|
| 64 | + * |
|
| 65 | + * @param Tag $tag The tag to look for in the database. |
|
| 66 | + * @return bool |
|
| 67 | + */ |
|
| 68 | + public function tagExists($tag) { |
|
| 69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 70 | + . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
| 71 | + try { |
|
| 72 | + $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
| 73 | + } catch (DoesNotExistException $e) { |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 76 | + return true; |
|
| 77 | + } |
|
| 78 | 78 | } |
| 79 | 79 | |
@@ -37,54 +37,54 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class Tag extends Entity { |
| 39 | 39 | |
| 40 | - protected $owner; |
|
| 41 | - protected $type; |
|
| 42 | - protected $name; |
|
| 40 | + protected $owner; |
|
| 41 | + protected $type; |
|
| 42 | + protected $name; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Constructor. |
|
| 46 | - * |
|
| 47 | - * @param string $owner The tag's owner |
|
| 48 | - * @param string $type The type of item this tag is used for |
|
| 49 | - * @param string $name The tag's name |
|
| 50 | - */ |
|
| 51 | - public function __construct($owner = null, $type = null, $name = null) { |
|
| 52 | - $this->setOwner($owner); |
|
| 53 | - $this->setType($type); |
|
| 54 | - $this->setName($name); |
|
| 55 | - } |
|
| 44 | + /** |
|
| 45 | + * Constructor. |
|
| 46 | + * |
|
| 47 | + * @param string $owner The tag's owner |
|
| 48 | + * @param string $type The type of item this tag is used for |
|
| 49 | + * @param string $name The tag's name |
|
| 50 | + */ |
|
| 51 | + public function __construct($owner = null, $type = null, $name = null) { |
|
| 52 | + $this->setOwner($owner); |
|
| 53 | + $this->setType($type); |
|
| 54 | + $this->setName($name); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Transform a database columnname to a property |
|
| 59 | - * |
|
| 60 | - * @param string $columnName the name of the column |
|
| 61 | - * @return string the property name |
|
| 62 | - * @todo migrate existing database columns to the correct names |
|
| 63 | - * to be able to drop this direct mapping |
|
| 64 | - */ |
|
| 65 | - public function columnToProperty($columnName){ |
|
| 66 | - if ($columnName === 'category') { |
|
| 67 | - return 'name'; |
|
| 68 | - } elseif ($columnName === 'uid') { |
|
| 69 | - return 'owner'; |
|
| 70 | - } else { |
|
| 71 | - return parent::columnToProperty($columnName); |
|
| 72 | - } |
|
| 73 | - } |
|
| 57 | + /** |
|
| 58 | + * Transform a database columnname to a property |
|
| 59 | + * |
|
| 60 | + * @param string $columnName the name of the column |
|
| 61 | + * @return string the property name |
|
| 62 | + * @todo migrate existing database columns to the correct names |
|
| 63 | + * to be able to drop this direct mapping |
|
| 64 | + */ |
|
| 65 | + public function columnToProperty($columnName){ |
|
| 66 | + if ($columnName === 'category') { |
|
| 67 | + return 'name'; |
|
| 68 | + } elseif ($columnName === 'uid') { |
|
| 69 | + return 'owner'; |
|
| 70 | + } else { |
|
| 71 | + return parent::columnToProperty($columnName); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Transform a property to a database column name |
|
| 77 | - * |
|
| 78 | - * @param string $property the name of the property |
|
| 79 | - * @return string the column name |
|
| 80 | - */ |
|
| 81 | - public function propertyToColumn($property){ |
|
| 82 | - if ($property === 'name') { |
|
| 83 | - return 'category'; |
|
| 84 | - } elseif ($property === 'owner') { |
|
| 85 | - return 'uid'; |
|
| 86 | - } else { |
|
| 87 | - return parent::propertyToColumn($property); |
|
| 88 | - } |
|
| 89 | - } |
|
| 75 | + /** |
|
| 76 | + * Transform a property to a database column name |
|
| 77 | + * |
|
| 78 | + * @param string $property the name of the property |
|
| 79 | + * @return string the column name |
|
| 80 | + */ |
|
| 81 | + public function propertyToColumn($property){ |
|
| 82 | + if ($property === 'name') { |
|
| 83 | + return 'category'; |
|
| 84 | + } elseif ($property === 'owner') { |
|
| 85 | + return 'uid'; |
|
| 86 | + } else { |
|
| 87 | + return parent::propertyToColumn($property); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @todo migrate existing database columns to the correct names |
| 63 | 63 | * to be able to drop this direct mapping |
| 64 | 64 | */ |
| 65 | - public function columnToProperty($columnName){ |
|
| 65 | + public function columnToProperty($columnName) { |
|
| 66 | 66 | if ($columnName === 'category') { |
| 67 | 67 | return 'name'; |
| 68 | 68 | } elseif ($columnName === 'uid') { |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @param string $property the name of the property |
| 79 | 79 | * @return string the column name |
| 80 | 80 | */ |
| 81 | - public function propertyToColumn($property){ |
|
| 81 | + public function propertyToColumn($property) { |
|
| 82 | 82 | if ($property === 'name') { |
| 83 | 83 | return 'category'; |
| 84 | 84 | } elseif ($property === 'owner') { |