1 | <?php |
||
34 | abstract class BaseOrganization extends User |
||
35 | { |
||
36 | use SelfBlameableTrait; |
||
37 | |||
38 | const TYPE_ORGANIZATION = 1; |
||
39 | const TYPE_DEPARTMENT = 2; |
||
40 | |||
41 | /** |
||
42 | * @var boolean Organization does not need password and corresponding features. |
||
43 | */ |
||
44 | public $passwordHashAttribute = false; |
||
45 | |||
46 | /** |
||
47 | * @var boolean Organization does not need password and corresponding features. |
||
48 | */ |
||
49 | public $passwordResetTokenAttribute = false; |
||
50 | |||
51 | /** |
||
52 | * @var boolean Organization does not need password and corresponding features. |
||
53 | */ |
||
54 | public $passwordHistoryClass = false; |
||
55 | |||
56 | /** |
||
57 | * @var boolean Organization does not need source. |
||
58 | */ |
||
59 | public $sourceAttribute = false; |
||
60 | |||
61 | /** |
||
62 | * @var boolean Organization does not need auth key. |
||
63 | */ |
||
64 | public $authKeyAttribute = false; |
||
65 | |||
66 | /** |
||
67 | * @var boolean Organization does not need access token. |
||
68 | */ |
||
69 | public $accessTokenAttribute = false; |
||
70 | |||
71 | /** |
||
72 | * |
||
73 | * @var boolean Organization does not need login log. |
||
74 | */ |
||
75 | public $loginLogClass = false; |
||
76 | |||
77 | public $profileClass = Profile::class; |
||
78 | |||
79 | public $memberClass = Member::class; |
||
80 | private $noInitMember; |
||
81 | /** |
||
82 | * @return Member |
||
83 | */ |
||
84 | protected function getNoInitMember() |
||
92 | 1 | ||
93 | public function init() |
||
106 | |||
107 | /** |
||
108 | * @inheritdoc |
||
109 | */ |
||
110 | public function attributeLabels() |
||
124 | |||
125 | /** |
||
126 | * @inheritdoc |
||
127 | 1 | */ |
|
128 | public static function tableName() |
||
132 | |||
133 | abstract protected function typeAttributeBehavior(); |
||
134 | |||
135 | /** |
||
136 | * @inheritdoc |
||
137 | 1 | */ |
|
138 | public function behaviors() |
||
142 | |||
143 | abstract protected function getTypeRules(); |
||
144 | 1 | ||
145 | public function rules() |
||
149 | |||
150 | /** |
||
151 | * Get Member Query. |
||
152 | * @return MemberQuery |
||
153 | */ |
||
154 | public function getMembers() |
||
158 | |||
159 | /** |
||
160 | * Get member users' query. |
||
161 | * @return BaseUserQuery |
||
162 | */ |
||
163 | public function getMemberUsers() |
||
170 | |||
171 | /** |
||
172 | * Get member with specified user. |
||
173 | * @param User|string|integer $user |
||
174 | * @return Member Null if `user` is not in this organization. |
||
175 | */ |
||
176 | public function getMember($user) |
||
183 | |||
184 | /** |
||
185 | * Add member to organization. |
||
186 | * @param Member|User|string|integer $member |
||
187 | * @see createMemberModel |
||
188 | * @see createMemberModelWithUser |
||
189 | * @return boolean |
||
190 | */ |
||
191 | public function addMember(&$member) |
||
206 | |||
207 | /** |
||
208 | * Create member model, and set organization with this. |
||
209 | * @param Member $member If this parameter is not new record, it's organization |
||
210 | * will be set with this, and return it. Otherwise, it will extract `User` |
||
211 | * model and create new `Member` model. |
||
212 | * @see createMemberModelWithUser |
||
213 | * @return Member |
||
214 | */ |
||
215 | public function createMemberModel($member) |
||
223 | |||
224 | /** |
||
225 | * Create member model with user, and set organization with this. |
||
226 | * @param User|string|integer $user |
||
227 | * @return Member |
||
228 | */ |
||
229 | public function createMemberModelWithUser($user) |
||
241 | |||
242 | /** |
||
243 | * Remove member. |
||
244 | * @param Member|User $member |
||
245 | * @return boolean |
||
246 | */ |
||
247 | public function removeMember(&$member) |
||
255 | } |
||
256 |
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.