Documentation

Job
in package
implements JobInterface, ConfigurableInterface, LoggableInterface, ValidatesInterface uses LoggerTrait, RulesValidatorTrait

AbstractYes

A job. Could be a cron or a worker. You decide.

Has built-in config, logging, validation, stats.

Table of Contents

Interfaces

JobInterface
A job. Could be a cron or a worker. You decide.
ConfigurableInterface
This class is 'configurable' - it has an `update()` method that accepts iterables.
LoggableInterface
This class has logging capabilities.
ValidatesInterface
This class can validate.

Properties

$config  : array<string|int, mixed>
$id  : string
$start  : int
$loggers  : array<string|int, callable>

Methods

__construct()  : void
Create and validate a job with this config.
addLogger()  : int
Register a logger.
attach()  : void
Forward any logs from this loggable to a parent loggable.
clearLoggers()  : void
execute()  : static
Shorthand for creating, validating and running a job.
getId()  : string
A unique identifier.
getValidator()  : RulesValidatorInterface
log()  : void
Log something.
rules()  : array<string|int, mixed>
stats()  : array<string|int, string>
Get the current stats.
update()  : void
Update the object with a new configuration.
valid()  : array<string|int, mixed>|true
Validate this scenario (or default).
validate()  : void
Validate this scenario (or default).

Properties

$config

public array<string|int, mixed> $config = []

$id

public string $id = ''

$start

public int $start = 0

Unix timestamp in seconds.

$loggers

private array<string|int, callable> $loggers = []

Methods

__construct()

Create and validate a job with this config.

public __construct([array<string|int, mixed> $config = [] ][, bool $validate = true ]) : void
Parameters
$config : array<string|int, mixed> = []
$validate : bool = true

addLogger()

Register a logger.

public addLogger(callable|LogSinkInterface $logger[, int|null $level = null ][, string|array<string|int, mixed>|null $category = null ]) : int

Logs can be filtered by level and category.

// Only permit log levels higher than this:
// (excludes INFO, DEBUG, etc)
$loggable->addLogger($logger, Log::LEVEL_WARNING);

// Only permit this category:
$loggable->addLogger($logger, null, 'progress');

// Only permit these categories:
$loggable->addLogger($logger, null, ['log.request', 'log.response']);

// Exclude these categories:
$loggable->addLogger($logger, null, ['stats' => false, 'meta' => false]);
Parameters
$logger : callable|LogSinkInterface

(message, level, category, timestamp)

$level : int|null = null

filter by level

$category : string|array<string|int, mixed>|null = null

filter by category

Return values
int

attach()

Forward any logs from this loggable to a parent loggable.

public attach(callable|LogSinkInterface $logger[, int|null $level = null ][, string|array<string|int, mixed>|null $category = null ]) : void

Use addLogger() instead

Parameters
$logger : callable|LogSinkInterface
$level : int|null = null

filter by level

$category : string|array<string|int, mixed>|null = null

filter by category

execute()

Shorthand for creating, validating and running a job.

public static execute([array<string|int, mixed> $config = [] ]) : static
Parameters
$config : array<string|int, mixed> = []
Return values
static

getId()

A unique identifier.

public getId() : string
Tags
inheritdoc
Return values
string

log()

Log something.

public log(mixed $message[, int $level = null ][, string|null $category = null ][, float|null $timestamp = null ]) : void
Parameters
$message : mixed
$level : int = null

default: LEVEL_INFO

$category : string|null = null

default: class name (static)

$timestamp : float|null = null

default: now

rules()

public rules([string|null $scenario = null ]) : array<string|int, mixed>
Parameters
$scenario : string|null = null
Tags
inheritdoc
Return values
array<string|int, mixed>

stats()

Get the current stats.

public stats() : array<string|int, string>

This is automatically printed in execute().

Return values
array<string|int, string>

update()

Update the object with a new configuration.

public update(iterable<string|int, mixed> $config) : void
Parameters
$config : iterable<string|int, mixed>
Tags
inheritdoc

valid()

Validate this scenario (or default).

public valid([string|null $scenario = null ]) : array<string|int, mixed>|true
Parameters
$scenario : string|null = null

null for default.

Tags
throws
Exception
Return values
array<string|int, mixed>|true —

True if valid, errors array if invalid.

validate()

Validate this scenario (or default).

public validate([string|null $scenario = null ]) : void

This will throw if invalid or pass silently if valid.

Parameters
$scenario : string|null = null

null for default.

Tags
throws
Exception
ValidationException
On this page

Search results