|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CSlant\Blog\Api\Services; |
|
4
|
|
|
|
|
5
|
|
|
use CSlant\Blog\Core\Constants\AppConstant; |
|
|
|
|
|
|
6
|
|
|
use CSlant\Blog\Core\Facades\Base\MetaBox; |
|
7
|
|
|
use CSlant\Blog\Core\Models\Category; |
|
8
|
|
|
use CSlant\Blog\Core\Models\Page; |
|
9
|
|
|
use CSlant\Blog\Core\Models\Post; |
|
10
|
|
|
use CSlant\Blog\Core\Models\Tag; |
|
11
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
12
|
|
|
|
|
13
|
|
|
class MetaBoxService |
|
14
|
|
|
{ |
|
15
|
|
|
protected function getSEOMetaBoxByModel(Model $model, string $lang = AppConstant::DEFAULT_LOCALE): ?Model |
|
16
|
|
|
{ |
|
17
|
|
|
$metaKey = $lang === 'vi' ? 'seo_meta_vi' : 'seo_meta'; |
|
18
|
|
|
|
|
19
|
|
|
return MetaBox::getMeta($model, $metaKey); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
protected function getModelMetaBox(string $modelClass, int $modelId, string $lang = AppConstant::DEFAULT_LOCALE): ?Model |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var Model $modelClass */ |
|
25
|
|
|
$model = $modelClass::query()->find($modelId); |
|
26
|
|
|
|
|
27
|
|
|
if (!$model) { |
|
28
|
|
|
return null; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
return $this->getSEOMetaBoxByModel($model, $lang); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getPostMetaBox(int $modelId, string $lang): ?Model |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->getModelMetaBox(Post::getBaseModel(), $modelId, $lang); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getPageMetaBox(int $modelId, string $lang): ?Model |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->getModelMetaBox(Page::getBaseModel(), $modelId, $lang); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getCategoryMetaBox(int $modelId, string $lang): ?Model |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->getModelMetaBox(Category::getBaseModel(), $modelId, $lang); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getTagMetaBox(int $modelId, string $lang): ?Model |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->getModelMetaBox(Tag::getBaseModel(), $modelId, $lang); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $model |
|
56
|
|
|
* @param int $modelId |
|
57
|
|
|
* @param string $lang |
|
58
|
|
|
* |
|
59
|
|
|
* @return null|Model |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getMetaBoxByModel(string $model, int $modelId, string $lang = AppConstant::DEFAULT_LOCALE): ?Model |
|
62
|
|
|
{ |
|
63
|
|
|
if ($model === 'post') { |
|
64
|
|
|
return $this->getPostMetaBox($modelId, $lang); |
|
65
|
|
|
} elseif ($model === 'page') { |
|
66
|
|
|
return $this->getPageMetaBox($modelId, $lang); |
|
67
|
|
|
} elseif ($model === 'category') { |
|
68
|
|
|
return $this->getCategoryMetaBox($modelId, $lang); |
|
69
|
|
|
} elseif ($model === 'tag') { |
|
70
|
|
|
return $this->getTagMetaBox($modelId, $lang); |
|
71
|
|
|
} else { |
|
72
|
|
|
return null; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths