Neuron-PHP

Documentation

Table of Contents

Packages

Application
Neuron

Namespaces

Neuron

Functions

auth()  : User|null
Get the authenticated user
user()  : User|null
Alias for auth()
user_id()  : int|null
Get the authenticated user's ID
is_logged_in()  : bool
Check if user is authenticated
is_guest()  : bool
Check if user is a guest (not authenticated)
is_admin()  : bool
Check if user is an admin
is_editor()  : bool
Check if user is an editor
is_author()  : bool
Check if user is an author
has_role()  : bool
Check if user has a specific role
csrf_token()  : string
Get the current CSRF token
csrf_field()  : string
Generate a CSRF token hidden input field
current_user_identifier()  : string
Get current user identifier for audit purposes
sendEmail()  : bool
Send a simple email
sendEmailTemplate()  : bool
Send an email using a template
email()  : Sender
Create a new email Sender instance with fluent interface
gravatar_url()  : string
Generate a Gravatar URL for the given email address
gravatar()  : string
Generate a complete Gravatar image tag
route_path()  : string
Generate a relative URL path for a named route
route_url()  : string
Generate an absolute URL for a named route
format_user_datetime()  : string
Format a DateTimeImmutable object in the authenticated user's timezone
format_user_date()  : string
Format a DateTimeImmutable object as a date (no time) in the authenticated user's timezone
get_timezones()  : array<string, array<string|int, string>>
Get a list of all available timezones grouped by region
group_timezones_for_select()  : array<string, array<string|int, array{value: string, label: string, selected: bool}>>
Prepare timezones for select dropdown with selection state
boot()  : Scheduler|null
Initialize the application.
scheduler()  : void
Run the application.
dispatch()  : string
Dispatch a job to the queue for background processing
dispatchNow()  : mixed
Execute a job immediately (synchronously), bypassing the queue
getQueueManager()  : QueueManager
Get the queue manager instance from registry
queueSize()  : int
Get the size of a queue
clearQueue()  : int
Clear all jobs from a queue

Functions

auth()

Get the authenticated user

auth() : User|null
Return values
User|null

user_id()

Get the authenticated user's ID

user_id() : int|null
Return values
int|null

is_logged_in()

Check if user is authenticated

is_logged_in() : bool
Return values
bool

is_guest()

Check if user is a guest (not authenticated)

is_guest() : bool
Return values
bool

is_admin()

Check if user is an admin

is_admin() : bool
Return values
bool

is_editor()

Check if user is an editor

is_editor() : bool
Return values
bool

is_author()

Check if user is an author

is_author() : bool
Return values
bool

has_role()

Check if user has a specific role

has_role(string $role) : bool
Parameters
$role : string
Return values
bool

csrf_token()

Get the current CSRF token

csrf_token() : string
Return values
string

csrf_field()

Generate a CSRF token hidden input field

csrf_field() : string
Return values
string

current_user_identifier()

Get current user identifier for audit purposes

current_user_identifier() : string

Returns the authenticated CMS user's username if available (web context), otherwise returns the OS user running the process (CLI context).

Return values
string

User identifier (e.g., "admin" or "www-data" or "system")

sendEmail()

Send a simple email

sendEmail(string $to, string $subject, string $body[, bool $isHtml = true ][, ISettingSource|null $settings = null ]) : bool
Parameters
$to : string

Recipient email address

$subject : string

Email subject

$body : string

Email body content

$isHtml : bool = true

Whether the body is HTML (default: true)

$settings : ISettingSource|null = null

Optional settings source for email configuration

Tags
example

