'staff_3', 'requestData' => [ 'name' => [ 'validation' => DataValidator::notBlank()->length(2, 55)->alnum(), 'error' => ERRORS::INVALID_NAME ], 'type' => [ 'validation' => DataValidator::in(APIKey::TYPES), 'error' => ERRORS::INVALID_API_KEY_TYPE ] ] ]; } public function handler() { $apiInstance = new APIKey(); $name = Controller::request('name'); $type = Controller::request('type'); $keyInstance = APIKey::getDataStore($name, 'name'); if($keyInstance->isNull()){ $token = Hashing::generateRandomToken(); $apiInstance->setProperties([ 'name' => $name, 'token' => $token, 'type' => $type, ]); $apiInstance->store(); Response::respondSuccess($token); } else { throw new RequestException(ERRORS::NAME_ALREADY_USED); } } }