-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionModel.php
More file actions
105 lines (88 loc) · 2.35 KB
/
ConnectionModel.php
File metadata and controls
105 lines (88 loc) · 2.35 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace App\Model;
use App\Entity\Connection;
use App\Model\Interface\Configurable;
use App\Model\Interface\Exportable;
use App\Model\Interface\Persistable;
use App\Model\Trait\Config;
use App\Model\Trait\Data;
use App\Model\Trait\Entity;
use App\Model\Trait\Ref;
use App\Model\Trait\Relations;
use App\Service\Webservices;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* @method int getId()
* @method setId( int $id )
* @method string getName()
* @method setName( string $name )
* @method string getDescription()
* @method setDescription( string $description )
*/
class ConnectionModel implements Exportable, Configurable, Persistable
{
use Entity;
use Ref;
use Config;
use Data;
use Relations;
public function __construct( Connection $connection )
{
$this->entity = $connection;
$this->config = $connection->getConfig();
$this->data = $connection->getData();
}
public function getWebservice(): WebserviceModel|null
{
$webservice = $this->getConfig( 'webservice' );
if ( $webservice['_class'] ?? false ) {
return Webservices::getWebservice( $webservice['_class'] );
}
return null;
}
public function handleRequest( Request $request ): Response
{
$config = $request->get( 'config' );
if ( $config ) {
$this->setConfig( json_decode( $config, true ) );
}
$webservice = $this->getWebservice();
if ( ! $webservice ) {
return new Response();
}
return $webservice->handleRequest( $request, $this );
}
public function handleAuthorization( array $config ): array
{
$config = array_merge( $this->getConfig( 'webservice' ), $config );
$webservice = $this->getWebservice();
return $webservice->authorize( $config );
}
public function handleSend( array $config, $data )
{
$config = $this->handleAuthorization( $config );
$webservice = $this->getWebservice();
return $webservice->send( $config, $data );
}
public function handleRetrieve( array $config )
{
$config = $this->handleAuthorization( $config );
$webservice = $this->getWebservice();
return $webservice->retrieve( $config );
}
public static function getFields(): array
{
// @todo Implement fields.
return [
'webservice' => [
'label' => 'Webservice',
'type' => 'webservice',
],
];
}
public static function getEntityClass(): string
{
return Connection::class;
}
}