Skip to content

API Helpers

Dory Azar edited this page Nov 15, 2026 · 2 revisions

Helper functions

Caligrafy Quill 2.26.0. Generated from the source by php qa/build-api-reference.php; the guides explain how to use these classes, this reference says exactly what each public method takes and returns. Back to the API reference.

The global functions of framework/helpers, loaded for every request and command.

corehelpers.php

generateKey()

function generateKey($size = 32)

No doc comment.

Parameters

  • $size, default 32

Source: framework/helpers/corehelpers.php:26

generateToken()

function generateToken($size = 12)

No doc comment.

Parameters

  • $size, default 12

Source: framework/helpers/corehelpers.php:31

encryptDecrypt()

function encryptDecrypt($action, $data, $key = APP_KEY)

Encryption and Decryption methods used for key identification of entities

Parameters

  • $action string: to specify whether it is an ecryption or decryption
  • $data
  • $key, default APP_KEY

Returns string: of the encrypted or decrypted field

Source: framework/helpers/corehelpers.php:43

isSessionExpired()

function isSessionExpired($time = SESSION_EXPIRATION_TIME)

Checks if a session expired and if it is the session is terminated

Parameters

  • $time int, default SESSION_EXPIRATION_TIME: passes a time argument to override the default session_expiration_time if needed

Source: framework/helpers/corehelpers.php:77

saveInSession()

function saveInSession($input_data, $session_variable)

Saves forms in a session array

Parameters

  • $input_data array: of all variables saved in form
  • $session_variable string: identifies the session array where data should be saved

Source: framework/helpers/corehelpers.php:94

clearFromSession()

function clearFromSession($session_variable)

Clears data from a specific session variable

Parameters

  • $session_variable string: identifies the session array where data has been saved

Source: framework/helpers/corehelpers.php:110

scripts()

function scripts($key, $value = null)

Gets/Sets script from session by key name

Parameters

  • $key string: defines the keyname to look for in the session variables
  • $value, default null

Source: framework/helpers/corehelpers.php:127

design_stylesheet()

function design_stylesheet()

URL of the override stylesheet of the design style selected in .env (DESIGN_STYLE), loaded after the Caligrafy stylesheets; '' for Caligrafy's own look (empty setting, unknown style or stylesheet not written yet)

Source: framework/helpers/corehelpers.php:139

copyright()

function copyright($value = null)

Gets the copyright signature from session

Parameters

  • $value, default null

Source: framework/helpers/corehelpers.php:149

keywords()

function keywords($value = null)

Gets/Sets the keywords

Parameters

  • $value, default null

Source: framework/helpers/corehelpers.php:162

metadata()

function metadata($pairs = array())

Gets/Sets a metadata variable by key

Parameters

  • $pairs, default array()

Source: framework/helpers/corehelpers.php:175

session()

function session($key, $value = null)

Gets/Sets a session variable by key

Parameters

  • $key
  • $value, default null

Source: framework/helpers/corehelpers.php:190

caligrafySessionNeeded()

function caligrafySessionNeeded($key, $value, $ready)

Whether session($key, $value) needs the session started (2.19.0): reading the CSRF token always does (it is handed to a page or a client), a write does once the request's settings ran ($ready, caligrafySessionSnapshot()). The settings (coresettings.php, config.php) write scripts, metadata, keywords... on every request: they stay in memory.

Parameters

  • $key
  • $value
  • $ready

Source: framework/helpers/corehelpers.php:207

caligrafySessionReady()

function caligrafySessionReady()

Whether the request's settings ran (caligrafySessionSnapshot() was called)

Source: framework/helpers/corehelpers.php:218

caligrafySessionMustSave()

function caligrafySessionMustSave($snapshot, array $session, $output)

Whether a request that came without a session cookie must save its session when it ends (2.19.0): it changed $_SESSION after the snapshot, or its output carries the CSRF token (a form posts it back)

