-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRetrieve.php
More file actions
66 lines (56 loc) · 1.62 KB
/
Retrieve.php
File metadata and controls
66 lines (56 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace App\Task;
use App\Model\ConnectionModel;
use App\Model\TaskModel;
use App\Service\ExecutionContext;
use App\Service\TagParser;
use App\Service\Webservices;
class Retrieve extends TaskModel
{
public function __construct()
{
$this->type = 'request';
$this->name = 'Retrieve';
$this->description = 'Retrieve your data from your specific connection';
parent::__construct();
}
function getFields(): array
{
return [
'connection' => [
'label' => 'Connection',
'type' => 'entity',
'entity' => 'connection',
'config' => 'webservice',
'actions' => [ 'edit', 'create' ],
],
'param' => [
'label' => 'Response param name',
'help' => 'The param name where the results are located',
'type' => 'text',
'placeholder' => 'eg. products',
],
];
}
function execute( array $config, ExecutionContext $context, $data )
{
$connectionConfig = $config['connection'];
if ( ! empty( $connectionConfig['id'] ) ) {
$connection = ConnectionModel::get( $connectionConfig['id'] );
$result = $connection->handleRetrieve( $connectionConfig );
} else {
// @todo Custom webservice without Connection?
$webservice = Webservices::getWebservice( $connectionConfig['_class'] );
$result = $webservice->retrieve( $connectionConfig );
}
if ( ! empty( $config['param'] ) ) {
$parser = new TagParser( (array) $result );
$result = $parser->parseTag( $config['param'] );
}
if ( ! is_array( $result ) ) {
$result = [ 'response' => $result ];
}
// @todo Option to include in current dataset?
return $result;
}
}