The Request Object
The Request object plays a crucial role in Floky applications, providing access to information about the incoming HTTP request. You can inject the Request object into controller methods to retrieve user input, headers, and other request data.  
Request Injection
Floky controllers can receive the Request object as an argument in their methods. This allows you to access various request details within your controller logic.
Here's an example:
| PHP | |
|---|---|
Request Methods
The Request object provides several methods to access different aspects of the HTTP request:
- input(string $key, $default = null): Retrieves a specific value from the request body (either GET or POST data). If the key doesn't exist, it returns the default value.
- get(string $key = null, $default = null): Retrieves a value from the GET request data. If no key is provided, it returns the entire GET data array.
- post(string $key = null, $default = null): Retrieves a value from the POST request data. If no key is provided, it returns the entire POST data array.
- only(array $keys): Returns a subset of the request data containing only the specified keys.
- all(): Returns an array containing all request data merged from GET, POST, and other sources.
- validator(array $rules, array $messages = []): Creates a validator instance using the BlakvGhost PHPValidator library to validate request data against defined rules. You can specify custom error messages as well.
- validate(array $rules, array $messages = []): Validates request data against defined rules and throws an exception if validation fails. Alternatively, consider using the- backmethod for redirecting with errors.
- back(mixed $data = []): Redirects the user back to the previous page (using the- Refererheader) and stores the provided data in the session for displaying errors or other information.
- getUri(): Returns the current request URI.
- getReferer(): Returns the URL from which the user originated the request (based on the- Refererheader).
- getUrl(): Alias for- getUri().
- getMethod(): Returns the HTTP method used for the request (GET, POST, PUT, etc.).
- isMethod(string $method): Checks if the current request method matches the provided method.
- isGet(),- isPost(),- isPut(), etc.: Convenient methods to check if the current request uses the specific HTTP method.
- header(): Returns a- Headerobject that provides access to request headers.
Accessing Request Headers in Floky
The Header class within Floky's Request component provides functionalities to access and manipulate HTTP headers sent by the client in the request : 
- get(string $headerName): Retrieves the value of a specific header by name. The header name is converted to uppercase and underscores are replaced with hyphens for compatibility with the server variable format (e.g.,- Content-Typebecomes- HTTP_CONTENT_TYPE). This method returns the sanitized value of the header or- nullif it doesn't exist.
- getAll(): Returns an associative array containing all request headers. The header names are converted to a more readable format (e.g.,- Content-Typebecomes- contentType). The values are also sanitized before being returned.
Common Header Checks:
- acceptJson(): Checks if the request accepts JSON content type (- application/json) by examining the- Acceptheader.
- isAjax(): Determines if the request is an AJAX request by checking the presence and value of the- X-Requested-Withheader (- XMLHttpRequest).
Setting Headers:
- set(string $headerName, string $headerValue): Sets a new HTTP header in the response. This method allows you to define custom headers to be sent back to the client.
Additional Information:
- isSecure(): Checks if the current request is using a secure HTTPS connection.
- getUserAgent(): Returns the user agent string sent by the client's browser.
- getReferer(): Retrieves the referring URL from the- Refererheader if present.
- getClientIp(): Returns the client's IP address based on the- REMOTE_ADDRserver variable.
- getBearer(): Extracts the bearer token from the- Authorizationheader if the request uses Bearer token authentication. It checks for a prefix of- "Bearer "and returns the remaining string as the token.
Additional Features
File Uploads
The Files trait within Floky's Request component provides functionalities to handle file uploads submitted through forms. It's important to note that this trait is used within the Request object, not as a standalone class.
Checking for Uploaded Files:
- hasFile(string $inputName): This method checks if a specific file input named- $inputNameexists in the uploaded files array (- $_FILES). It returns- trueif the file was uploaded and- falseotherwise.
Accessing Uploaded File Details:
- getFile(string $inputName): If a file with the given- $inputNamewas uploaded, this method retrieves the corresponding information from the- $_FILESarray. It returns an associative array containing details about the uploaded file, such as:- name: The original filename of the uploaded file.
- type: The MIME type of the uploaded file.
- tmp_name: The temporary filename of the uploaded file on the server.
- error: An error code indicating any issues during the upload process (refer to PHP documentation for specific error codes).
- size: The size of the uploaded file in bytes.
 
Moving Uploaded Files:
- moveUploadedFile(string $inputName, string $destination): This method attempts to move the uploaded file identified by- $inputNameto a specified- $destinationpath. It performs the following actions:- Checks if a file with the provided $inputNameexists usinghasFile.
- Verifies if the upload was successful by checking the errorcode in the file information (should beUPLOAD_ERR_OK).
- Appends the original filename to the provided $destinationpath to avoid naming conflicts.
- Uses the move_uploaded_filePHP function to move the temporary file to the specified destination.
- If the move operation is successful, it returns the complete destination path where the file is now stored.
- If any errors occur during the process, it returns null.
 
- Checks if a file with the provided 
Conclusion
The Request object is an essential tool for handling user interactions within your Floky applications. By leveraging its methods, you can effectively retrieve request data, validate user input, and implement various request-related functionalities.