{@inheritdoc}

@api

@throws Exception\MethodNotImplemented if any enabled state implement the required method
@throws \Throwable

@see http://php.net/manual/en/class.arrayaccess.php
345699
public function offsetSet($offset, $value)
    {
        $args = [$offset, $value];
        $methodName = __FUNCTION__;

        return $this->findAndCall($methodName, $args);
    }
1258088
protected function method($method)
    {
        if (strtolower($this->request->getMethod()) != strtolower($method)) {
            throw new MethodNotAllowedException('No matching method for HTTP method "'.$this->request->getMethod().'"');
        }
        return true;
    }
15091
public function update()
    {
        if (!$this->request->is('post')) {
            if ($this->request->is('ajax')) {
                throw new MethodNotAllowedException();
            } else {
                $this->Flash->error($this->invalidRequestMessage);
                $this->redirect(['action' => 'index']);
                return;
            }
        }

        if (empty($this->request->data) && !$this->request->is('ajax')) {
            $this->Flash->warning(__d('wasabi_core', 'There are no permissions to update yet.'));
            $this->redirect(['action' => 'index']);
            return;
        }

        // save the new language positions
        $permissions = $this->GroupPermissions->patchEntities(
            $this->GroupPermissions->find('all'),
            $this->request->data
        );

        /** @var Connection $connection */
        $connection = $this->GroupPermissions->connection();
        $connection->begin();
        foreach ($permissions as $permission) {
            if (!$this->GroupPermissions->save($permission)) {
                $connection->rollback();
                break;
            }
        }

        if ($connection->inTransaction()) {
            $connection->commit();
            Cache::clear(false, 'wasabi/core/group_permissions');
            if ($this->request->is('ajax')) {
                $status = 'success';
                $this->set(compact('status'));
                $this->set('_serialize', ['status']);
            } else {
                $this->Flash->success(__d('wasabi_core', 'All permissions have been saved.'));
                $this->redirect(['action' => 'index']);
                return;
            }
        } else {
            $this->Flash->error($this->dbErrorMessage);
        }
    }
64920
private function checkMethod() {
        if (strpos(self::$currentRoute['method'], '|') !== false) {
            if (!in_array($_SERVER['REQUEST_METHOD'], explode('|', self::$currentRoute['method']))) {
                throw new RouteException(_message(ExceptionMessages::INCORRECT_METHOD, $_SERVER['REQUEST_METHOD']));
            }
        } else if ($_SERVER['REQUEST_METHOD'] != self::$currentRoute['method']) {
            throw new RouteException(_message(ExceptionMessages::INCORRECT_METHOD, $_SERVER['REQUEST_METHOD']));
        }
    }
181055
public function wrong_method( $possible_methods = array() ) {
		// Any defined possible methods?
		if ( is_array($possible_methods) && count($possible_methods) > 0 ) {
			// Uppercase whatever was passed, for good measure
			$possible_methods = array_map( 'strtoupper', $possible_methods );

			// Add them to our response
			$this->response->possible_methods = $possible_methods;
		}
		elseif ( is_string($possible_methods) && !empty($possible_methods) ) {
			// Uppercase whatever was passed, for good measure
			$possible_methods = strtoupper($possible_methods);

			// Add it to our response as an array so that it stays consistent
			$this->response->possible_methods = array( $possible_methods );
		}

		// Also add the possible methods to our "more_info" for readability
		$more_info = array(
			'possible_methods' => $this->response->possible_methods
		);

		// We didn't match their request, create and throw an exception
		$wrong_method_exception = new WrongMethod();
		$wrong_method_exception->set_more_info( $more_info );
		throw $wrong_method_exception;
	}
322995
private function checkRequired()
    {
        // Loop through all params
        foreach ($this->params as $param) {
            if (array_key_exists('required', $param) && $param['required'] == true) {
                if (!array_key_exists($param['name'], $this->pinputs)) {
                    throw new \Exception('Parameter "' . $param['name'] . '" is required');
                }
            }
        }

        // Loop through all options
        foreach ($this->options as $key => $option) {
            // if option is required
            if (array_key_exists('required', $option) && $option['required'] == true) {
                // check that it is defined in pinputs
                if ($this->pinputs[$option['short']] == false) {
                    throw new \Exception('Option "' . $option['help'] . '" is required');
                }
            }
        }

    }
556661
public function exception(\Throwable $throwable)
    {
        try {
            if (@Application::getSettings()->logging->exceptions) {
                $this->error('[EXCEPTION] ' . $throwable . PHP_EOL . $throwable->getTraceAsString());
            }
        } catch (SettingsException $throwable) {
            // No setting present, throwable will not be logged.
        }
    }
383407
public function addAllowedMethods(array $methods): MethodNotAllowed
    {
        $this->allowedMethods = array_merge($this->allowedMethods, $methods);

        return $this;
    }
97095
public function throwsExactly()
    {
        try {
            $this->data[0]();
        } catch (Exception $exception) {
            $exceptionClass = get_class($exception);
            if ($exceptionClass === $this->data[1]) {
                return;
            } else {
                throw new DidNotMatchException(
                    "Expected exactly {$this->data[1]} to be thrown, " .
                    "but $exceptionClass was thrown."
                );
            }
        }
        throw new DidNotMatchException(
            "Expected exactly {$this->data[1]} to be thrown, " .
            "but nothing was thrown."
        );
    }
