1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @author Mihkel Viilveer <[email protected]> |
5
|
|
|
* @date 22.08.2014 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace opus\elastic\spooler; |
9
|
|
|
|
10
|
|
|
use yii\base\ErrorException; |
11
|
|
|
use yii\console\Controller; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class ElasticController |
15
|
|
|
* |
16
|
|
|
* @author Mihkel Viilveer <[email protected]> |
17
|
|
|
* @package opus\elastic\spooler |
18
|
|
|
*/ |
19
|
|
|
class ElasticController extends Controller |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Data providers to index/spool |
23
|
|
|
* @var string[] |
24
|
|
|
*/ |
25
|
|
|
public $dataProviders = []; |
26
|
|
|
/** |
27
|
|
|
* @throws \yii\base\ErrorException |
28
|
|
|
*/ |
29
|
|
|
public function actionImport() |
30
|
|
|
{ |
31
|
|
|
$elasticManager = new SpoolManager( |
32
|
|
|
[ |
33
|
|
|
'dataProviders' => $this->createDataProviders($this->dataProviders) |
|
|
|
|
34
|
|
|
] |
35
|
|
|
); |
36
|
|
|
$elasticManager->reindex(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @throws \yii\base\ErrorException |
41
|
|
|
*/ |
42
|
|
|
public function actionSpool() |
43
|
|
|
{ |
44
|
|
|
$elasticManager = new SpoolManager( |
45
|
|
|
[ |
46
|
|
|
'dataProviders' => $this->createDataProviders($this->dataProviders) |
|
|
|
|
47
|
|
|
] |
48
|
|
|
); |
49
|
|
|
$elasticManager->spool(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param AbstractDataProvider[] $dataProviders |
54
|
|
|
* @throws ErrorException |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
private function createDataProviders(array $dataProviders) |
58
|
|
|
{ |
59
|
|
|
$dataProviderModels = []; |
60
|
|
|
|
61
|
|
|
foreach ($dataProviders as $dataProvider) { |
62
|
|
|
$dataProvider = new $dataProvider(); |
63
|
|
|
if (!($dataProvider instanceof AbstractDataProvider)) { |
64
|
|
|
throw new ErrorException( |
65
|
|
|
'dataProvider is not instance of DataProviderInterface' |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
$dataProviderModels[] = $dataProvider; |
69
|
|
|
} |
70
|
|
|
return $dataProviderModels; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: