Install Canary
require 'canary/setup.php';
Include the setup file to initialize the Canary PHP Framework environment and prepare routing, database, and utilities.
Framework Structure
api/ ├── canary/ │ └── setup.php ├── user/ │ ├── index.php │ ├── controller.php │ └── model.php ├── wallet/ ├── notification/ └── ...
Directory structure of the API organized in a simple MVC format per module (user, wallet, etc.).
Routing Example
canary::Route('signin', $user);
Used to map a specific action like 'signin' to a corresponding method inside the provided class instance (e.g., $user->signin()).
Example API Call
POST /api/user/index.php { "action": "signin", "email": "test@example.com", "password": "123456" }
Typical API usage scenario to sign in a user using POST data.
var
canary::var($var);
Returns a global variable value from the canary container.
SET
canary::SET($var, $val);
Sets a global variable inside the canary container.
GET
canary::GET();
Parses and logs data from $_GET and returns it as JSON.
POST
canary::POST();
Parses and logs data from $_POST and returns it as JSON.
REQUEST
canary::REQUEST();
Parses and logs data from $_REQUEST and returns it as JSON.
REQUESTW
canary::REQUESTW();
Parses data from $_REQUEST and returns it silently (no logs or echo).
ENV
canary::ENV($var = null);
Returns a specific environment variable or all if null.
sendOTPEmail
canary::sendOTPEmail($toEmail, $otp);
Sends an OTP email using environment mail settings.
sendOTPWhatsApp
canary::sendOTPWhatsApp($toWhatsapp, $otp);
Sends an OTP code via WhatsApp using WhatsApp API.
sendFCM
canary::sendFCM($token, $title, $body, $image = null);
Sends push notification via Firebase to a device.
sendSocketFCM
canary::sendSocketFCM($deviceToken, $data);
Sends a push notification via WebSocket FCM.
sendBroadcastFCM
canary::sendBroadcastFCM($tokensArray, $data);
Sends a broadcast message to multiple devices via FCM.
getLang
canary::getLang();
Returns the current language stored in canary.
getToken
canary::getToken();
Returns the current user token from canary.
checkToken
canary::checkToken($dbtbl, $dbtoken = null, $dbexpier = null);
Validates the user token using database and expiry rules.
VERSION
canary::VERSION($min, $last, $name);
Checks current app version and enforces update if required.
MAINTENANCE
canary::MAINTENANCE($bool = null);
Shows maintenance message based on state.
allowedReport
canary::allowedReport();
Enables system to show error reports.
allowedDoctor
canary::allowedDoctor();
Enables Doctor Debug Mode.
doctor
canary::doctor();
Prints runtime logs if Doctor Mode is enabled.
doctori
canary::doctori();
Prints extra info during debug when Doctor Info is enabled.
listening
canary::listening($res, $data = null);
Logs a success message and optionally logs data.
listeninge
canary::listeninge($res, $data = null);
Logs a failed message and optionally logs data.
export
canary::export($msg, $code = null, $data = null, $msgAr = null);
Exports a JSON response with HTTP status code.
conn
canary::conn();
Returns the active database connection.
SQL
canary::SQL($sql);
Executes an SQL query and logs results.
SELECT
canary::SELECT($sql);
Runs a SELECT query and logs results.
SELECTW
canary::SELECTW($sql);
Runs a SELECT query without logs.
SELECT1
canary::SELECT1($sql);
Returns the first row of SELECT result.
SELECT1W
canary::SELECT1W($sql);
Returns first row of SELECT without logs.
INSERT
canary::INSERT($sql);
Executes an INSERT SQL query.
UPDATE
canary::UPDATE($sql);
Executes an UPDATE SQL query.
DELETE
canary::DELETE($sql);
Executes a DELETE SQL query.
lastSQL
canary::lastSQL();
Returns the last executed SQL query.
lastId
canary::lastId();
Returns the last inserted ID from DB.
checkLibImport
canary::checkLibImport($lib);
Checks if a library has been imported.
geo
canary::geo($ip = null);
Returns geo information for IP address.
Route
canary::Route($key, $class, $prm = null);
Routes the action parameter to the appropriate class method.
VALIDATE
canary::VALIDATE(&$input, $type = null, $options = []);
Validates input value by type (email, number, etc).
Copyright © 2020-2024 Canary Holdings Inc.