490304
public function execute()
    {
        $ch = curl_init();
        $this->setAuth($ch);
        try {
            switch (strtoupper($this->verb)) {
                case 'GET':
                    $this->executeGet($ch);
                    break;
                case 'POST':
                    $this->executePost($ch);
                    break;
                case 'PUT':
                    $this->executePut($ch);
                    break;
                case 'DELETE':
                    $this->executeDelete($ch);
                    break;
                default:
                    throw new \InvalidArgumentException(
                        'Current verb (' . $this->verb
                        . ') is an invalid REST verb.'
                    );
            }
        } catch (\InvalidArgumentException $e) {
            curl_close($ch);
            throw $e;
        } catch (\Exception $e) {
            curl_close($ch);
            throw $e;
        }

        /*
         * check and debug api request total time
         */
        $this->processDebugApi();

        return $this->responseBody;
    }
530709
public function execute(object $object, array $properties, array $methodPrefixes = ['set', 'add']): object
    {
        try {
            foreach ($properties as $property => $value) {
                if (false === $this->assignValueWithSetterMethod($object, [$property, $value], $methodPrefixes)) {
                    $object->$property = $value;
                }
            }

            return $object;
        } catch (\Throwable $t) {
            throw new PropertyNotAccessibleException($t->getMessage());
        }
    }
223574
public function execAction()
    {
        //no action defined
        if(!$this->action) {
            throw new \Exception(sprintf('no action defined for subject %s', $this->name));
        }
        //exec method
        try {
            $this->checkTraitsInjections();
            $this->traitsInit();
            $this->{'exec'.$this->sanitizeAction($this->action)}();
        } catch(Exception $exception) {
        //no method defined
            throw new Exception(sprintf('no method for handling %s %s %s', AREA, $this->name, $this->action));
        }
    }
1158021
protected function validate()
    {
        if ($this->method === HttpMethods::POST && empty($this->data)) {
            throw new Exceptions\WebException(
                "Using method POST without data."
            );
        }
    }
602342
public function init() {
        if (VERBOSE) echo 'INIT:' ,PHP_EOL;
        if (VERBOSE) echo ' CONNECTING API' ,PHP_EOL;
        $this->api->auth();
        if (VERBOSE) echo ' API CONNECTED' ,PHP_EOL;
        if (VERBOSE) echo ' CONNECTING SQL' ,PHP_EOL;
        $this->db->connect();
        if (VERBOSE) echo ' SQL CONNECTED' ,PHP_EOL;
        if (VERBOSE) echo ' CHECKING PATHS' ,PHP_EOL;
        if (DEBUG) echo '  CHECKING TMP DIR AT : '.$this->tmp_dir ,PHP_EOL;
        if (!file_exists($this->tmp_dir)) {
            throw new Exception("Path for 'tmp_dir' not found at '".$this->tmp_dir."'!");
        }
        if (DEBUG) echo '  CHECKING DUMP DIR AT : '.$this->dumps_dir ,PHP_EOL;
        if (!file_exists($this->dumps_dir)) {
            throw new Exception("Path for 'dumps_dir' not found at '".$this->dumps_dir."'!");
        }
        if (VERBOSE) echo ' PATHS FOUND' ,PHP_EOL;
    }
1022850
public function setMethod($method)
    {
        $valid = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT'];
        $method = strtoupper($method);

        if (!in_array($method, $valid)) {
            throw new \Exception('Error: That request method is not valid.');
        }
        $this->method = $method;

        return $this;
    }
215418
protected function _loadRequestMethod()
    {
        if($this->_requestMethod !== NULL) return;

        if(!key_exists('REQUEST_METHOD', $_SERVER)) {
            throw new Exception("Request method unknown");
        }

        $method = strtoupper($_SERVER['REQUEST_METHOD']);

        if (in_array($method, array('GET', 'POST', 'PUT', 'DELETE', 'PATCH'))) {
            $this->_requestMethod = $method;
        } else {
            throw new Exception("Request method ($method) invalid");
        }
    }
53444
public function call($method, array $data = null)
    {
        $options = $this->proxySettings + [
            CURLOPT_URL => $this->getUrl().'/'.$method,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => null,
            CURLOPT_POSTFIELDS => null,
            CURLOPT_TIMEOUT => 5,
        ];

        if ($data) {
            $options[CURLOPT_POST] = true;
            $options[CURLOPT_POSTFIELDS] = $data;
        }

        if (!empty($this->customCurlOptions) && is_array($this->customCurlOptions)) {
            $options += $this->customCurlOptions;
        }

        $response = self::jsonValidate($this->executeCurl($options), $this->returnArray);

        if ($this->returnArray) {
            if (!isset($response['ok'])) {
                throw new Exception($response['description'], $response['error_code']);
            }

            return $response['result'];
        }

        if (!$response->ok) {
            throw new Exception($response->description, $response->error_code);
        }

        return $response->result;
    }