refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
78
app/Services/BaseService.php
Normal file
78
app/Services/BaseService.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
abstract class BaseService
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the service.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate all datas to execute the service.
|
||||
*
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function validate(array $data): bool
|
||||
{
|
||||
Validator::make($data, $this->rules())
|
||||
->validate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the value is empty or null.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param mixed $index
|
||||
* @return mixed
|
||||
*/
|
||||
public function nullOrValue($data, $index)
|
||||
{
|
||||
$value = Arr::get($data, $index, null);
|
||||
|
||||
return is_null($value) || $value === '' ? null : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the value is empty or null and returns a date from a string.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param mixed $index
|
||||
* @return mixed
|
||||
*/
|
||||
public function nullOrDate($data, $index)
|
||||
{
|
||||
$value = Arr::get($data, $index, null);
|
||||
|
||||
return is_null($value) || $value === '' ? null : Carbon::parse($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value if it's defined, or false otherwise.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param mixed $index
|
||||
* @return mixed
|
||||
*/
|
||||
public function valueOrFalse($data, $index)
|
||||
{
|
||||
if (empty($data[$index])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data[$index];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user