Parameters

  • $snapshot
  • $session array
  • $output

Source: framework/helpers/corehelpers.php:227

caligrafySessionStart()

function caligrafySessionStart()

Starts the session of a request that came without a session cookie (2.19.0): the values this request already put in $_SESSION are kept. True when the session is active.

Source: framework/helpers/corehelpers.php:240

caligrafySessionSnapshot()

function caligrafySessionSnapshot()

What the session holds once the settings ran (config.php sets metadata, keywords...): a request that changes it afterwards, or whose page carries the CSRF token, gets its session saved (caligrafySessionShutdown)

Source: framework/helpers/corehelpers.php:261

caligrafySessionShutdown()

function caligrafySessionShutdown()

No doc comment.

Source: framework/helpers/corehelpers.php:271

view()

function view($viewName, $viewData = array())

Generic view function that instantiates a View class

Parameters

  • $viewName
  • $viewData, default array()

Source: framework/helpers/corehelpers.php:288

api()

function api($viewData = array())

Generic view function that instantiates a View class

Parameters

  • $viewData, default array()

Source: framework/helpers/corehelpers.php:298

findKey()

function findKey($array, $keySearch)

Looks for a key in a multidimensional array

Parameters

  • $array array: define the array to be searched
  • $keySearch string: defines the key to be searched

Returns boolean: if at least one instance is found

Source: framework/helpers/corehelpers.php:312

recursive_filter()

function recursive_filter(&$array, $allowed)

Filters the result depending on package chosen

Parameters

  • $array int: defines the array to be filtered
  • $allowed array: defines what the package allows

Returns array: the filtered results

Source: framework/helpers/corehelpers.php:337

loadConstantFromArray()

function loadConstantFromArray($array)

Define constants from 2D array

Parameters

  • $array array: defines the array to turn into constant definition

Returns boolean: if action was executed

Source: framework/helpers/corehelpers.php:359

terminateSession()

function terminateSession($url)

Terminates a session

Parameters

  • $url: to redirect the user upon session termination

Source: framework/helpers/corehelpers.php:378

getGlobalInformation()

function getGlobalInformation($superGlobal = 'session')

Function that gets all the super global variables needed for a page to function

Parameters

  • $superGlobal string, default 'session': determines which super variable to fetch information from

Returns array: $result returns an array of all the fetched information desired

Source: framework/helpers/corehelpers.php:396

isAllowedUpload()

function isAllowedUpload($filename, $allowedExtensions = null)

Checks if a file name has an extension that can safely be uploaded

Parameters

  • $filename string: the original file name
  • $allowedExtensions array, default null: the allowed extensions. Defaults to DEFAULT_UPLOAD_EXTENSIONS

Returns boolean: true if the extension is allowed

Source: framework/helpers/corehelpers.php:438

uploadFile()

function uploadFile($picture, $allowedExtensions = null)

Uploads a file from a form into the server

Parameters

  • $picture array: defines the file attributes array (an entry of $_FILES)
  • $allowedExtensions array, default null: the allowed extensions. Defaults to DEFAULT_UPLOAD_EXTENSIONS

Returns string: the resulting public URL of the uploaded file, or '' if the file was refused or could not be moved

Source: framework/helpers/corehelpers.php:455

deleteFile()

function deleteFile($url)

Deletes a file given its public path

Parameters

  • $url string: of the image public url

Returns boolean: of the result

Source: framework/helpers/corehelpers.php:491

isJson()

function isJson($string)

Checks if a string is a json

Parameters

  • $string string: defines the string to be checked

Returns boolean: true if it is a json

Source: framework/helpers/corehelpers.php:511

sanitize()

function sanitize($string)

Sanitizes a string from html tags

Parameters

  • $string string: defines the string to be sanitized

Returns string: the sanitized screen

Source: framework/helpers/corehelpers.php:526

request()

function request()

Accessor to the request information

Returns Request: the request object information

Source: framework/helpers/corehelpers.php:539

connect()

function connect()

Accessor connects a controller to the model

Returns Model: with connection to database established

Source: framework/helpers/corehelpers.php:552

import()

function import($filename)

Accessor to require more librairies and helpers classes and files

Parameters

  • $filename

Source: framework/helpers/corehelpers.php:564

parsePath()

function parsePath($path)

No doc comment.

Parameters

  • $path

Source: framework/helpers/corehelpers.php:577

currentRoute()

function currentRoute()

Accessor to the route information

Returns String: the route information

Source: framework/helpers/corehelpers.php:591

currentBind()

function currentBind()

Accessor to the list of variables bound to the route

Returns Array: bound variables from the route

Source: framework/helpers/corehelpers.php:602

startWith()

function startWith($haystack, $needle)

Checks if strings starts with a character and removes it

Parameters

  • $haystack
  • $needle

Returns String: with the character removed

Source: framework/helpers/corehelpers.php:613

endWith()

function endWith($haystack, $needle)

Checks if strings ends with a character and removes it

Parameters

  • $haystack
  • $needle

Returns String: with the character removed

Source: framework/helpers/corehelpers.php:624

sanitizePath()

function sanitizePath($path)

Sanitizes the path by getting rid of beginning and ending slashes

Parameters

  • $path

Returns String: the new path without the slashes

Source: framework/helpers/corehelpers.php:636

associate()

function associate($controller, $modelname, $table)

No doc comment.

Parameters

  • $controller
  • $modelname
  • $table

Source: framework/helpers/corehelpers.php:643

bindRouteToVar()

function bindRouteToVar($route, $uri, $pattern = ROUTE_ARG_PATTERN)

No doc comment.

Parameters

  • $route
  • $uri
  • $pattern, default ROUTE_ARG_PATTERN

Source: framework/helpers/corehelpers.php:648

parseRoute()

function parseRoute($path, $pattern = ROUTE_ARG_PATTERN)

Parses a path

Parameters

  • $path
  • $pattern, default ROUTE_ARG_PATTERN

Returns parsed: information

Source: framework/helpers/corehelpers.php:672

_require_all()

function _require_all($path, $depth = 0)

load all files in user-created directories and subdirectories

Parameters

  • $path
  • $depth, default 0

Source: framework/helpers/corehelpers.php:689

singularize()

function singularize($word)

Singularizes regular plurals

Parameters

  • $word

Source: framework/helpers/corehelpers.php:712

methodField()

function methodField($method)

Injects a hidden html input to change the method

Parameters

  • $method

Source: framework/helpers/corehelpers.php:722

csrf()

function csrf()

Injects a csrf field into the form

Source: framework/helpers/corehelpers.php:732

errors()

function errors($field = null)

The field errors a Route::form() sent back with the previous request (2.19.0): all of them, or one field's message (null when it has none). In a view: if errors('title') / p.cq-field-error= errors('title')

Parameters

  • $field, default null

Source: framework/helpers/corehelpers.php:741

old()

function old($field, $default = '')

What a field held when a Route::form() sent it back (2.19.0), else $default: input(name='title', value=old('title')) Passwords and other secrets are never kept.

Parameters

  • $field
  • $default, default ''

Source: framework/helpers/corehelpers.php:751

flash()

function flash($key, $value = null)

A message of the previous request (2.19.0): flash('success') after a Route::form() 'flash', flash('error') after invalid input; with a value, keeps a message for the next request

Parameters

  • $key
  • $value, default null

Source: framework/helpers/corehelpers.php:761

authorize()

function authorize($user)

Method that authorizes a logged in user to perform actions

Parameters

  • $user

Source: framework/helpers/corehelpers.php:776

authorized()

function authorized()

Method that checks if a session user is allowed to perform actions

Source: framework/helpers/corehelpers.php:786

unauthorize()

function unauthorize()

