Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117747857
GroupName.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
GroupName.php
View Options
<?php
namespace
App\Rules
;
use
App\User
;
use
Illuminate\Contracts\Validation\Rule
;
use
Illuminate\Support\Str
;
class
GroupName
implements
Rule
{
private
$message
;
private
$owner
;
private
$domain
;
/**
* Class constructor.
*
* @param User $owner The account owner
* @param string $domain The domain name of the group
*/
public
function
__construct
(
$owner
,
$domain
)
{
$this
->
owner
=
$owner
;
$this
->
domain
=
Str
::
lower
(
$domain
);
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute Attribute name
* @param mixed $name The value to validate
*/
public
function
passes
(
$attribute
,
$name
):
bool
{
if
(
empty
(
$name
)
||
!
is_string
(
$name
))
{
$this
->
message
=
\trans
(
'validation.nameinvalid'
);
return
false
;
}
// Check the max length, according to the database column length
if
(
strlen
(
$name
)
>
191
)
{
$this
->
message
=
\trans
(
'validation.max.string'
,
[
'max'
=>
191
]);
return
false
;
}
// Check if the name is unique in the domain
// FIXME: Maybe just using the whole groups table would be faster than groups()?
$exists
=
$this
->
owner
->
groups
()
->
where
(
'name'
,
$name
)
->
where
(
'email'
,
'like'
,
'%@'
.
$this
->
domain
)
->
exists
();
if
(
$exists
)
{
$this
->
message
=
\trans
(
'validation.nameexists'
);
return
false
;
}
return
true
;
}
/**
* Get the validation error message.
*/
public
function
message
():
?
string
{
return
$this
->
message
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Apr 4, 12:37 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18741492
Default Alt Text
GroupName.php (1 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline