1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Admin\Grid\Factory; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Admin\Constant\Route; |
8
|
|
|
use AbterPhp\Admin\Grid\Factory\Table\Header\User as HeaderFactory; |
9
|
|
|
use AbterPhp\Admin\Grid\Factory\Table\User as TableFactory; |
|
|
|
|
10
|
|
|
use AbterPhp\Admin\Grid\Filters\User as Filters; |
11
|
|
|
use AbterPhp\Framework\Constant\Html5; |
12
|
|
|
use AbterPhp\Framework\Grid\Action\Action; |
13
|
|
|
use AbterPhp\Framework\Grid\Component\Actions; |
14
|
|
|
use Opulence\Routing\Urls\UrlGenerator; |
15
|
|
|
|
16
|
|
|
class User extends BaseFactory |
17
|
|
|
{ |
18
|
|
|
private const GETTER_USERNAME = 'getUsername'; |
19
|
|
|
private const GETTER_EMAIL = 'getEmail'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* User constructor. |
23
|
|
|
* |
24
|
|
|
* @param UrlGenerator $urlGenerator |
25
|
|
|
* @param PaginationFactory $paginationFactory |
26
|
|
|
* @param TableFactory $tableFactory |
27
|
|
|
* @param GridFactory $gridFactory |
28
|
|
|
* @param Filters $filters |
29
|
|
|
*/ |
30
|
|
|
public function __construct( |
31
|
|
|
UrlGenerator $urlGenerator, |
32
|
|
|
PaginationFactory $paginationFactory, |
33
|
|
|
TableFactory $tableFactory, |
34
|
|
|
GridFactory $gridFactory, |
35
|
|
|
Filters $filters |
36
|
|
|
) { |
37
|
|
|
parent::__construct($urlGenerator, $paginationFactory, $tableFactory, $gridFactory, $filters); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function getGetters(): array |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
HeaderFactory::GROUP_USERNAME => static::GETTER_USERNAME, |
47
|
|
|
HeaderFactory::GROUP_EMAIL => static::GETTER_EMAIL, |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return Actions |
53
|
|
|
*/ |
54
|
|
|
protected function getRowActions(): Actions |
55
|
|
|
{ |
56
|
|
|
$attributeCallbacks = $this->getAttributeCallbacks(); |
57
|
|
|
|
58
|
|
|
$editAttributes = [ |
59
|
|
|
Html5::ATTR_HREF => [Route::USERS_EDIT], |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
$deleteAttributes = [ |
63
|
|
|
Html5::ATTR_HREF => [Route::USERS_DELETE], |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
$cellActions = new Actions(); |
67
|
|
|
$cellActions[] = new Action( |
68
|
|
|
static::LABEL_EDIT, |
69
|
|
|
$this->editIntents, |
70
|
|
|
$editAttributes, |
71
|
|
|
$attributeCallbacks, |
72
|
|
|
Html5::TAG_A |
73
|
|
|
); |
74
|
|
|
$cellActions[] = new Action( |
75
|
|
|
static::LABEL_DELETE, |
76
|
|
|
$this->deleteIntents, |
77
|
|
|
$deleteAttributes, |
78
|
|
|
$attributeCallbacks, |
79
|
|
|
Html5::TAG_A |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
return $cellActions; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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: