1 | <?php |
||
12 | class AuthorizedController extends AuthenticatedController |
||
13 | { |
||
14 | use AuthorizesRequests; |
||
15 | |||
16 | /** |
||
17 | * The resource Ability Map. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $resourceAbilityMap = [ |
||
22 | 'activities' => 'audit', |
||
23 | 'index' => 'list', |
||
24 | 'logs' => 'audit', |
||
25 | ]; |
||
26 | |||
27 | /** |
||
28 | * The resource methods without models. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $resourceMethodsWithoutModels = []; |
||
33 | |||
34 | /** |
||
35 | * Resource action whitelist. |
||
36 | * Array of resource actions to skip mapping to abilities automatically. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $resourceActionWhitelist = []; |
||
41 | |||
42 | /** |
||
43 | * Create a new authorized controller instance. |
||
44 | * |
||
45 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
46 | */ |
||
47 | public function __construct() |
||
48 | { |
||
49 | parent::__construct(); |
||
50 | |||
51 | if (property_exists(static::class, 'resource')) { |
||
52 | $this->isClassName($this->resource) ? $this->authorizeResource($this->resource) : $this->authorizeGeneric($this->resource); |
||
53 | } else { |
||
54 | // At this stage, sessions still not loaded yet, and `AuthorizationException` |
||
55 | // depends on seesions to flash redirection error msg, so delegate to a middleware |
||
56 | // Since Laravel 5.3 controller constructors executed before middleware to be able to append |
||
57 | // new middleware to the pipeline then all middleware executed together, and sessions started in `StartSession` middleware |
||
58 | $this->middleware('can:null'); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | public function authorizeResource($model, $parameter = null, array $options = [], $request = null): void |
||
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | public function authorizeGeneric($resource): void |
||
96 | |||
97 | /** |
||
98 | * Map resource actions to resource abilities. |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | protected function mapResourceAbilities(): array |
||
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | protected function resourceAbilityMap(): array |
||
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | protected function resourceMethodsWithoutModels() |
||
140 | |||
141 | /** |
||
142 | * Checks if the given string looks like a fully qualified class name. |
||
143 | * |
||
144 | * @param string $value |
||
145 | * @return bool |
||
146 | */ |
||
147 | protected function isClassName($value) |
||
151 | } |
||
152 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.