Method used upon logout to unauthorize a user in session from performing actions

Source: framework/helpers/corehelpers.php:796

user()

function user()

Method that retrieves the user currently logged in

Source: framework/helpers/corehelpers.php:806

guard()

function guard(
    $permissionAttribute,
    $acceptedPermission,
    $loginUrl = '/login',
    $notAuthorized = '/notAuthorized'
)

Method that checks if the user in session has permissions to access

Parameters

  • $permissionAttribute
  • $acceptedPermission
  • $loginUrl, default '/login'
  • $notAuthorized, default '/notAuthorized'

Returns boolean: of whether or not the user is valid and allowed to perform actions

Source: framework/helpers/corehelpers.php:815

logout()

function logout($redirectUrl = '/')

Method that logs the user out

Parameters

  • $redirectUrl, default '/'

Source: framework/helpers/corehelpers.php:823

imageCanva()

function imageCanva()

Method that instantiates the Claviska Simple Image library that manipulate pictures

Source: framework/helpers/corehelpers.php:834

load_script()

function load_script($params)

Loads a script into the UI

Parameters

  • $params array: inputs needed to generate the script

Returns string: HTML or TXT fully formatted

Source: framework/helpers/corehelpers.php:854

redirect()

function redirect($url)

Reroutes to another url

Parameters

  • $url

Source: framework/helpers/corehelpers.php:874

getRelativeTime()

function getRelativeTime($datetime, $depth = 1)

Get RelativeTime

Parameters

  • $datetime
  • $depth, default 1

Source: framework/helpers/corehelpers.php:891

rearrange()

function rearrange($arr)

Rearrange multi-dimensional array onto key array. Used to rearrange File inputs

Parameters

  • $arr

Source: framework/helpers/corehelpers.php:947

httpFile()

function httpFile($url, $filepath, $headers, $username = null, $password = null, $purpose = 'assistants')

cUrl post file function

Parameters

  • $url
  • $filepath
  • $headers
  • $username, default null
  • $password, default null
  • $purpose, default 'assistants'

Source: framework/helpers/corehelpers.php:959

httpRequest()

function httpRequest($url, $method, $data, $headers, $username = null, $password = null)

cUrl request function

Parameters

  • $url
  • $method
  • $data
  • $headers
  • $username, default null
  • $password, default null

Source: framework/helpers/corehelpers.php:998

now()

function now()

now() returns the current timestamp in a mySQL format

Source: framework/helpers/corehelpers.php:1038

sendMail()

function sendMail($recipients, $emailContent, $from)

sendMail() sends an email using the configuration in the .env file

Parameters

  • $recipients array: : array('email' => 'recipient_email', 'name' => 'recipent_name)
  • $emailContent
  • $from

Source: framework/helpers/corehelpers.php:1049

arraySort()

function arraySort($array, $attribute, $sort = SORT_DESC)

arraySort() sorts a multimdimensional array by a column

Parameters

  • $array array: defines the array to sort
  • $attribute string: defines the column to sort by
  • $sort string, default SORT_DESC: defines the sorting direction: SORT_ASC, SORT_DESC

Returns array: sorted array

Source: framework/helpers/corehelpers.php:1063

Caligrafy: Describe it. Approve it. Ship it. Your idea turned into a complete app: every feature built once, for web pages, Vue apps, a REST API and AI agents, and online.

Start here

Why Caligrafy: the benefits, the measurements, and what it is not yet

  1. Quickstart with Claude: describe it, approve it, ship it

    or the Quickstart: the same three steps by hand, in 5 minutes

  2. How Caligrafy works: the ideas in 5 minutes
  3. Your first capability: build a feature, page included

Capabilities

Experiences

Data and people

  1. Models
  2. Relationships
  3. Queries: filters, paging, related rows
  4. Sign-in, users and tokens

Built-in features

Put it online

Build with AI

Reference

Clone this wiki locally