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