1 | <?php |
||
33 | abstract class BaseOrganization extends User |
||
34 | { |
||
35 | use SelfBlameableTrait; |
||
36 | |||
37 | const TYPE_ORGANIZATION = 1; |
||
38 | const TYPE_DEPARTMENT = 2; |
||
39 | |||
40 | /** |
||
41 | * @var boolean Organization does not need password and corresponding features. |
||
42 | */ |
||
43 | public $passwordHashAttribute = false; |
||
44 | |||
45 | /** |
||
46 | * @var boolean Organization does not need password and corresponding features. |
||
47 | */ |
||
48 | public $passwordResetTokenAttribute = false; |
||
49 | |||
50 | /** |
||
51 | * @var boolean Organization does not need password and corresponding features. |
||
52 | */ |
||
53 | public $passwordHistoryClass = false; |
||
54 | |||
55 | /** |
||
56 | * @var boolean Organization does not need source. |
||
57 | */ |
||
58 | public $sourceAttribute = false; |
||
59 | |||
60 | /** |
||
61 | * @var boolean Organization does not need auth key. |
||
62 | */ |
||
63 | public $authKeyAttribute = false; |
||
64 | |||
65 | /** |
||
66 | * @var boolean Organization does not need access token. |
||
67 | */ |
||
68 | public $accessTokenAttribute = false; |
||
69 | |||
70 | /** |
||
71 | * |
||
72 | * @var boolean Organization does not need login log. |
||
73 | */ |
||
74 | public $loginLogClass = false; |
||
75 | |||
76 | public $profileClass = Profile::class; |
||
77 | |||
78 | public $memberClass = Member::class; |
||
79 | private $noInitMember; |
||
80 | /** |
||
81 | * @return Member |
||
82 | */ |
||
83 | protected function getNoInitMember() |
||
91 | |||
92 | 1 | public function init() |
|
105 | |||
106 | /** |
||
107 | * @inheritdoc |
||
108 | */ |
||
109 | public function attributeLabels() |
||
123 | |||
124 | /** |
||
125 | * @inheritdoc |
||
126 | */ |
||
127 | 1 | public static function tableName() |
|
131 | |||
132 | abstract protected function typeAttributeBehavior(); |
||
133 | |||
134 | /** |
||
135 | * @inheritdoc |
||
136 | */ |
||
137 | 1 | public function behaviors() |
|
141 | |||
142 | abstract protected function getTypeRules(); |
||
143 | |||
144 | 1 | public function rules() |
|
148 | |||
149 | /** |
||
150 | * Get Member Query. |
||
151 | * @return MemberQuery |
||
152 | */ |
||
153 | public function getMembers() |
||
157 | |||
158 | /** |
||
159 | * |
||
160 | * @return BaseUserQuery |
||
161 | */ |
||
162 | public function getMemberUsers() |
||
169 | |||
170 | /** |
||
171 | * Add member to organization. |
||
172 | * @param Member|User $member |
||
173 | * @return Member |
||
174 | */ |
||
175 | public function addMember($member) |
||
185 | |||
186 | /** |
||
187 | * Create member model, and set organization with this. |
||
188 | * @param Member $member |
||
189 | * @return Member |
||
190 | */ |
||
191 | protected function createMemberModel($member) |
||
199 | |||
200 | /** |
||
201 | * Create member model with user, and set organization with this. |
||
202 | * @param User|string|integer $user |
||
203 | * @return Member |
||
204 | */ |
||
205 | protected function createMemberModelWithUser($user) |
||
217 | } |
||
218 |
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_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.