PHP Класс WpGears\Plugin

When run in Client mode it will allow adding new jobs to the Queue. When run in worker mode it will execute jobs on the Queue. Worker mode also allows adding new jobs to the queue just like Mlient mode.
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$client The Client object used to enqueue jobs
$client_class client class
$config_prefix Configuration constants are prefixed by WP_GEARS by default. ;w Eg:- WP_GEARS_JOBS_PER_WORKER
$did_enable *
$did_run *
$instance Single instance of the plugin
$jobs_per_worker Number of jobs to execute per worker, Default 1
$worker The Worker object used to execute jobs
$worker_class Custom worker class

Открытые методы

Метод Описание
add ( string $hook, array $args = [], string $priority = 'normal' ) : boolean Adds a new job to the Client with the specified arguments and priority.
build_client ( ) : Client Conditionally builds a new Client object. If the constant WP_GEARS_CLIENT_CLASS is defined it will return an instance of that class.
build_worker ( ) : Worker Conditionally builds a new Worker object. If the constant WP_GEARS_WORKER_CLASS is defined it will return an instance of that class.
enable ( ) Enables the plugin by registering it's clients and workers.
get_client ( ) : Client Returns the Client object used to add jobs. Creates the instance of the client lazily.
get_config ( string $constant, string $default = '', string $config_prefix = '' ) : mixed Helper to pickup config options from Constants with fallbacks.
get_instance ( ) : Plugin Returns the singleton instance of the Plugin. Creates the instance if it is absent.
get_jobs_per_worker ( ) : integer Returns the jobs to execute per worker instance
get_worker ( ) Returns the Worker object used to execute jobs. Creates the instance of the worker lazily.
get_wp_load ( ) : string Returns the path to the wp-load.php file.
has_config ( string $constant ) : boolean Checks if a config option is defined. Empty strings are treated as an undefined config option.
load_wordpress ( ) Tries to load WordPress using wp-load.php. If loading fails an error message is logged and the Script will exit immediately with a status code of 1.
quit ( integer $status_code ) Helper to quit with a status code. When running under PHPUnit it returns the status_code instead of exiting immediately.
run ( ) : integer Starts processing jobs in the Worker.
work ( ) : integer Executes jobs on the current Worker. A Worker will taken up only one job by default. If WP_GEARS_JOBS_PER_WORKER is defined that many jobs will be executed before it exits.

Описание методов

add() публичный Метод

Adds a new job to the Client with the specified arguments and priority.
public add ( string $hook, array $args = [], string $priority = 'normal' ) : boolean
$hook string The action hook name for the job
$args array Optional arguments for the job
$priority string Optional priority of the job
Результат boolean true or false depending on the Client

build_client() публичный Метод

By default it will detect if Gearman is present and return the Gearman Client else fallback to the Cron Client.
public build_client ( ) : Client
Результат Client New instance of the Client

build_worker() публичный Метод

By default it will detect if Gearman is present and return the Gearman Worker else fallback to the Cron Worker.
public build_worker ( ) : Worker
Результат Worker New instance of the Worker

enable() публичный Метод

Ignored if already enabled
public enable ( )

get_client() публичный Метод

Returns the Client object used to add jobs. Creates the instance of the client lazily.
public get_client ( ) : Client
Результат Client The client instance

get_config() публичный Метод

Order of lookup is, 1. Local Property 2. Constant of that name 3. Default specified Eg:- get_config( 'FOO', 'abc', 'MY' ) will look for, 1. Local Property $this->my_foo 2. Constant MY_FOO 3. Defaualt ie:- abc
public get_config ( string $constant, string $default = '', string $config_prefix = '' ) : mixed
$constant string Name of constant to lookup
$default string Optional default
$config_prefix string Optional config prefix, Default is WP_GEARS
Результат mixed The value of the config

get_instance() публичный статический Метод

Returns the singleton instance of the Plugin. Creates the instance if it is absent.
public static get_instance ( ) : Plugin
Результат Plugin instance of Plugin

get_jobs_per_worker() публичный Метод

Returns the jobs to execute per worker instance
public get_jobs_per_worker ( ) : integer
Результат integer Defaults to 1

get_worker() публичный Метод

Returns the Worker object used to execute jobs. Creates the instance of the worker lazily.
public get_worker ( )

get_wp_load() публичный Метод

Returns the path to the wp-load.php file.
public get_wp_load ( ) : string
Результат string Path to the wp-load.php file

has_config() публичный Метод

Checks if a config option is defined. Empty strings are treated as an undefined config option.
public has_config ( string $constant ) : boolean
$constant string The name of the constant
Результат boolean True or false depending on whether the config is present

load_wordpress() публичный Метод

Tries to load WordPress using wp-load.php. If loading fails an error message is logged and the Script will exit immediately with a status code of 1.
public load_wordpress ( )

quit() публичный Метод

Helper to quit with a status code. When running under PHPUnit it returns the status_code instead of exiting immediately.
public quit ( integer $status_code )
$status_code integer The status between 0-255 to quit with.

run() публичный Метод

Only one run is permitted.
public run ( ) : integer
Результат integer The exit status code (only for PHPUnit)

work() публичный Метод

This method will exit with the result code based on success/failure of executing the job.
public work ( ) : integer
Результат integer 0 for success and 1 for failure

Описание свойств

$client публичное свойство

The Client object used to enqueue jobs
public $client

$client_class публичное свойство

client class
public $client_class

$config_prefix публичное свойство

Configuration constants are prefixed by WP_GEARS by default. ;w Eg:- WP_GEARS_JOBS_PER_WORKER
public $config_prefix

$did_enable публичное свойство

*
public $did_enable

$did_run публичное свойство

*
public $did_run

$instance публичное статическое свойство

Single instance of the plugin
public static $instance

$jobs_per_worker публичное свойство

Number of jobs to execute per worker, Default 1
public $jobs_per_worker

$worker публичное свойство

The Worker object used to execute jobs
public $worker

$worker_class публичное свойство

Custom worker class
public $worker_class