Globals
The framework provides several global helper functions that are available throughout the application. These functions serve as shortcuts to common tasks, service container resolution, and utility operations.
droip_app
Get the application container instance or resolve a dependency.
Description:
The droip_app() function returns the global Application instance. If a class name or abstract string is provided, it attempts to resolve that dependency from the container.
Method Signature:
function droip_app(string $name = null, array $parameters = []): Application|mixed
Parameters:
$name- (Optional) The class name or alias to resolve.$parameters- (Optional) Parameters to pass to the constructor if resolving.
Examples:
// Get container instance
$app = droip_app();
// Resolve a service
$migrator = droip_app(Migrator::class);
// Resolve with parameters
$user = droip_app(User::class, ['user_id' => 1]);
droip_config
Get a configuration value.
Description:
The droip_config() function retrieves a value from the configuration files located in the configs directory. You can use dot notation to access nested values.
Method Signature:
function droip_config(string $key = null, mixed $default = null): mixed
Parameters:
$key- The configuration key infilename.keyformat.$default- (Optional) Default value if key is missing.
Examples:
// Get entire config array from 'app.php'
$appConfig = droip_config('app');
// Get nested value
$timezone = droip_config('app.timezone', 'UTC');
// With default value
$debug = droip_config('app.debug', false);
droip_user
Get the User model instance.
Description:
The droip_user() function resolves a User model instance from the container.
Method Signature:
function droip_user(int $user_id = null): User
Parameters:
$user_id- (Optional) The user ID to initialize the model with.
Examples:
// Get instance (empty)
$user = droip_user();
// Get specific user
$user = droip_user(1);
droip_customer
Get the Customer model instance.
Description:
The droip_customer() function resolves a Customer model instance from the container.
Method Signature:
function droip_customer(int $user_id = null, int $customer_id = null): Customer
Parameters:
$user_id- (Optional) The user ID linked to the customer.$customer_id- (Optional) The customer ID.
Examples:
// Get customer by user ID
$customer = droip_customer(1);
// Get specific customer instance
$customer = droip_customer(null, 5);
droip_settings
Get the AppSettings instance.
Description:
The droip_settings() function resolves an AppSettings instance for a specific key.
Method Signature:
function droip_settings(string $key): AppSettings
Parameters:
$key- The settings key key to resolve.
Examples:
$settings = droip_settings('general');
$siteName = $settings->get('site_name');
dd
Dump and die.
Description:
The dd() function dumps the given variables using var_dump inside a <xmp> tag for formatting and then terminates the script execution. Useful for debugging.
Method Signature:
function dd(mixed ...$args): never
Parameters:
...$args- One or more variables to dump.
Examples:
$data = ['name' => 'Test'];
dd($data);
// Output: Variable dump and script exit
pr
Print (print_r) and die.
Description:
The pr() function prints the given variables using print_r inside a <xmp> tag and then terminates the script.
Method Signature:
function pr(mixed ...$args): never
Parameters:
...$args- One or more variables to print.
Examples:
$data = ['name' => 'Test'];
pr($data);
droip_response
Get the Response instance.
Description:
The droip_response() function creates a new Response instance with standard security headers pre-configured (X-Content-Type-Options, X-Frame-Options, etc.).
Method Signature:
function droip_response(): Response
Examples:
return droip_response()->json(['status' => 'success']);
droip_with_prefix
Get a string with the application prefix.
Description:
The droip_with_prefix() function ensures the given key is prefixed with the application's defined prefix constant.
Method Signature:
function droip_with_prefix(string $key): string
Parameters:
$key- The key to prefix.
Examples:
echo droip_with_prefix('orders');
// Output: "droip_ecommerce_orders" (assuming that is the prefix)
droip_without_prefix
Get a string without the application prefix.
Description:
The droip_without_prefix() function removes the application's prefix from the given key.
Method Signature:
function droip_without_prefix(string $key): string
Parameters:
$key- The key to un-prefix.
Examples:
echo droip_without_prefix('droip_ecommerce_orders');
// Output: "orders"
droip_cast_value
Cast a value to a specific type.
Description:
The droip_cast_value() function casts a value using the DataCaster utility.
Method Signature:
function droip_cast_value(mixed $value, string $type = null): mixed
Parameters:
$value- The value to cast.$type- The target type (e.g., 'int', 'bool', 'float').
Examples:
$int = droip_cast_value('123', 'int'); // 123
$bool = droip_cast_value('true', 'bool'); // true
droip_cast_data
Cast multiple values in an array/object.
Description:
The droip_cast_data() function casts multiple fields in a data set defined by a mapping array.
Method Signature:
function droip_cast_data(array|object $data, array $map): array
Parameters:
$data- The source data.$map- Associative array of field names to types.
Examples:
$data = ['price' => '10.50', 'active' => '1'];
$map = ['price' => 'float', 'active' => 'bool'];
$casted = droip_cast_data($data, $map);
// ['price' => 10.5, 'active' => true]
droip_redirect
Redirect to a location.
Description:
The droip_redirect() function is a helper wrapper for Url::redirect().
Method Signature:
function droip_redirect(string $location): void
Parameters:
$location- The URL to redirect to.
Examples:
droip_redirect('/dashboard');
droip_is_valid_json
Check if a string is valid JSON.
Description:
The droip_is_valid_json() function checks if the provided string is a valid JSON format.
Method Signature:
function droip_is_valid_json(string $string): bool
Parameters:
$string- The string to check.
Examples:
if (droip_is_valid_json('{"a":1}')) {
// Valid
}
droip_clean_path
Clean and normalize a file path.
Description:
The droip_clean_path() function calls wp_normalize_path and optionally adds or removes a trailing slash.
Method Signature:
function droip_clean_path(string $path, bool $trailing_slash = true): string
Parameters:
$path- The path to clean.$trailing_slash- (Optional) Whether to ensure a trailing slash. Defaults totrue.
Examples:
echo droip_clean_path('C:\\xampp\\htdocs\\site');
// Output: "C:/xampp/htdocs/site/"
droip_uuid
Generate a UUID.
Description:
The droip_uuid() function generates a version 4 UUID using Utils::uuid().
Method Signature:
function droip_uuid(): string
Examples:
$uuid = droip_uuid();
droip_url
Generate a URL with query parameters.
Description:
The droip_url() function is a wrapper for Url::make().
Method Signature:
function droip_url(string $url, array $query_vars = []): string
Parameters:
$url- Base URL.$query_vars- Associative array of query parameters.
Examples:
echo droip_url('/shop', ['sort' => 'new']);
// "/shop?sort=new"
droip_is_block_theme
Check if the active theme is a block theme.
Description:
The droip_is_block_theme() function checks if the site is currently using a Full Site Editing (Block) theme.
Method Signature:
function droip_is_block_theme(): bool
Examples:
if (droip_is_block_theme()) {
// Load block-specific assets
}
droip_migrator
Get the Migrator instance.
Description:
The droip_migrator() function resolves the Migrator service from the container.
Method Signature:
function droip_migrator(): Migrator
Examples:
droip_migrator()->run();
droip_decision_engine
Get the DecisionEngine instance.
Description:
The droip_decision_engine() function resolves the DecisionEngine service from the container.
Method Signature:
function droip_decision_engine(): DecisionEngine
Examples:
$engine = droip_decision_engine();
droip_tap
Tap into a value.
Description:
The droip_tap() function allows you to call a closure with a given value and then returns the value itself. If no closure is passed, it returns a HigherOrderTapProxy.
Method Signature:
function droip_tap(mixed $value, callable $callback = null): mixed
Parameters:
$value- The value to tap into.$callback- (Optional) The closure to execute.
Examples:
$user = droip_tap(User::find(1), function($user) {
$user->update(['last_login' => now()]);
});
// Returns the user instance
droip_base_currency_code
Get the base currency code.
Description:
The droip_base_currency_code() function retrieves the base currency code defined in the settings. Defaults to 'USD'.
Method Signature:
function droip_base_currency_code(): string
Examples:
echo droip_base_currency_code(); // "USD"
droip_fake
Get a Faker instance.
Description:
The droip_fake() function returns a Faker\Generator instance if the Faker library is available.
Method Signature:
function droip_fake(): ?Faker\Generator
Examples:
$name = droip_fake()->name();
$email = droip_fake()->email();