Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117752370
GroupConfigTrait.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
GroupConfigTrait.php
View Options
<?php
namespace
App\Traits
;
trait
GroupConfigTrait
{
/**
* A helper to get the group configuration.
*/
public
function
getConfig
():
array
{
$config
=
[];
$sp
=
$this
->
getSetting
(
'sender_policy'
);
$config
[
'sender_policy'
]
=
array_filter
(
$sp
?
json_decode
(
$sp
,
true
)
:
[],
static
function
(
$item
)
{
// remove the special "-" entry, it's an implementation detail
return
$item
!==
'-'
;
}
);
return
$config
;
}
/**
* A helper to update a group configuration.
*
* @param array $config An array of configuration options
*
* @return array A list of input validation errors
*/
public
function
setConfig
(
array
$config
):
array
{
$errors
=
[];
foreach
(
$config
as
$key
=>
$value
)
{
// validate and save SMTP sender policy entries
if
(
$key
===
'sender_policy'
)
{
if
(!
is_array
(
$value
))
{
$value
=
(
array
)
$value
;
}
foreach
(
$value
as
$i
=>
$v
)
{
if
(!
is_string
(
$v
))
{
$errors
[
$key
][
$i
]
=
\trans
(
'validation.sp-entry-invalid'
);
}
}
if
(
empty
(
$errors
[
$key
]))
{
// remove empty entries, and '-' entry
$value
=
array_filter
(
$value
,
static
function
(
$item
)
{
return
$item
!==
''
&&
$item
!==
'-'
;
});
if
(!
empty
(
$value
))
{
$value
[]
=
'-'
;
// Block anyone not on the list
}
$this
->
setSetting
(
$key
,
json_encode
(
$value
));
}
}
else
{
$errors
[
$key
]
=
\trans
(
'validation.invalid-config-parameter'
);
}
}
return
$errors
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Apr 4, 4:02 AM (15 h, 43 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
48/3d/8ae8a20fe6846e1fef66e0ae9521
Default Alt Text
GroupConfigTrait.php (1 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline