1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/organization/license |
6
|
|
|
* @link https://www.flipboxfactory.com/software/organization/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\organization\web\twig\variables; |
10
|
|
|
|
11
|
|
|
use craft\elements\User; |
|
|
|
|
12
|
|
|
use flipbox\organization\elements\db\Organization as OrganizationQuery; |
13
|
|
|
use flipbox\organization\elements\Organization as OrganizationElement; |
14
|
|
|
use flipbox\organization\Organization as OrganizationPlugin; |
15
|
|
|
use yii\di\ServiceLocator; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Flipbox Factory <[email protected]> |
19
|
|
|
* @since 1.0.0 |
20
|
|
|
*/ |
21
|
|
|
class Organization extends ServiceLocator |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @inheritdoc |
26
|
|
|
*/ |
27
|
|
|
public function __construct($config = []) |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
parent::__construct(array_merge( |
31
|
|
|
$config, |
32
|
|
|
[ |
33
|
|
|
'components' => [ |
34
|
|
|
'organization' => __NAMESPACE__ . '\Organization', |
35
|
|
|
'settings' => __NAMESPACE__ . '\Settings', |
36
|
|
|
'type' => __NAMESPACE__ . '\Type', |
37
|
|
|
'user' => __NAMESPACE__ . '\User' |
38
|
|
|
] |
39
|
|
|
] |
40
|
|
|
)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Configure a query. |
45
|
|
|
* |
46
|
|
|
* @param mixed $criteria |
47
|
|
|
* @return OrganizationQuery |
48
|
|
|
*/ |
49
|
|
|
public function getQuery($criteria = null) |
50
|
|
|
{ |
51
|
|
|
return OrganizationPlugin::getInstance()->getOrganization()->getQuery($criteria); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Configure a query. |
56
|
|
|
* |
57
|
|
|
* @param mixed $criteria |
58
|
|
|
* @return OrganizationQuery |
59
|
|
|
*/ |
60
|
|
|
public function find($criteria = null) |
61
|
|
|
{ |
62
|
|
|
return $this->getQuery($criteria); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param array $config |
67
|
|
|
* @return \craft\base\Element|OrganizationElement |
68
|
|
|
*/ |
69
|
|
|
public function create(array $config = []) |
70
|
|
|
{ |
71
|
|
|
return OrganizationPlugin::getInstance()->getOrganization()->create($config); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Sub-Variables that are accessed 'craft.organization.settings' |
76
|
|
|
* |
77
|
|
|
* @return null|object|Settings |
78
|
|
|
*/ |
79
|
|
|
public function getSettings() |
80
|
|
|
{ |
81
|
|
|
return $this->get('settings'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Sub-Variables that are accessed 'craft.organization.type' |
86
|
|
|
* |
87
|
|
|
* @return null|object|Type |
88
|
|
|
*/ |
89
|
|
|
public function getType() |
90
|
|
|
{ |
91
|
|
|
return $this->get('type'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Sub-Variables that are accessed 'craft.organization.user' |
96
|
|
|
* |
97
|
|
|
* @return null|object|User |
98
|
|
|
*/ |
99
|
|
|
public function getUser() |
100
|
|
|
{ |
101
|
|
|
return $this->get('user'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: