new functions
This commit is contained in:
80
app/Services/ProjectCodeService.php
Normal file
80
app/Services/ProjectCodeService.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Services\ProjectCodeValidator;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class ProjectCodeService
|
||||
{
|
||||
protected ProjectCodeValidator $validator;
|
||||
|
||||
public function __construct(ProjectCodeValidator $validator)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un validador para un proyecto específico
|
||||
*/
|
||||
public function forProject(Project $project): ProjectCodeValidator
|
||||
{
|
||||
// Si es un modelo Eloquent, convertir a array
|
||||
//$projectData = $project instanceof Project ? $project->toArray() : $project;
|
||||
|
||||
return new ProjectCodeValidator($project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Valida un código rápidamente
|
||||
*/
|
||||
public function validate(Project $project, string $code): bool
|
||||
{
|
||||
$validator = $this->forProject($project);
|
||||
return $validator->validate($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Analiza un código y devuelve detalles
|
||||
*/
|
||||
public function analyze(Project $project, string $code): array
|
||||
{
|
||||
$validator = $this->forProject($project);
|
||||
return $validator->analyze($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera un nuevo código para el proyecto
|
||||
*/
|
||||
public function generate(
|
||||
Project $project,
|
||||
array $components,
|
||||
string $documentName
|
||||
): string
|
||||
{
|
||||
$validator = $this->forProject($project);
|
||||
return $validator->generateCode($components, $documentName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene la configuración de codificación
|
||||
*/
|
||||
public function getConfiguration(Project $project): array
|
||||
{
|
||||
$validator = $this->forProject($project);
|
||||
|
||||
return [
|
||||
'format' => $validator->getFormat(),
|
||||
'reference' => $validator->getReference(),
|
||||
'separator' => $validator->getSeparator(),
|
||||
'sequence_length' => $validator->getSequenceLength(),
|
||||
'components' => [
|
||||
'maker' => $validator->getAllowedCodesForComponent('maker'),
|
||||
'system' => $validator->getAllowedCodesForComponent('system'),
|
||||
'discipline' => $validator->getAllowedCodesForComponent('discipline'),
|
||||
'document_type' => $validator->getAllowedCodesForComponent('document_type'),
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user