phputils/framework

Tiniest PHP framework


License
MIT

Documentation

Installation

Just run composer install [package_name]

After that all these functions should be available in every PHP file (via composer's autoloader)

handle_cors

Handles a CORS request

function handle_cors($domainCheck = NULL, $extra = [])

get_domain

Returns domain of the app

function get_domain()

get_http_method

Returns the HTTP method

function get_http_method($allowed = ['get', 'post', 'options'])

check_http_method

Returns the HTTP method

function check_http_method(...$allowed)

handle_upload

Handles a file upload

function handle_upload($names = NULL, $destDir = NULL, $allowedExt = NULL)

handle_json_request

Process PHP json request

function handle_json_request()

config

Gets value from config file

function config($name, $default)

app_dir

Return app's base dir

function app_dir($path = NULL, $check_exists = TRUE)

url

Creates a URL for current app

function url($url, $params = [])

auth_url

Creates a pre-authenticated url

function auth_url($url, $user_id, $activity = 'link_click', $data = [])

is_ajax_request

Check if it is a ajax request

function is_ajax_request()

login_redir

Redirect to login page with error

function login_redir($message = '')

abort

Aborts a request with 403 error code

function abort($message = '', $code = 403)

redirect

Redirect to another url

function redirect($location, $code = 302, $message = NULL)

request

Returns a request param

@return string|array

function request($name = NULL, $default = NULL)

add_route

Adds a route for router

function add_route(string $path, $action, $method = '', $auth = FALSE)

router

Simplest PHP router

function router()

jwt_cookie_name

Returns the name of the JWT COOKIE

function jwt_cookie_name()

user

Get logged in user

function user($key = '', $default = NULL)

user_id

Logged in user's id

function user_id()

check_login

Checks if the user is logged-in (returns user_id) otherwise aborts

function check_login()

site_set_cookie

Sets a global cookie

function site_set_cookie($name, $value, $expires = 0)

user_login

Log in a user by starting session

function user_login($user, $expires = 86400)

user_logout

Logs out existing user

function user_logout()

user_info_public

All publicly accessible user info

function user_info_public($user = NULL)

guest_id

Checks if the user is authenticated in guest mode and if so returns the user_id (false otherwise)

function guest_id()

bootstrap

Handles setting up environment for handling http requests

function bootstrap($env)