config($config); } /** * Get a table from the alias, table object or inspecting the request for a default table * * @param Request $request request * @param mixed $table table * @return \Cake\ORM\Table * @throws \OutOfBoundsException if table alias is empty */ protected function _getTable(Request $request, $table = null) { if (empty($table)) { return $this->_getTableFromRequest($request); } if ($table instanceof Table) { return $table; } return TableRegistry::get($table); } /** * Inspect the request and try to retrieve a table based on the current controller * * @param Request $request request * @return Table * @throws \OutOfBoundsException if table alias can't be extracted from request */ protected function _getTableFromRequest(Request $request) { $plugin = Hash::get($request->params, 'plugin'); $controller = Hash::get($request->params, 'controller'); $modelClass = ($plugin ? $plugin . '.' : '') . $controller; $this->modelFactory('Table', [$this->tableLocator(), 'get']); if (empty($modelClass)) { throw new OutOfBoundsException(__d('CakeDC/Users', 'Table alias is empty, please define a table alias, we could not extract a default table from the request')); } return $this->loadModel($modelClass); } /** * Check the current entity is owned by the logged in user * * @param array $user Auth array with the logged in data * @param string $role role of the user * @param Request $request current request, used to get a default table if not provided * @return bool * @throws \OutOfBoundsException if table is not found or it doesn't have the expected fields */ abstract public function allowed(array $user, $role, Request $request); }