2023-12-15 18:15:55 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\ValidationRules\Company;
|
|
|
|
|
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use App\Utils\Ninja;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ValidCompanyQuantity.
|
|
|
|
*/
|
|
|
|
class ValidExpenseMailbox implements Rule
|
|
|
|
{
|
|
|
|
|
|
|
|
private $validated_schema = false;
|
|
|
|
private $isEnterprise = false;
|
2023-12-15 18:36:17 +01:00
|
|
|
private array $endings;
|
|
|
|
private bool $hasCompanyKey;
|
|
|
|
private array $enterprise_endings;
|
2023-12-15 18:15:55 +01:00
|
|
|
|
2024-04-07 16:30:04 +02:00
|
|
|
public function __construct()
|
2023-12-15 18:15:55 +01:00
|
|
|
{
|
2024-04-04 07:27:07 +02:00
|
|
|
$this->endings = explode(",", config('ninja.inbound_mailbox.expense_mailbox_endings'));
|
2023-12-15 18:15:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function passes($attribute, $value)
|
|
|
|
{
|
2024-04-04 07:27:07 +02:00
|
|
|
if (empty($value)) {
|
2023-12-15 18:15:55 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// early return, if we dont have any additional validation
|
2024-04-04 07:27:07 +02:00
|
|
|
if (!config('ninja.inbound_mailbox.expense_mailbox_endings')) {
|
2023-12-15 18:15:55 +01:00
|
|
|
$this->validated_schema = true;
|
2024-04-04 07:27:07 +02:00
|
|
|
return MultiDB::checkExpenseMailboxAvailable($value);
|
2023-12-15 18:15:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate Schema
|
2023-12-15 18:36:17 +01:00
|
|
|
$validated = false;
|
2023-12-28 10:00:38 +01:00
|
|
|
foreach ($this->endings as $ending) {
|
|
|
|
if (str_ends_with($ending, $value)) {
|
|
|
|
$validated = true;
|
|
|
|
break;
|
2023-12-15 18:36:17 +01:00
|
|
|
}
|
2023-12-28 10:00:38 +01:00
|
|
|
}
|
2023-12-15 18:15:55 +01:00
|
|
|
|
2023-12-28 10:00:38 +01:00
|
|
|
if (!$validated)
|
2023-12-15 18:15:55 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
$this->validated_schema = true;
|
2024-04-04 07:27:07 +02:00
|
|
|
return MultiDB::checkExpenseMailboxAvailable($value);
|
2023-12-15 18:15:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function message()
|
|
|
|
{
|
2023-12-28 10:05:46 +01:00
|
|
|
if (!$this->validated_schema)
|
2024-04-04 07:27:07 +02:00
|
|
|
return ctrans('texts.expense_mailbox_invalid');
|
2023-12-28 10:00:38 +01:00
|
|
|
|
2024-04-04 07:27:07 +02:00
|
|
|
return ctrans('texts.expense_mailbox_taken');
|
2023-12-15 18:15:55 +01:00
|
|
|
}
|
|
|
|
}
|