1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Similar plugin for Craft CMS 3.x |
4
|
|
|
* |
5
|
|
|
* Similar for Craft lets you find elements, Entries, Categories, Commerce |
6
|
|
|
* Products, etc, that are similar, based on... other related elements. |
7
|
|
|
* |
8
|
|
|
* @link https://nystudio107.com/ |
|
|
|
|
9
|
|
|
* @copyright Copyright (c) 2018 nystudio107.com |
|
|
|
|
10
|
|
|
*/ |
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace nystudio107\similar\services; |
13
|
|
|
|
14
|
|
|
use craft\helpers\ArrayHelper; |
15
|
|
|
use nystudio107\similar\services\Similar as SimilarService; |
16
|
|
|
use yii\base\InvalidConfigException; |
17
|
|
|
|
18
|
|
|
/** |
|
|
|
|
19
|
|
|
* @author nystudio107.com |
|
|
|
|
20
|
|
|
* @package Similar |
|
|
|
|
21
|
|
|
* @since 1.0.0 |
|
|
|
|
22
|
|
|
* |
23
|
|
|
* @property SimilarService $similar |
|
|
|
|
24
|
|
|
*/ |
|
|
|
|
25
|
|
|
trait ServicesTrait |
26
|
|
|
{ |
27
|
|
|
// Public Methods |
28
|
|
|
// ========================================================================= |
29
|
|
|
|
30
|
|
|
/** |
|
|
|
|
31
|
|
|
* @inheritdoc |
32
|
|
|
*/ |
33
|
|
|
public function __construct($id, $parent = null, array $config = []) |
34
|
|
|
{ |
35
|
|
|
// Merge in the passed config, so it our config can be overridden by Plugins::pluginConfigs['similar'] |
36
|
|
|
// ref: https://github.com/craftcms/cms/issues/1989 |
37
|
|
|
$config = ArrayHelper::merge([ |
|
|
|
|
38
|
|
|
'components' => [ |
39
|
|
|
'similar' => SimilarService::class, |
40
|
|
|
], |
41
|
|
|
], $config); |
|
|
|
|
42
|
|
|
|
43
|
|
|
parent::__construct($id, $parent, $config); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Returns the similar service |
48
|
|
|
* |
49
|
|
|
* @return SimilarService The similar service |
50
|
|
|
* @throws InvalidConfigException |
51
|
|
|
*/ |
52
|
|
|
public function getSimilar(): SimilarService |
53
|
|
|
{ |
54
|
|
|
return $this->get('similar'); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|