QR_code_generator/app/Services/Registries/RegistryImportService.php

39 lines
1.1 KiB
PHP

<?php
namespace App\Services\Registries;
use App\Models\Asset;
use App\Models\Registries\Registry;
use App\Services\Documents\DocumentDownloadService;
use Illuminate\Support\Str;
use PHPHtmlParser\Dom;
class RegistryImportService {
protected Registry $registry;
protected string $url;
protected Dom $dom;
protected array $mimes = [
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'pdf' => 'application/pdf',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
];
public function __construct(Registry $registry, string $url) {
$this->registry = $registry;
$this->url = $url;
$this->dom = new Dom;
$this->dom->loadFromUrl($url);
}
public function download($url, $dir = null, $filename = null): ?Asset {
$info = parse_url($url);
if (empty($info['host'])) {
$url = 'https://' . Str::replace('//', '/', "www.faufcc.ru/{$url}");
}
return (new DocumentDownloadService())->download($url, $dir, $filename);
}
}