1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Files\Http\Controllers\Admin\Form; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Admin\Http\Controllers\Admin\FormAbstract; |
8
|
|
|
use AbterPhp\Framework\Assets\AssetManager; |
9
|
|
|
use AbterPhp\Files\Domain\Entities\File as Entity; |
10
|
|
|
use AbterPhp\Files\Domain\Entities\FileCategory; |
|
|
|
|
11
|
|
|
use AbterPhp\Files\Form\Factory\File as FormFactory; |
12
|
|
|
use AbterPhp\Files\Orm\FileRepo as Repo; |
13
|
|
|
use AbterPhp\Framework\Domain\Entities\IStringerEntity; |
14
|
|
|
use AbterPhp\Framework\I18n\ITranslator; |
15
|
|
|
use AbterPhp\Framework\Session\FlashService; |
16
|
|
|
use Opulence\Events\Dispatchers\IEventDispatcher; |
17
|
|
|
use Opulence\Routing\Urls\UrlGenerator; |
18
|
|
|
use Opulence\Sessions\ISession; |
19
|
|
|
use Psr\Log\LoggerInterface; |
20
|
|
|
|
21
|
|
|
class File extends FormAbstract |
22
|
|
|
{ |
23
|
|
|
const ENTITY_PLURAL = 'files'; |
24
|
|
|
const ENTITY_SINGULAR = 'file'; |
25
|
|
|
|
26
|
|
|
const ENTITY_TITLE_SINGULAR = 'files:file'; |
27
|
|
|
const ENTITY_TITLE_PLURAL = 'files:files'; |
28
|
|
|
|
29
|
|
|
const ROUTING_PATH = 'files'; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
protected $resource = 'files'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* File constructor. |
36
|
|
|
* |
37
|
|
|
* @param FlashService $flashService |
38
|
|
|
* @param ITranslator $translator |
39
|
|
|
* @param UrlGenerator $urlGenerator |
40
|
|
|
* @param LoggerInterface $logger |
41
|
|
|
* @param Repo $repo |
42
|
|
|
* @param ISession $session |
43
|
|
|
* @param FormFactory $formFactory |
44
|
|
|
* @param IEventDispatcher $eventDispatcher |
45
|
|
|
* @param AssetManager $assetManager |
46
|
|
|
*/ |
47
|
|
|
public function __construct( |
48
|
|
|
FlashService $flashService, |
49
|
|
|
ITranslator $translator, |
50
|
|
|
UrlGenerator $urlGenerator, |
51
|
|
|
LoggerInterface $logger, |
52
|
|
|
Repo $repo, |
53
|
|
|
ISession $session, |
54
|
|
|
FormFactory $formFactory, |
55
|
|
|
IEventDispatcher $eventDispatcher, |
56
|
|
|
AssetManager $assetManager |
57
|
|
|
) { |
58
|
|
|
parent::__construct( |
59
|
|
|
$flashService, |
60
|
|
|
$translator, |
61
|
|
|
$urlGenerator, |
62
|
|
|
$logger, |
63
|
|
|
$repo, |
64
|
|
|
$session, |
65
|
|
|
$formFactory, |
66
|
|
|
$eventDispatcher |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$this->assetManager = $assetManager; |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string $entityId |
74
|
|
|
* |
75
|
|
|
* @return Entity |
76
|
|
|
*/ |
77
|
|
|
protected function createEntity(string $entityId): IStringerEntity |
78
|
|
|
{ |
79
|
|
|
$fileCategory = new FileCategory('', '', '', false, []); |
80
|
|
|
|
81
|
|
|
return new Entity($entityId, '', '', '', '', $fileCategory, null); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param IStringerEntity|null $entity |
86
|
|
|
* |
87
|
|
|
* @throws \League\Flysystem\FileNotFoundException |
88
|
|
|
*/ |
89
|
|
|
protected function addCustomAssets(?IStringerEntity $entity = null) |
90
|
|
|
{ |
91
|
|
|
parent::addCustomAssets($entity); |
92
|
|
|
|
93
|
|
|
if (!($entity instanceof Entity)) { |
94
|
|
|
return; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$footer = $this->getResourceName(static::RESOURCE_FOOTER); |
98
|
|
|
$this->assetManager->addJs($footer, '/admin-assets/js/semi-auto.js'); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
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: