LaravelRUS /
SleepingOwlAdmin
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SleepingOwl\Admin\Model; |
||
| 4 | |||
| 5 | use Illuminate\Database\Eloquent\Model; |
||
| 6 | use SleepingOwl\Admin\Contracts\Display\DisplayInterface; |
||
| 7 | use SleepingOwl\Admin\Contracts\Form\FormInterface; |
||
| 8 | use SleepingOwl\Admin\Contracts\Initializable; |
||
| 9 | use SleepingOwl\Admin\Display\DisplayDatatablesAsync; |
||
| 10 | |||
| 11 | class SectionModelConfiguration extends ModelConfigurationManager |
||
| 12 | { |
||
| 13 | protected $breadcrumbs = null; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var mixed |
||
| 17 | */ |
||
| 18 | protected $payload = []; |
||
| 19 | |||
| 20 | public function __construct(\Illuminate\Contracts\Foundation\Application $app, $class) |
||
| 21 | { |
||
| 22 | parent::__construct($app, $class); |
||
| 23 | |||
| 24 | $this->breadcrumbs = collect(); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @return \Illuminate\Support\Collection|null |
||
| 29 | */ |
||
| 30 | public function getBreadCrumbs() |
||
| 31 | { |
||
| 32 | return $this->breadcrumbs->toArray(); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param $breadcrumb |
||
| 37 | * @return mixed|void |
||
| 38 | */ |
||
| 39 | public function addBreadCrumb($breadcrumb) |
||
| 40 | { |
||
| 41 | $this->breadcrumbs->push($breadcrumb); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @return bool |
||
| 46 | */ |
||
| 47 | public function isCreatable() |
||
| 48 | { |
||
| 49 | return method_exists($this, 'onCreate') && parent::isCreatable($this->getModel()); |
||
|
0 ignored issues
–
show
|
|||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param \Illuminate\Database\Eloquent\Model $model |
||
| 54 | * |
||
| 55 | * @return bool |
||
| 56 | */ |
||
| 57 | public function isEditable(Model $model) |
||
| 58 | { |
||
| 59 | return method_exists($this, 'onEdit') && parent::isEditable($model); |
||
| 60 | } |
||
| 61 | |||
| 62 | public function isDeletable(Model $model) |
||
| 63 | { |
||
| 64 | return method_exists($this, 'onDelete') && parent::isDeletable($model); |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @param mixed $payload |
||
| 69 | * @return mixed|DisplayInterface|void |
||
| 70 | */ |
||
| 71 | public function fireDisplay($payload = []) |
||
| 72 | { |
||
| 73 | if (! method_exists($this, 'onDisplay')) { |
||
| 74 | return; |
||
| 75 | } |
||
| 76 | |||
| 77 | $this->setPayload($payload); |
||
| 78 | |||
| 79 | $display = $this->app->call([$this, 'onDisplay'], ['payload' => $payload]); |
||
| 80 | |||
| 81 | if ($display instanceof DisplayDatatablesAsync) { |
||
| 82 | $display->setPayload($payload); |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($display instanceof DisplayInterface) { |
||
| 86 | $display->setModelClass($this->getClass()); |
||
| 87 | $display->initialize(); |
||
| 88 | } |
||
| 89 | |||
| 90 | return $display; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param mixed $payload |
||
| 95 | * @return mixed|void |
||
| 96 | */ |
||
| 97 | public function fireCreate($payload = []) |
||
| 98 | { |
||
| 99 | if (! method_exists($this, 'onCreate')) { |
||
| 100 | return; |
||
| 101 | } |
||
| 102 | |||
| 103 | $this->setPayload($payload); |
||
| 104 | |||
| 105 | $form = $this->app->call([$this, 'onCreate'], ['payload' => $payload]); |
||
| 106 | |||
| 107 | if ($form instanceof DisplayInterface) { |
||
| 108 | $form->setModelClass($this->getClass()); |
||
| 109 | } |
||
| 110 | |||
| 111 | if ($form instanceof Initializable) { |
||
| 112 | $form->initialize(); |
||
| 113 | } |
||
| 114 | |||
| 115 | if ($form instanceof FormInterface) { |
||
| 116 | $form->setAction($this->getStoreUrl()); |
||
| 117 | } |
||
| 118 | |||
| 119 | return $form; |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @param int $id |
||
| 124 | * @param mixed $payload |
||
| 125 | * |
||
| 126 | * @return mixed|void |
||
| 127 | */ |
||
| 128 | public function fireEdit($id, $payload = []) |
||
| 129 | { |
||
| 130 | if (! method_exists($this, 'onEdit')) { |
||
| 131 | return; |
||
| 132 | } |
||
| 133 | |||
| 134 | $model = $this; |
||
| 135 | if (method_exists($model, 'getModelValue')) { |
||
| 136 | $item = $model->getModelValue(); |
||
| 137 | if (! $item) { |
||
| 138 | $item = $model->getRepository()->find($id); |
||
| 139 | if (method_exists($model, 'setModelValue') && $item) { |
||
| 140 | $model->setModelValue($item); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | $this->setPayload($payload); |
||
| 146 | |||
| 147 | $payload = array_merge(['id' => $id], ['payload' => $payload]); |
||
| 148 | |||
| 149 | $form = $this->app->call([$this, 'onEdit'], $payload); |
||
| 150 | |||
| 151 | if ($form instanceof DisplayInterface) { |
||
| 152 | $form->setModelClass($this->getClass()); |
||
| 153 | } |
||
| 154 | |||
| 155 | if ($form instanceof Initializable) { |
||
| 156 | $form->initialize(); |
||
| 157 | } |
||
| 158 | |||
| 159 | if ($form instanceof FormInterface) { |
||
| 160 | $form->setAction($this->getUpdateUrl($id)); |
||
| 161 | $form->setId($id); |
||
| 162 | } |
||
| 163 | |||
| 164 | return $form; |
||
| 165 | } |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @param $id |
||
| 169 | * |
||
| 170 | * @return mixed |
||
| 171 | */ |
||
| 172 | public function fireDelete($id) |
||
| 173 | { |
||
| 174 | if (method_exists($this, 'onDelete')) { |
||
| 175 | return $this->app->call([$this, 'onDelete'], ['id' => $id]); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @param $id |
||
| 181 | * |
||
| 182 | * @return mixed |
||
| 183 | */ |
||
| 184 | public function fireDestroy($id) |
||
| 185 | { |
||
| 186 | if (method_exists($this, 'onDestroy')) { |
||
| 187 | return $this->app->call([$this, 'onDestroy'], ['id' => $id]); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param $id |
||
| 193 | * |
||
| 194 | * @return bool|mixed |
||
| 195 | */ |
||
| 196 | public function fireRestore($id) |
||
| 197 | { |
||
| 198 | if (method_exists($this, 'onRestore')) { |
||
| 199 | return $this->app->call([$this, 'onRestore'], ['id' => $id]); |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @return mixed |
||
| 205 | */ |
||
| 206 | public function getPayload() |
||
| 207 | { |
||
| 208 | return $this->payload; |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @param mixed $payload |
||
| 213 | * |
||
| 214 | * @return $this |
||
| 215 | */ |
||
| 216 | public function setPayload($payload = []) |
||
| 217 | { |
||
| 218 | $this->payload = $payload; |
||
| 219 | |||
| 220 | return $this; |
||
| 221 | } |
||
| 222 | } |
||
| 223 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.