Passed
Push — master ( 95d3b3...37ba81 )
by Adrien
07:02
created

User::setMobilePhone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Acl\Acl;
8
use Application\Api\Exception;
9
use Application\DBAL\Types\BillingTypeType;
10
use Application\DBAL\Types\RelationshipType;
11
use Application\ORM\Query\Filter\AclFilter;
12
use Application\Traits\HasAddress;
13
use Application\Traits\HasDoorAccess;
14
use Application\Traits\HasRemarks;
15
use Cake\Chronos\Chronos;
16
use Cake\Chronos\Date;
17
use Doctrine\Common\Collections\ArrayCollection;
18
use Doctrine\Common\Collections\Collection;
19
use Doctrine\ORM\Mapping as ORM;
20
use GraphQL\Doctrine\Annotation as API;
21
22
/**
23
 * User
24
 *
25
 * @ORM\Entity(repositoryClass="Application\Repository\UserRepository")
26
 * @ORM\AssociationOverrides({
27
 *     @ORM\AssociationOverride(name="owner", inversedBy="users")
28
 * })
29
 */
30
class User extends AbstractModel
31
{
32
    const ROLE_ANONYMOUS = 'anonymous';
33
    const ROLE_BOOKING_ONLY = 'booking_only';
34
    const ROLE_INDIVIDUAL = 'individual';
35
    const ROLE_MEMBER = 'member';
36
    const ROLE_RESPONSIBLE = 'responsible';
37
    const ROLE_ADMINISTRATOR = 'administrator';
38
39
    const STATUS_INACTIVE = 'inactive';
40
    const STATUS_NEW = 'new';
41
    const STATUS_ACTIVE = 'active';
42
    const STATUS_ARCHIVED = 'archived';
43
44
    use HasDoorAccess;
45
    use HasRemarks;
46
    use HasAddress;
47
48
    /**
49
     * @var User
50
     */
51
    private static $currentUser;
52
53
    /**
54
     * Set currently logged in user
55
     * WARNING: this method should only be called from \Application\Authentication\AuthenticationListener
56
     *
57
     * @param \Application\Model\User $user
58
     */
59 57
    public static function setCurrent(?self $user): void
60
    {
61 57
        self::$currentUser = $user;
62
63
        // Initalize ACL filter with current user if a logged in one exists
64 57
        _em()->getFilters()->getFilter(AclFilter::class)->setUser($user);
65 57
    }
66
67
    /**
68
     * Returns currently logged user or null
69
     *
70
     * @return null|self
71
     */
72 45
    public static function getCurrent(): ?self
73
    {
74 45
        return self::$currentUser;
75
    }
76
77
    /**
78
     * @var null|string
79
     *
80
     * @ORM\Column(type="string", length=50, nullable=true, unique=true)
81
     */
82
    private $login;
83
84
    /**
85
     * @var string
86
     * @ORM\Column(type="string", length=191)
87
     */
88
    private $firstName = '';
89
90
    /**
91
     * @var string
92
     * @ORM\Column(type="string", length=191)
93
     */
94
    private $lastName = '';
95
96
    /**
97
     * @var string
98
     *
99
     * @ORM\Column(type="string", length=255)
100
     */
101
    private $password = '';
102
103
    /**
104
     * @var null|string
105
     * @ORM\Column(type="string", length=191, nullable=true, unique=true)
106
     */
107
    private $email;
108
109
    /**
110
     * @var string
111
     * @ORM\Column(type="UserRole", options={"default" = User::ROLE_INDIVIDUAL})
112
     */
113
    private $role = self::ROLE_INDIVIDUAL;
114
115
    /**
116
     * @var string
117
     * @ORM\Column(type="UserStatus", options={"default" = User::STATUS_NEW})
118
     */
119
    private $status = self::STATUS_NEW;
120
121
    /**
122
     * @var null|Chronos
123
     * @ORM\Column(type="datetime", nullable=true)
124
     */
125
    private $lastLogin;
126
127
    /**
128
     * @var null|Chronos
129
     * @ORM\Column(type="datetime", nullable=true)
130
     */
131
    private $welcomeSessionDate;
132
133
    /**
134
     * @var int sex according to ISO/IEC 5218
135
     * @ORM\Column(type="smallint", options={"default" = 0}))
136
     */
137
    private $sex = 0;
138
139
    /**
140
     * @var string
141
     * @ORM\Column(type="string", length=25, options={"default" = ""})
142
     */
143
    private $phone = '';
144
145
    /**
146
     * @var string
147
     * @ORM\Column(type="string", length=25, options={"default" = ""})
148
     */
149
    private $mobilePhone = '';
150
151
    /**
152
     * @var string
153
     * @ORM\Column(type="string", length=25, options={"default" = ""})
154
     */
155
    private $ichtusSwissSailing = '';
156
157
    /**
158
     * @var null|Date
159
     * @ORM\Column(type="date", nullable=true)
160
     */
161
    private $birthday;
162
163
    /**
164
     * @var bool
165
     * @ORM\Column(type="boolean", options={"default" = 0})
166
     */
167
    private $termsAgreement = false;
168
169
    /**
170
     * @var bool
171
     * @ORM\Column(type="boolean", options={"default" = 0})
172
     */
173
    private $hasInsurance = false;
174
175
    /**
176
     * @var bool
177
     * @ORM\Column(type="boolean", options={"default" = 0})
178
     */
179
    private $receivesNewsletter = false;
180
181
    /**
182
     * @var string
183
     * @ORM\Column(type="Relationship", options={"default" = RelationshipType::HOUSEHOLDER})
184
     */
185
    private $familyRelationship = RelationshipType::HOUSEHOLDER;
186
187
    /**
188
     * @var string
189
     * @ORM\Column(type="BillingType", options={"default" = BillingTypeType::ALL_ELECTRONIC})
190
     */
191
    private $billingType = BillingTypeType::ALL_ELECTRONIC;
192
193
    /**
194
     * @var null|string
195
     * @ORM\Column(type="string", length=32, nullable=true, unique=true)
196
     */
197
    private $token;
198
199
    /**
200
     * @var null|Chronos
201
     *
202
     * @ORM\Column(type="datetime", nullable=true)
203
     */
204
    private $tokenCreationDate;
205
206
    /**
207
     * @var Collection
208
     * @ORM\OneToMany(targetEntity="Booking", mappedBy="owner")
209
     */
210
    private $bookings;
211
212
    /**
213
     * @var Collection
214
     * @ORM\ManyToMany(targetEntity="License", mappedBy="users")
215
     */
216
    private $licenses;
217
218
    /**
219
     * @var Collection
220
     * @ORM\ManyToMany(targetEntity="UserTag", mappedBy="users")
221
     */
222
    private $userTags;
223
224
    /**
225
     * @var Collection
226
     * @ORM\OneToMany(targetEntity="Message", mappedBy="recipient")
227
     */
228
    private $messages;
229
230
    /**
231
     * There is actually 0 to 1 account, never more. And this is
232
     * enforced by DB unique constraints
233
     *
234
     * @var Collection
235
     * @ORM\OneToMany(targetEntity="Account", mappedBy="owner")
236
     */
237
    private $accounts;
238
239
    /**
240
     * @var Collection
241
     * @ORM\OneToMany(targetEntity="User", mappedBy="owner")
242
     */
243
    private $users;
244
245
    /**
246
     * Constructor
247
     *
248
     * @param string $role role for new user
249
     */
250 28
    public function __construct(string $role = self::ROLE_INDIVIDUAL)
251
    {
252 28
        $this->role = $role;
253 28
        $this->bookings = new ArrayCollection();
254 28
        $this->accounts = new ArrayCollection();
255 28
        $this->licenses = new ArrayCollection();
256 28
        $this->userTags = new ArrayCollection();
257 28
        $this->messages = new ArrayCollection();
258 28
        $this->users = new ArrayCollection();
259 28
    }
260
261
    /**
262
     * Set login (eg: johndoe)
263
     *
264
     * @API\Input(type="Login")
265
     *
266
     * @param string $login
267
     */
268 2
    public function setLogin(string $login): void
269
    {
270 2
        $this->login = $login;
271 2
    }
272
273
    /**
274
     * Get login (eg: johndoe)
275
     *
276
     * @API\Field(type="?Login")
277
     *
278
     * @return null|string
279
     */
280 11
    public function getLogin(): ?string
281
    {
282 11
        return $this->login;
283
    }
284
285
    /**
286
     * Hash and change the user password
287
     *
288
     * @param string $password
289
     */
290 6
    public function setPassword(string $password): void
291
    {
292
        // Ignore empty password that could be sent "by mistake" by the client
293
        // when agreeing to terms
294 6
        if ($password === '') {
295 1
            return;
296
        }
297
298 6
        $this->revokeToken();
299
300 6
        $this->password = password_hash($password, PASSWORD_DEFAULT);
301 6
    }
302
303
    /**
304
     * Returns the hashed password
305
     *
306
     * @API\Exclude
307
     *
308
     * @return string
309
     */
310 3
    public function getPassword(): string
311
    {
312 3
        return $this->password;
313
    }
314
315
    /**
316
     * Set first name
317
     *
318
     * @param string $firstName
319
     */
320 2
    public function setFirstName($firstName): void
321
    {
322 2
        $this->firstName = $firstName;
323 2
    }
324
325
    /**
326
     * Get first name
327
     *
328
     * @return string
329
     */
330 4
    public function getFirstName(): string
331
    {
332 4
        return (string) $this->firstName;
333
    }
334
335
    /**
336
     * Set last name
337
     *
338
     * @param string $lastName
339
     */
340 2
    public function setLastName($lastName): void
341
    {
342 2
        $this->lastName = $lastName;
343 2
    }
344
345
    /**
346
     * Get last name
347
     *
348
     * @return string
349
     */
350 1
    public function getLastName(): string
351
    {
352 1
        return (string) $this->lastName;
353
    }
354
355
    /**
356
     * Get full name
357
     *
358
     * @return string
359
     */
360 1
    public function getName(): string
361
    {
362 1
        return implode(' ', [$this->getFirstName(), $this->getLastName()]);
363
    }
364
365
    /**
366
     * Set email
367
     *
368
     * @API\Input(type="?Email")
369
     *
370
     * @param string $email
371
     */
372 3
    public function setEmail(string $email): void
373
    {
374 3
        $this->email = $email;
375 3
    }
376
377
    /**
378
     * Get email
379
     *
380
     * @API\Field(type="?Email")
381
     *
382
     * @return null|string
383
     */
384 5
    public function getEmail(): ?string
385
    {
386 5
        return $this->email;
387
    }
388
389
    /**
390
     * Returns whether the user is administrator and thus have can do anything.
391
     *
392
     * @API\Field(type="Application\Api\Enum\UserRoleType")
393
     */
394 30
    public function getRole(): string
395
    {
396 30
        return $this->role;
397
    }
398
399
    /**
400
     * Sets the user role
401
     *
402
     * The current user is allowed to promote another user up to the same role as himself. So
403
     * a Responsible can promote a Member to Responsible. Or an Admin can promote a Individual to Admin.
404
     *
405
     * But the current user is **not** allowed to demote a user who has a higher role than himself.
406
     * That means that a Responsible cannot demote an Admin to Individual.
407
     *
408
     * @param string $role
409
     */
410 7
    public function setRole(string $role): void
411
    {
412 7
        if ($role === $this->role) {
413 2
            return;
414
        }
415
416 5
        $currentRole = self::getCurrent() ? self::getCurrent()->getRole() : self::ROLE_ANONYMOUS;
417
        $orderedRoles = [
418 5
            self::ROLE_ANONYMOUS,
419 5
            self::ROLE_INDIVIDUAL,
420 5
            self::ROLE_MEMBER,
421 5
            self::ROLE_RESPONSIBLE,
422 5
            self::ROLE_ADMINISTRATOR,
423
        ];
424
425 5
        $newFound = false;
426 5
        $oldFound = false;
427 5
        foreach ($orderedRoles as $r) {
428 5
            if ($r === $this->role) {
429 3
                $oldFound = true;
430
            }
431 5
            if ($r === $role) {
432 2
                $newFound = true;
433
            }
434
435 5
            if ($r === $currentRole) {
436 5
                break;
437
            }
438
        }
439
440 5
        if (!$newFound || !$oldFound) {
441 3
            throw new Exception($currentRole . ' is not allowed to change role from ' . $this->role . ' to ' . $role);
442
        }
443
444 2
        $this->role = $role;
445 2
    }
446
447 5
    public function setOwner(self $owner = null): void
448
    {
449 5
        if ($owner && $owner !== $this) {
450 4
            if ($owner->getOwner() && $owner !== $owner->getOwner()) {
451 1
                throw new Exception('This user cannot be owned by a user who is himself owned by somebody else');
452
            }
453
454 4
            if ($this->users->count()) {
455 1
                throw new Exception('This user owns other users, so he cannot himself be owned by somebody else');
456
            }
457
        }
458
459 5
        if ($this->getOwner()) {
460
            $this->getOwner()->users->removeElement($this);
461
        }
462
463 5
        parent::setOwner($owner);
464
465 5
        if ($this->getOwner()) {
466 4
            $this->getOwner()->users->add($this);
467 4
            $this->setStatus($this->getOwner()->getStatus());
468
        }
469 5
    }
470
471
    /**
472
     * @API\Field(type="Application\Api\Enum\UserStatusType")
473
     *
474
     * @return string
475
     */
476 4
    public function getStatus(): string
477
    {
478 4
        return $this->status;
479
    }
480
481
    /**
482
     * @API\Input(type="Application\Api\Enum\UserStatusType")
483
     *
484
     * @param string $status
485
     */
486 6
    public function setStatus(string $status): void
487
    {
488 6
        $this->status = $status;
489 6
        $this->revokeToken();
490
491 6
        foreach ($this->users as $user) {
492 3
            if ($user !== $this) {
493 1
                $user->setStatus($status);
494
            }
495
        }
496 6
    }
497
498 1
    public function activate(): void
499
    {
500 1
        $this->role = self::ROLE_MEMBER; // Bypass security
501 1
        $this->setStatus(self::STATUS_ACTIVE);
502 1
    }
503
504
    /**
505
     * @return string
506
     */
507
    public function getPhone(): string
508
    {
509
        return $this->phone;
510
    }
511
512
    /**
513
     * @param string $phone
514
     */
515
    public function setPhone(string $phone): void
516
    {
517
        $this->phone = $phone;
518
    }
519
520
    /**
521
     * @return string
522
     */
523
    public function getMobilePhone(): string
524
    {
525
        return $this->mobilePhone;
526
    }
527
528
    /**
529
     * @param string $mobilePhone
530
     */
531
    public function setMobilePhone(string $mobilePhone): void
532
    {
533
        $this->mobilePhone = $mobilePhone;
534
    }
535
536
    /**
537
     * @return null|Date
538
     */
539
    public function getBirthday(): ?Date
540
    {
541
        return $this->birthday;
542
    }
543
544
    /**
545
     * @param null|Date $birthday
546
     */
547
    public function setBirthday(?Date $birthday): void
548
    {
549
        $this->birthday = $birthday;
550
    }
551
552
    /**
553
     * Get bookings
554
     *
555
     * @return Collection
556
     */
557 1
    public function getBookings(): Collection
558
    {
559 1
        return $this->bookings;
560
    }
561
562
    /**
563
     * Notify the user that it has a new booking.
564
     * This should only be called by Booking::setResponsible()
565
     *
566
     * @param Booking $booking
567
     */
568 8
    public function bookingAdded(Booking $booking): void
569
    {
570 8
        $this->bookings->add($booking);
571 8
    }
572
573
    /**
574
     * Notify the user that it has a booking was removed.
575
     * This should only be called by Booking::setResponsible()
576
     *
577
     * @param Booking $booking
578
     */
579 4
    public function bookingRemoved(Booking $booking): void
580
    {
581 4
        $this->bookings->removeElement($booking);
582 4
    }
583
584
    /**
585
     * @return Collection
586
     */
587 1
    public function getLicenses(): Collection
588
    {
589 1
        return $this->licenses;
590
    }
591
592
    /**
593
     * @return Collection
594
     */
595 1
    public function getUserTags(): Collection
596
    {
597 1
        return $this->userTags;
598
    }
599
600
    /**
601
     * Notify the user that it has a new license.
602
     * This should only be called by License::addUser()
603
     *
604
     * @param License $license
605
     */
606 1
    public function licenseAdded(License $license): void
607
    {
608 1
        $this->licenses->add($license);
609 1
    }
610
611
    /**
612
     * Notify the user that it a license was removed.
613
     * This should only be called by License::removeUser()
614
     *
615
     * @param License $license
616
     */
617 1
    public function licenseRemoved(License $license): void
618
    {
619 1
        $this->licenses->removeElement($license);
620 1
    }
621
622
    /**
623
     * Notify the user that it has a new userTag.
624
     * This should only be called by UserTag::addUser()
625
     *
626
     * @param UserTag $userTag
627
     */
628 1
    public function userTagAdded(UserTag $userTag): void
629
    {
630 1
        $this->userTags->add($userTag);
631 1
    }
632
633
    /**
634
     * Notify the user that a userTag was removed.
635
     * This should only be called by UserTag::removeUser()
636
     *
637
     * @param UserTag $userTag
638
     */
639 1
    public function userTagRemoved(UserTag $userTag): void
640
    {
641 1
        $this->userTags->removeElement($userTag);
642 1
    }
643
644
    /**
645
     * @return bool
646
     */
647
    public function isTermsAgreement(): bool
648
    {
649
        return $this->termsAgreement;
650
    }
651
652
    /**
653
     * @param bool $termsAgreement
654
     */
655 1
    public function setTermsAgreement(bool $termsAgreement): void
656
    {
657 1
        $this->termsAgreement = $termsAgreement;
658 1
    }
659
660
    /**
661
     * @return bool
662
     */
663
    public function getHasInsurance(): bool
664
    {
665
        return $this->hasInsurance;
666
    }
667
668
    /**
669
     * @param bool $hasInsurance
670
     */
671 1
    public function setHasInsurance(bool $hasInsurance): void
672
    {
673 1
        $this->hasInsurance = $hasInsurance;
674 1
    }
675
676
    /**
677
     * @return null|Chronos
678
     */
679
    public function getWelcomeSessionDate(): ?Chronos
680
    {
681
        return $this->welcomeSessionDate;
682
    }
683
684
    /**
685
     * @param null|Chronos $welcomeSessionDate
686
     */
687
    public function setWelcomeSessionDate(?Chronos $welcomeSessionDate): void
688
    {
689
        $this->welcomeSessionDate = $welcomeSessionDate;
690
    }
691
692
    /**
693
     * @return bool
694
     */
695
    public function isReceivesNewsletter(): bool
696
    {
697
        return $this->receivesNewsletter;
698
    }
699
700
    /**
701
     * @param bool $receivesNewsletter
702
     */
703
    public function setReceivesNewsletter(bool $receivesNewsletter): void
704
    {
705
        $this->receivesNewsletter = $receivesNewsletter;
706
    }
707
708
    /**
709
     * Get the ISO/IEC 5218 sex
710
     *
711
     * @API\Field(type="Sex")
712
     *
713
     * @return int
714
     */
715
    public function getSex(): int
716
    {
717
        return $this->sex;
718
    }
719
720
    /**
721
     * Set the ISO/IEC 5218 sex
722
     *
723
     * @API\Input(type="Sex")
724
     *
725
     * @param int $sex
726
     */
727
    public function setSex(int $sex): void
728
    {
729
        $this->sex = $sex;
730
    }
731
732
    /**
733
     * @return string
734
     */
735
    public function getIchtusSwissSailing(): string
736
    {
737
        return $this->ichtusSwissSailing;
738
    }
739
740
    /**
741
     * @param string $ichtusSwissSailing
742
     */
743
    public function setIchtusSwissSailing(string $ichtusSwissSailing): void
744
    {
745
        $this->ichtusSwissSailing = $ichtusSwissSailing;
746
    }
747
748
    /**
749
     * Get the last login
750
     *
751
     * @return null|Chronos
752
     */
753
    public function getLastLogin(): ?Chronos
754
    {
755
        return $this->lastLogin;
756
    }
757
758
    /**
759
     * @param null|Chronos $lastLogin
760
     */
761 3
    public function setLastLogin(?Chronos $lastLogin): void
762
    {
763 3
        $this->lastLogin = $lastLogin;
764 3
        $this->revokeToken();
765 3
    }
766
767
    /**
768
     * @API\Field(type="Relationship")
769
     *
770
     * @return string
771
     */
772 1
    public function getFamilyRelationship(): string
773
    {
774 1
        return $this->familyRelationship;
775
    }
776
777
    /**
778
     * @API\Input(type="Relationship")
779
     *
780
     * @param string $familyRelationship
781
     */
782
    public function setFamilyRelationship(string $familyRelationship): void
783
    {
784
        $this->familyRelationship = $familyRelationship;
785
    }
786
787
    /**
788
     * @return string
789
     */
790
    public function getBillingType(): string
791
    {
792
        return $this->billingType;
793
    }
794
795
    /**
796
     * @param string $billingType
797
     */
798
    public function setBillingType(string $billingType): void
799
    {
800
        $this->billingType = $billingType;
801
    }
802
803
    /**
804
     * Get the user transaction account
805
     *
806
     * @return null|Account
807
     */
808 1
    public function getAccount(): ?Account
809
    {
810 1
        return $this->accounts->count() ? $this->accounts->first() : null;
811
    }
812
813
    /**
814
     * Notify the user that it has a new account
815
     * This should only be called by Account::setOwner()
816
     *
817
     * @param Account $account
818
     */
819 1
    public function accountAdded(Account $account): void
820
    {
821 1
        $this->accounts->clear();
822 1
        $this->accounts->add($account);
823 1
    }
824
825
    /**
826
     * Notify the user that a account was removed
827
     * This should only be called by Account::setOwner()
828
     */
829 1
    public function accountRemoved(): void
830
    {
831 1
        $this->accounts->clear();
832 1
    }
833
834
    /**
835
     * Get messages sent to the user
836
     *
837
     * @return Collection
838
     */
839 1
    public function getMessages(): Collection
840
    {
841 1
        return $this->messages;
842
    }
843
844
    /**
845
     * Notify the user that it has a new message
846
     * This should only be called by Message::setRecipient()
847
     *
848
     * @param Message $message
849
     */
850 4
    public function messageAdded(Message $message): void
851
    {
852 4
        $this->messages->add($message);
853 4
    }
854
855
    /**
856
     * Notify the user that a message was removed
857
     * This should only be called by Message::setRecipient()
858
     *
859
     * @param Message $message
860
     */
861 1
    public function messageRemoved(Message $message): void
862
    {
863 1
        $this->messages->removeElement($message);
864 1
    }
865
866
    /**
867
     * Generate a new random token to reset password
868
     */
869 4
    public function createToken(): string
870
    {
871 4
        $this->token = bin2hex(random_bytes(16));
872 4
        $this->tokenCreationDate = new Chronos();
873
874 4
        return $this->token;
875
    }
876
877
    /**
878
     * Destroy existing token
879
     */
880 10
    private function revokeToken(): void
881
    {
882 10
        $this->token = null;
883 10
        $this->tokenCreationDate = null;
884 10
    }
885
886
    /**
887
     * Check if token is valid.
888
     *
889
     * @API\Exclude
890
     *
891
     * @return bool
892
     */
893 3
    public function isTokenValid(): bool
894
    {
895 3
        if (!$this->tokenCreationDate) {
896 1
            return false;
897
        }
898
899 3
        $timeLimit = $this->tokenCreationDate->addMinutes(30);
900
901 3
        return $timeLimit->isFuture();
902
    }
903
904
    /**
905
     * Check if the user can *really* open a door
906
     * This also takes into account the user status, role and IP address
907
     *
908
     * @API\Field(args={@API\Argument(name="door", type="?Application\Api\Enum\DoorType")})
909
     *
910
     * @param null|string $door a particular door, or null for any
911
     *
912
     * @return bool
913
     */
914
    public function getCanOpenDoor(?string $door = null): bool
915
    {
916
        global $container;
917
918
        $allowedStatus = [self::STATUS_ACTIVE];
919
        $allowedRoles = [self::ROLE_MEMBER, self::ROLE_RESPONSIBLE, self::ROLE_ADMINISTRATOR];
920
        if ($door && !$this->$door) {
921
            return false;
922
        }
923
        if (!in_array($this->status, $allowedStatus, true) || !in_array($this->role, $allowedRoles, true)) {
924
            return false;
925
        }
926
        $apiConfig = $container->get('config')['doorsApi'];
927
        foreach ($apiConfig['authorizedIps'] as $host) {
928
            if (filter_var($host, FILTER_VALIDATE_DOMAIN) && in_array($_SERVER['REMOTE_ADDR'], gethostbynamel($host), true)) {
929
                return true;
930
            }
931
            if (filter_var($host, FILTER_VALIDATE_IP) && $_SERVER['REMOTE_ADDR'] === $host) {
932
                return true;
933
            }
934
        }
935
936
        return false;
937
    }
938
}
939