sendEmail('[email protected]', 'Welcome!', '

Welcome to our site!

');

Return values
bool

True if email was sent successfully

sendEmailTemplate()

Send an email using a template

sendEmailTemplate(string $to, string $subject, string $template[, array<string|int, mixed> $data = [] ][, ISettingSource|null $settings = null ][, string $basePath = '' ]) : bool
Parameters
$to : string

Recipient email address

$subject : string

Email subject

$template : string

Template path relative to resources/views

$data : array<string|int, mixed> = []

Data to pass to the template

$settings : ISettingSource|null = null

Optional settings source for email configuration

$basePath : string = ''

Base path for template resolution (default: current directory)

Tags
example

sendEmailTemplate( '[email protected]', 'Welcome!', 'emails/welcome', ['userName' => 'John', 'activationLink' => 'https://...'] );

Return values
bool

True if email was sent successfully

email()

Create a new email Sender instance with fluent interface

email([ISettingSource|null $settings = null ][, string $basePath = '' ]) : Sender
Parameters
$settings : ISettingSource|null = null

Optional settings source for email configuration

$basePath : string = ''

Base path for template resolution (default: current directory)

Tags
example

email() ->to('[email protected]') ->cc('[email protected]') ->subject('Order Confirmation') ->template('emails/order-confirmation', ['order' => $order]) ->attach('/path/to/invoice.pdf', 'invoice.pdf') ->send();

Return values
Sender

gravatar_url()

Generate a Gravatar URL for the given email address

gravatar_url(string $email[, int $size = 80 ][, string $default = 'mp' ]) : string
Parameters
$email : string

Email address

$size : int = 80

Image size in pixels (default: 80)

$default : string = 'mp'

Default image type (mp, identicon, monsterid, wavatar, retro, robohash, blank)

Tags
example

gravatar_url('[email protected]', 128, 'identicon')

Return values
string

Gravatar URL

gravatar()

Generate a complete Gravatar image tag

gravatar(string $email[, int $size = 80 ][, string $default = 'mp' ][, string $class = '' ]) : string
Parameters
$email : string

Email address

$size : int = 80

Image size in pixels (default: 80)

$default : string = 'mp'

Default image type (mp, identicon, monsterid, wavatar, retro, robohash, blank)

$class : string = ''

Additional CSS classes to add to the img tag

Tags
example

gravatar('[email protected]', 32, 'mp', 'rounded-circle')

Return values
string

Complete HTML img tag

route_path()

Generate a relative URL path for a named route

route_path(string $routeName[, array<string, mixed> $parameters = [] ]) : string
Parameters
$routeName : string

The name of the route

$parameters : array<string, mixed> = []

Route parameters

Tags
example

route_path('blog_post', ['slug' => 'my-post']) // Returns: /blog/post/my-post route_path('admin_dashboard') // Returns: /admin/dashboard

Return values
string

Relative URL path

route_url()

Generate an absolute URL for a named route

route_url(string $routeName[, array<string, mixed> $parameters = [] ]) : string
Parameters
$routeName : string

The name of the route

$parameters : array<string, mixed> = []

Route parameters

Tags
example

route_url('blog_post', ['slug' => 'my-post']) // Returns: https://example.com/blog/post/my-post route_url('admin_dashboard') // Returns: https://example.com/admin/dashboard

Return values
string

Absolute URL

format_user_datetime()

Format a DateTimeImmutable object in the authenticated user's timezone

format_user_datetime(DateTimeImmutable|null $dateTime[, string $format = 'Y-m-d H:i' ]) : string

Converts a DateTime from UTC to the user's preferred timezone and formats it. Falls back to system timezone if no user is authenticated or user has no timezone set.

Parameters
$dateTime : DateTimeImmutable|null

DateTime to format (assumed to be in UTC)

$format : string = 'Y-m-d H:i'

Date format string (default: 'Y-m-d H:i')

Tags
example

format_user_datetime($post->getCreatedAt()) // Returns: 2024-11-10 15:30 format_user_datetime($post->getCreatedAt(), 'F j, Y g:i A') // Returns: November 10, 2024 3:30 PM

Return values
string

Formatted date/time string, or 'N/A' if dateTime is null

format_user_date()

Format a DateTimeImmutable object as a date (no time) in the authenticated user's timezone

format_user_date(DateTimeImmutable|null $dateTime[, string $format = 'Y-m-d' ]) : string

Convenience wrapper around format_user_datetime for date-only display.

Parameters
$dateTime : DateTimeImmutable|null

DateTime to format (assumed to be in UTC)

$format : string = 'Y-m-d'

Date format string (default: 'Y-m-d')

Tags
example

format_user_date($post->getCreatedAt()) // Returns: 2024-11-10 format_user_date($post->getCreatedAt(), 'F j, Y') // Returns: November 10, 2024

Return values
string

Formatted date string, or 'N/A' if dateTime is null

get_timezones()

Get a list of all available timezones grouped by region

get_timezones() : array<string, array<string|int, string>>

Returns an associative array with regions as keys and arrays of timezones as values. Useful for populating timezone dropdown selects.

Tags
example

$timezones = get_timezones(); // Returns: ['America' => ['America/New_York', 'America/Chicago', ...], ...]

Return values
array<string, array<string|int, string>>

Grouped timezones

group_timezones_for_select()

Prepare timezones for select dropdown with selection state

group_timezones_for_select(array<int, string> $timezones[, string|null $currentTimezone = null ]) : array<string, array<string|int, array{value: string, label: string, selected: bool}>>

Groups timezones by region and returns a structured array ready for rendering in a select dropdown. Each timezone includes value, label, and selected state.

Parameters
$timezones : array<int, string>

List of timezone identifiers

$currentTimezone : string|null = null

Currently selected timezone

Tags
example

$grouped = group_timezones_for_select($timezones, 'America/New_York'); // Returns: // [ // 'America' => [ // ['value' => 'America/New_York', 'label' => 'America/New_York', 'selected' => true], // ['value' => 'America/Chicago', 'label' => 'America/Chicago', 'selected' => false], // ], // 'Other' => [...] // ]

Return values
array<string, array<string|int, array{value: string, label: string, selected: bool}>>

Grouped timezones

boot()

Initialize the application.

boot(string $ConfigPath) : Scheduler|null
Parameters
$ConfigPath : string
Tags
throws
Exception
Return values
Scheduler|null

scheduler()

Run the application.

scheduler(Scheduler $App, array<string|int, mixed> $argv) : void
Parameters
$App : Scheduler
$argv : array<string|int, mixed>
Tags
throws
Exception

dispatch()

Dispatch a job to the queue for background processing

dispatch(IJob $job[, array<string|int, mixed> $args = [] ][, string|null $queue = null ][, int $delay = 0 ]) : string
Parameters
$job : IJob

Job instance to queue

$args : array<string|int, mixed> = []

Arguments to pass to the job

$queue : string|null = null

Queue name (null = default)

$delay : int = 0

Delay in seconds before job is available

Tags
example

// Basic usage dispatch(new SendEmailJob(), ['to' => '[email protected]']);

// With specific queue dispatch(new ProcessImageJob(), ['path' => '/tmp/image.jpg'], 'images');

// Delayed job (run in 1 hour) dispatch(new SendReminderJob(), ['order_id' => 123], 'default', 3600);

Return values
string

Job ID

dispatchNow()

Execute a job immediately (synchronously), bypassing the queue

dispatchNow(IJob $job[, array<string|int, mixed> $args = [] ]) : mixed

Useful for testing or when you want to ensure a job runs in the current process without queueing.

Parameters
$job : IJob

Job instance to execute

$args : array<string|int, mixed> = []

Arguments to pass to the job

Tags
example

$result = dispatchNow(new ProcessDataJob(), ['data' => $data]);

Return values
mixed

Job result

getQueueManager()

Get the queue manager instance from registry

getQueueManager() : QueueManager

Creates a new instance if one doesn't exist.

Return values
QueueManager

queueSize()

Get the size of a queue

queueSize([string|null $queue = null ]) : int
Parameters
$queue : string|null = null

Queue name (null = default)

Tags
example

$size = queueSize(); // default queue $emailQueueSize = queueSize('emails');

Return values
int

Number of jobs in queue

clearQueue()

Clear all jobs from a queue

clearQueue([string|null $queue = null ]) : int
Parameters
$queue : string|null = null

Queue name (null = default)

Tags
example

$cleared = clearQueue('emails');

Return values
int

Number of jobs cleared

Search results