ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilGroupNameAsMailValidator.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
10{
12 protected $host;
13
16
21 public function __construct(string $host, callable $groupNameCheckCallable = null)
22 {
23 $this->host = $host;
24
25 if (null === $groupNameCheckCallable) {
26 $groupNameCheckCallable = function (string $groupName) {
27 return ilUtil::groupNameExists($groupName);
28 };
29 }
30
31 $this->groupNameCheckCallable = $groupNameCheckCallable;
32 }
33
39 public function validate(ilMailAddress $address) : bool
40 {
41 $groupName = substr($address->getMailbox(), 1);
42
44 if ($func($groupName) && $this->isHostValid($address->getHost())) {
45 return true;
46 }
47
48 return false;
49 }
50
56 private function isHostValid(string $host) : bool
57 {
58 return ($host == $this->host || 0 === strlen($host));
59 }
60}
An exception for terminatinating execution or to throw for unit testing.
Class ilGroupNameAsMailValidator.
validate(ilMailAddress $address)
Validates if the given address contains a valid group name to send an email.
__construct(string $host, callable $groupNameCheckCallable=null)
isHostValid(string $host)
Checks if the given host is valid in the email context.
Class ilMailAddress.
static groupNameExists($a_group_name, $a_id=0)
checks if group name already exists.