|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenStack\Networking\v2\Extensions\SecurityGroups\Models; |
|
4
|
|
|
|
|
5
|
|
|
use OpenStack\Common\Resource\Alias; |
|
6
|
|
|
use OpenStack\Common\Resource\OperatorResource; |
|
7
|
|
|
use OpenStack\Common\Resource\Creatable; |
|
8
|
|
|
use OpenStack\Common\Resource\Deletable; |
|
9
|
|
|
use OpenStack\Common\Resource\Listable; |
|
10
|
|
|
use OpenStack\Common\Resource\Retrievable; |
|
11
|
|
|
use OpenStack\Common\Resource\Updateable; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Represents a SecurityGroup resource in the Network v2 service |
|
15
|
|
|
* |
|
16
|
|
|
* @property \OpenStack\Networking\v2\Extensions\SecurityGroups\Api $api |
|
17
|
|
|
*/ |
|
18
|
|
|
class SecurityGroup extends OperatorResource implements Creatable, Listable, Deletable, Retrievable, Updateable |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
public $description; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $id; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
public $name; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var []SecurityGroupRule |
|
37
|
|
|
*/ |
|
38
|
|
|
public $securityGroupRules; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
public $tenantId; |
|
44
|
|
|
|
|
45
|
|
|
protected $aliases = [ |
|
46
|
|
|
'tenant_id' => 'tenantId', |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
protected $resourceKey = 'security_group'; |
|
50
|
|
|
protected $resourcesKey = 'security_groups'; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @inheritdoc |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function getAliases() |
|
56
|
|
|
{ |
|
57
|
|
|
$aliases = parent::getAliases(); |
|
58
|
|
|
$aliases['security_group_rules'] = new Alias('securityGroupRules', SecurityGroupRule::class, true); |
|
59
|
|
|
$aliases['rules'] = new Alias('securityGroupRules', SecurityGroupRule::class, true); |
|
60
|
|
|
return $aliases; |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritDoc} |
|
65
|
|
|
*/ |
|
66
|
|
|
public function create(array $userOptions): Creatable |
|
67
|
|
|
{ |
|
68
|
|
|
$response = $this->execute($this->api->postSecurityGroups(), $userOptions); |
|
69
|
|
|
return $this->populateFromResponse($response); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritDoc} |
|
74
|
|
|
*/ |
|
75
|
|
|
public function delete() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->executeWithState($this->api->deleteSecurityGroup()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritDoc} |
|
82
|
|
|
*/ |
|
83
|
|
|
public function retrieve() |
|
84
|
|
|
{ |
|
85
|
|
|
$response = $this->executeWithState($this->api->getSecurityGroup()); |
|
86
|
|
|
$this->populateFromResponse($response); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function update() |
|
90
|
|
|
{ |
|
91
|
|
|
$response = $this->executeWithState($this->api->putSecurityGroups()); |
|
92
|
|
|
$this->populateFromResponse($response); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.