1 | <?php |
||
2 | |||
3 | namespace Shamaseen\Repository\Utility; |
||
4 | |||
5 | use Illuminate\Contracts\Pagination\Paginator; |
||
6 | use Illuminate\Database\Eloquent\Collection; |
||
7 | use Illuminate\Database\Eloquent\Model; |
||
0 ignored issues
–
show
|
|||
8 | use Illuminate\Http\RedirectResponse; |
||
9 | use Illuminate\Support\Facades\Config; |
||
10 | use Illuminate\Support\Facades\Redirect; |
||
11 | use Illuminate\Support\Facades\View; |
||
12 | use Shamaseen\Repository\Interfaces\CrudResponse; |
||
13 | |||
14 | class WebResponses implements CrudResponse |
||
15 | { |
||
16 | private Controller $controller; |
||
17 | |||
18 | public function __construct(Controller $controller) |
||
19 | { |
||
20 | $this->controller = $controller; |
||
21 | View::share('breadcrumbs', $controller->breadcrumbs); |
||
22 | } |
||
23 | |||
24 | public function index(Paginator|Collection $paginate): \Illuminate\Contracts\View\View |
||
25 | { |
||
26 | View::share('pageTitle', __('repository.list').' '.$this->controller->pageTitle.' | '.Config::get('app.name')); |
||
27 | |||
28 | return view($this->controller->viewIndex, $this->controller->params) |
||
29 | ->with('entities', $paginate) |
||
30 | ->with('createRoute', $this->controller->createRoute) |
||
31 | ->with('filters', $this->controller->request->all()); |
||
32 | } |
||
33 | |||
34 | public function show(Model $entity): \Illuminate\Contracts\View\View |
||
35 | { |
||
36 | View::share('pageTitle', 'View '.$this->controller->pageTitle.' | '.Config::get('app.name')); |
||
37 | |||
38 | return view($this->controller->viewShow, $this->controller->params) |
||
39 | ->with('entity', $entity); |
||
40 | } |
||
41 | |||
42 | public function create(): \Illuminate\Contracts\View\View |
||
43 | { |
||
44 | View::share('pageTitle', 'Create '.$this->controller->pageTitle.' | '.Config::get('app.name')); |
||
45 | |||
46 | return view($this->controller->viewCreate, $this->controller->params); |
||
47 | } |
||
48 | |||
49 | public function store(Model $entity): RedirectResponse |
||
50 | { |
||
51 | return Redirect::to($this->controller->resolveRoute($this->controller->routeIndex)) |
||
52 | ->with('message', __('repository.created_successfully')); |
||
53 | } |
||
54 | |||
55 | public function edit(Model $entity): \Illuminate\Contracts\View\View |
||
56 | { |
||
57 | return view($this->controller->viewEdit, $this->controller->params) |
||
58 | ->with('entity', $entity); |
||
59 | } |
||
60 | |||
61 | public function update(int|bool|Model $updatedCount): RedirectResponse |
||
62 | { |
||
63 | return Redirect::to($this->controller->resolveRoute($this->controller->routeIndex)) |
||
64 | ->with('message', __('repository.modified_successfully')) |
||
65 | ->with('updatedCount', $updatedCount); |
||
66 | } |
||
67 | |||
68 | public function destroy(int|bool $destroyedCount): RedirectResponse |
||
69 | { |
||
70 | return Redirect::to($this->controller->resolveRoute($this->controller->routeIndex)) |
||
71 | ->with('message', __('repository.deleted_successfully')) |
||
72 | ->with('destroyedCount', $destroyedCount); |
||
73 | } |
||
74 | } |
||
75 |
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: