1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
8
|
|
|
* @link https://vistart.me/ |
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
10
|
|
|
* @license https://vistart.me/license/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace rhosocial\organization; |
14
|
|
|
|
15
|
|
|
use rhosocial\organization\queries\MemberQuery; |
16
|
|
|
use rhosocial\organization\queries\OrganizationQuery; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @property string $guidAttribute GUID Attribute. |
20
|
|
|
* @property-read Member[] $ofMembers |
21
|
|
|
* @property-read Organization[] $atOrganizations |
22
|
|
|
* |
23
|
|
|
* @version 1.0 |
24
|
|
|
* @author vistart <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
trait UserOrganizationTrait |
27
|
|
|
{ |
28
|
|
|
public $organizationClass = Organization::class; |
29
|
|
|
public $memberClass = Member::class; |
30
|
|
|
private $noInitOrganization; |
31
|
|
|
private $noInitMember; |
32
|
|
|
/** |
33
|
|
|
* @return Organization |
34
|
|
|
*/ |
35
|
|
|
protected function getNoInitOrganization() |
36
|
|
|
{ |
37
|
|
|
if (!$this->noInitOrganization) { |
38
|
|
|
$class = $this->organizationClass; |
39
|
|
|
$this->noInitOrganization = $class::buildNoInitModel(); |
40
|
|
|
} |
41
|
|
|
return $this->noInitOrganization; |
42
|
|
|
} |
43
|
|
|
/** |
44
|
|
|
* @return Member |
45
|
|
|
*/ |
46
|
|
|
protected function getNoInitMember() |
47
|
|
|
{ |
48
|
|
|
if (!$this->noInitMember) { |
49
|
|
|
$class = $this->memberClass; |
50
|
|
|
$this->noInitMember = $class::buildNoInitModel(); |
51
|
|
|
} |
52
|
|
|
return $this->noInitMember; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* |
57
|
|
|
* @return MemberQuery |
58
|
|
|
*/ |
59
|
|
|
public function getOfMembers() |
60
|
|
|
{ |
61
|
|
|
return $this->hasMany($this->memberClass, [$this->guidAttribute => $this->getNoInitMember()->memberAttribute])->inverseOf('memberUser'); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* |
66
|
|
|
* @return OrganizationQuery |
67
|
|
|
*/ |
68
|
|
|
public function getAtOrganizations() |
69
|
|
|
{ |
70
|
|
|
return $this->hasMany($this->organizationClass, [$this->guidAttribute => $this->getNoInitOrganization()->guidAttribute])->via('ofMembers'); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.