class ProfileController extends Controller

Supports ability to use user profile features and render relevant views.

Traits

A trait that support operations related to APIs and their associated JSON responses.

Properties

protected string $_action

The name of the current action.

from  Controller
protected string $_controller

The name of the current controller.

from  Controller
Input $request

Instance of Input class that performs much of our request tasks.

from  Controller
View $view

Instance of view class.

from  Controller
static string|null $rawInputOverride

Raw JSON override for tests

from  JsonResponse
static bool $testing

When true, do not send headers or exit; just echo JSON and return.

from  JsonResponse
static int $lastStatus

Captured status for tests (optional convenience).

from  JsonResponse
static array $lastHeaders

Captured headers for tests (optional convenience).

from  JsonResponse

Methods

__construct(string $controller, string $action)

Constructor for the parent Controller class. This constructor gets called when an instance of the child class is instantiated.

static void
appStart()

Initializes ErrorHandler and SessionManager and starts execution of the app.

void
_set_reporting()

Manages the displaying of error messages and other reporting for this application.

void
logViewForTesting(View $view)

Captures the current View instance during testing so that test assertions (e.g., assertViewContains) can access view-bound variables.

void
onConstruct()

Internal version of this controller uses internal layout.

bool
apiCsrfCheck()

Checks if CSRF token has been tampered with.

array|string
get(string|null $input = null)

Supports operations related to handling POST and GET requests.

void
jsonError(string $message, int $status = 400, array $errors = [])

Makes JSON Response for error payloads.

void
jsonRedirect(string $url)

Returns json response success = true and sets path for redirect.

void
jsonResponse(mixed $data, int $status = 200, array $extraHeaders = [])

Sends a JSON response with headers and status code.

void
preflight()

Respond to CORS preflight.

static void
setRawInputOverride(mixed $payload = null)

Inject JSON body by providing payload parameter. Also performs cleanup to avoid leaking into other tests.

void
deleteImageAction()

Deletes an image associated with a user's profile.

void
editAction()

Renders edit profile page and handles database updates.

void
indexAction()

Renders profile view for current logged in user.

void
updatePasswordAction()

Renders change password page for current logged in user.

Details

in Controller at line 47
__construct(string $controller, string $action)

Constructor for the parent Controller class. This constructor gets called when an instance of the child class is instantiated.

Parameters

string $controller

The name of the controller obtained while parsing the URL.

string $action

The name of the action specified in the path of the URL.

in Application at line 26
static void appStart()

Initializes ErrorHandler and SessionManager and starts execution of the app.

Return Value

void

in Application at line 51
private void _set_reporting()

Manages the displaying of error messages and other reporting for this application.

Return Value

void

in Controller at line 67
protected void logViewForTesting(View $view)

Captures the current View instance during testing so that test assertions (e.g., assertViewContains) can access view-bound variables.

This method should be called in controller actions before rendering a view. It stores the View object in ApplicationTestCase::$controllerOutput['view'] when the application is running in the 'testing' environment.

Parameters

View $view

The View instance to capture.

Return Value

void

at line 78
void onConstruct()

Internal version of this controller uses internal layout.

Return Value

void

in JsonResponse at line 47
bool apiCsrfCheck()

Checks if CSRF token has been tampered with.

Return Value

bool

True if token is valid, otherwise we return false.

in JsonResponse at line 62
array|string get(string|null $input = null)

Supports operations related to handling POST and GET requests.

Similar in behavior to the get function from the Input class but for JSON related operations.

Parameters

string|null $input

Field name from POST/GET request, or null to get all.

Return Value

array|string

Sanitized input as array or string.

in JsonResponse at line 97
void jsonError(string $message, int $status = 400, array $errors = [])

Makes JSON Response for error payloads.

Parameters

string $message

The error message.

int $status

The status code.

array $errors

The array of errors.

Return Value

void

in JsonResponse at line 110
void jsonRedirect(string $url)

Returns json response success = true and sets path for redirect.

Parameters

string $url

The url for redirection.

Return Value

void

in JsonResponse at line 125
void jsonResponse(mixed $data, int $status = 200, array $extraHeaders = [])

Sends a JSON response with headers and status code.

Parameters

mixed $data

The JSON response.

int $status

The status code.

array $extraHeaders

Any extra headers.

Return Value

void

in JsonResponse at line 174
void preflight()

Respond to CORS preflight.

Return Value

void

in JsonResponse at line 190
static void setRawInputOverride(mixed $payload = null)

Inject JSON body by providing payload parameter. Also performs cleanup to avoid leaking into other tests.

Parameters

mixed $payload

The JSON payload or null.

Return Value

void

at line 23
void deleteImageAction()

Deletes an image associated with a user's profile.

Return Value

void

at line 36
void editAction()

Renders edit profile page and handles database updates.

Return Value

void

at line 63
void indexAction()

Renders profile view for current logged in user.

Return Value

void

at line 87
void updatePasswordAction()

Renders change password page for current logged in user.

Return Value

void