PHP Class Crunz\Event

Show file Open project: lavary/crunz Class Usage Examples

Public Properties

Property Type Description
$description string The human readable description of the event.
$output string The location that output should be sent to.
$outputStream string Event generated output
$preventOverlapping boolean Indicates if the command should not overlap itself.
$shouldAppendOutput boolean Indicates whether output should be appended.

Protected Properties

Property Type Description
$afterCallbacks array The array of callbacks to be run after the event is finished.
$beforeCallbacks array The array of callbacks to be run before the event is started.
$command string The command string.
$cwd string Current working directory
$expression string The cron expression representing the event's frequency.
$fieldsPosition array Position of cron fields
$filters array The array of filter callbacks.
$id string The event's unique identifier
$process Symfony\Component\Process\Process Process that runs the event
$rejects array The array of reject callbacks.
$timezone DateTimeZone | string The timezone the date should be evaluated on.
$user string The user the command should run as.

Public Methods

Method Description
__call ( string $methodName, array $params ) Handling dynamic frequency methods
__construct ( $id, string $command ) : void Create a new event instance.
after ( Closure $callback ) Register a callback to be called after the operation.
afterCallbacks ( ) : array Return all registered after callbacks
appendOutputTo ( string $location ) Append the output of the command to a given location.
at ( string $time ) Schedule the command at a given time.
before ( Closure $callback ) Register a callback to be called before the operation.
beforeCallbacks ( ) : array Return all registered before callbacks
between ( $from, $to ) Set Working period
buildCommand ( ) : string Build the comand string.
cron ( string $expression ) The Cron expression representing the event's frequency.
daily ( ) Schedule the event to run daily.
dailyAt ( string $time ) Schedule the event to run daily at a given time (10:00, 19:30, etc).
dayOfMonth ( mixed $value ) Set hour for the cron job
dayOfWeek ( mixed $value ) Set hour for the cron job
days ( mixed $days ) Set the days of the week the command should run on.
description ( string $description ) Set the human-friendly description of the event.
every ( string $unit = null, string $value = null ) Another way to the frequency of the cron job
filtersPass ( ) : boolean Determine if the filters pass for the event.
fridays ( ) Schedule the event to run only on Fridays.
from ( string $datetime ) Check if event should be on
getCommand ( ) : string Return the event's command
getCommandForDisplay ( ) : string Get the command for display
getExpression ( ) : string Get the Cron expression for the event.
getId ( ) : string Return the event's command
getOutputStream ( ) : string Return event's full output
getProcess ( ) : Process Return the event's process
getSummaryForDisplay ( ) : string Get the summary of the event for display.
getWorkingDirectory ( ) : string Return the current working directory
hour ( mixed $value ) Set hour for the cron job
hourly ( ) Schedule the event to run hourly.
in ( string $directory ) Change the current working directory.
isClosure ( ) : boolean Determine whether the passed value is a closure ot not.
isDue ( ) : boolean Determine if the given event should run based on the Cron expression.
isLocked ( ) : boolean Check if another instance of the event is still running
lastPid ( ) : integer Get the last process Id of the event
lockFile ( ) : string Get the lock file path for the task
minute ( mixed $value ) Set minute for the cron job
mondays ( ) Schedule the event to run only on Mondays.
month ( mixed $value ) Set hour for the cron job
monthly ( ) Schedule the event to run monthly.
name ( string $description ) Set the human-friendly description of the event.
nullOutput ( ) : boolean Determine if the event's output is sent to null.
on ( string $date ) Schedule the event to run on a certain date
pingBefore ( string $url ) Register a callback to ping a given URL before the job runs.
preventOverlapping ( ) Do not allow the event to overlap each other.
quarterly ( ) Schedule the event to run quarterly.
saturdays ( ) Schedule the event to run only on Saturdays.
sendOutputTo ( string $location, boolean $append = false ) Send the output of the command to a given location.
setCommand ( string $command ) Set the event's command
setProcess ( Process $process = null ) Set the event's process
skip ( Closure $callback ) Register a callback to further filter the schedule.
start ( ) : integer Start the event execution
sundays ( ) Schedule the event to run only on Sundays.
then ( Closure $callback ) Register a callback to be called after the operation.
thenPing ( string $url ) Register a callback to ping a given URL after the job runs.
thursdays ( ) Schedule the event to run only on Thursdays.
timezone ( DateTimeZone | string $timezone ) Set the timezone the date should be evaluated on.
to ( string $datetime ) Check if event should be off
tuesdays ( ) Schedule the event to run only on Tuesdays.
twiceDaily ( integer $first = 1, integer $second = 13 ) Schedule the event to run twice daily.
user ( string $user ) Set which user the command should run as.
wednesdays ( ) Schedule the event to run only on Wednesdays.
weekdays ( ) Schedule the event to run only on weekdays.
weekly ( ) Schedule the event to run weekly.
weeklyOn ( integer $day, string $time = '0:0' ) Schedule the event to run weekly on a given day and time.
when ( Closure $callback ) Register a callback to further filter the schedule.
yearly ( ) Schedule the event to run yearly.

Protected Methods

Method Description
applyMask ( string $unit ) : string Mask a cron expression
expressionPasses ( ) : boolean Determine if the Cron expression passes.
getDefaultOutput ( ) : string Get the default output depending on the OS.
lock ( ) : string Lock the event
notYet ( $datetime ) : boolean Check if time hasn't arrived
past ( $datetime ) : boolean Check if the time has passed
serializeClosure ( string $closure ) : string Convert closure to an executable command
spliceIntoPosition ( integer $position, string $value ) Splice the given value into the given position of the expression.
sudo ( string $user ) : string Add sudo to the command

Method Details

__call() public method

Handling dynamic frequency methods
public __call ( string $methodName, array $params )
$methodName string
$params array

__construct() public method

Create a new event instance.
public __construct ( $id, string $command ) : void
$command string
return void

after() public method

Register a callback to be called after the operation.
public after ( Closure $callback )
$callback Closure

afterCallbacks() public method

Return all registered after callbacks
public afterCallbacks ( ) : array
return array

appendOutputTo() public method

Append the output of the command to a given location.
public appendOutputTo ( string $location )
$location string

applyMask() protected method

Mask a cron expression
protected applyMask ( string $unit ) : string
$unit string
return string

at() public method

Schedule the command at a given time.
public at ( string $time )
$time string

before() public method

Register a callback to be called before the operation.
public before ( Closure $callback )
$callback Closure

beforeCallbacks() public method

Return all registered before callbacks
public beforeCallbacks ( ) : array
return array

between() public method

Set Working period
public between ( $from, $to )

buildCommand() public method

Build the comand string.
public buildCommand ( ) : string
return string

cron() public method

The Cron expression representing the event's frequency.
public cron ( string $expression )
$expression string

daily() public method

Schedule the event to run daily.
public daily ( )

dailyAt() public method

Schedule the event to run daily at a given time (10:00, 19:30, etc).
public dailyAt ( string $time )
$time string

dayOfMonth() public method

Set hour for the cron job
public dayOfMonth ( mixed $value )
$value mixed

dayOfWeek() public method

Set hour for the cron job
public dayOfWeek ( mixed $value )
$value mixed

days() public method

Set the days of the week the command should run on.
public days ( mixed $days )
$days mixed

description() public method

Set the human-friendly description of the event.
public description ( string $description )
$description string

every() public method

Another way to the frequency of the cron job
public every ( string $unit = null, string $value = null )
$unit string
$value string

expressionPasses() protected method

Determine if the Cron expression passes.
protected expressionPasses ( ) : boolean
return boolean

filtersPass() public method

Determine if the filters pass for the event.
public filtersPass ( ) : boolean
return boolean

fridays() public method

Schedule the event to run only on Fridays.
public fridays ( )

from() public method

Check if event should be on
public from ( string $datetime )
$datetime string

getCommand() public method

Return the event's command
public getCommand ( ) : string
return string

getCommandForDisplay() public method

Get the command for display
public getCommandForDisplay ( ) : string
return string

getDefaultOutput() protected method

Get the default output depending on the OS.
protected getDefaultOutput ( ) : string
return string

getExpression() public method

Get the Cron expression for the event.
public getExpression ( ) : string
return string

getId() public method

Return the event's command
public getId ( ) : string
return string

getOutputStream() public method

Return event's full output
public getOutputStream ( ) : string
return string

getProcess() public method

Return the event's process
public getProcess ( ) : Process
return Symfony\Component\Process\Process $process

getSummaryForDisplay() public method

Get the summary of the event for display.
public getSummaryForDisplay ( ) : string
return string

getWorkingDirectory() public method

Return the current working directory
public getWorkingDirectory ( ) : string
return string

hour() public method

Set hour for the cron job
public hour ( mixed $value )
$value mixed

hourly() public method

Schedule the event to run hourly.
public hourly ( )

in() public method

Change the current working directory.
public in ( string $directory )
$directory string

isClosure() public method

Determine whether the passed value is a closure ot not.
public isClosure ( ) : boolean
return boolean

isDue() public method

Determine if the given event should run based on the Cron expression.
public isDue ( ) : boolean
return boolean

isLocked() public method

Check if another instance of the event is still running
public isLocked ( ) : boolean
return boolean

lastPid() public method

Get the last process Id of the event
public lastPid ( ) : integer
return integer

lock() protected method

Lock the event
protected lock ( ) : string
return string

lockFile() public method

Get the lock file path for the task
public lockFile ( ) : string
return string

minute() public method

Set minute for the cron job
public minute ( mixed $value )
$value mixed

mondays() public method

Schedule the event to run only on Mondays.
public mondays ( )

month() public method

Set hour for the cron job
public month ( mixed $value )
$value mixed

monthly() public method

Schedule the event to run monthly.
public monthly ( )

name() public method

Set the human-friendly description of the event.
public name ( string $description )
$description string

notYet() protected method

Check if time hasn't arrived
protected notYet ( $datetime ) : boolean
return boolean

nullOutput() public method

Determine if the event's output is sent to null.
public nullOutput ( ) : boolean
return boolean

on() public method

Schedule the event to run on a certain date
public on ( string $date )
$date string

past() protected method

Check if the time has passed
protected past ( $datetime ) : boolean
return boolean

pingBefore() public method

Register a callback to ping a given URL before the job runs.
public pingBefore ( string $url )
$url string

preventOverlapping() public method

Do not allow the event to overlap each other.
public preventOverlapping ( )

quarterly() public method

Schedule the event to run quarterly.
public quarterly ( )

saturdays() public method

Schedule the event to run only on Saturdays.
public saturdays ( )

sendOutputTo() public method

Send the output of the command to a given location.
public sendOutputTo ( string $location, boolean $append = false )
$location string
$append boolean

serializeClosure() protected method

Convert closure to an executable command
protected serializeClosure ( string $closure ) : string
$closure string
return string

setCommand() public method

Set the event's command
public setCommand ( string $command )
$command string

setProcess() public method

Set the event's process
public setProcess ( Process $process = null )
$process Symfony\Component\Process\Process

skip() public method

Register a callback to further filter the schedule.
public skip ( Closure $callback )
$callback Closure

spliceIntoPosition() protected method

Splice the given value into the given position of the expression.
protected spliceIntoPosition ( integer $position, string $value )
$position integer
$value string

start() public method

Start the event execution
public start ( ) : integer
return integer

sudo() protected method

Add sudo to the command
protected sudo ( string $user ) : string
$user string
return string

sundays() public method

Schedule the event to run only on Sundays.
public sundays ( )

then() public method

Register a callback to be called after the operation.
public then ( Closure $callback )
$callback Closure

thenPing() public method

Register a callback to ping a given URL after the job runs.
public thenPing ( string $url )
$url string

thursdays() public method

Schedule the event to run only on Thursdays.
public thursdays ( )

timezone() public method

Set the timezone the date should be evaluated on.
public timezone ( DateTimeZone | string $timezone )
$timezone DateTimeZone | string

to() public method

Check if event should be off
public to ( string $datetime )
$datetime string

tuesdays() public method

Schedule the event to run only on Tuesdays.
public tuesdays ( )

twiceDaily() public method

Schedule the event to run twice daily.
public twiceDaily ( integer $first = 1, integer $second = 13 )
$first integer
$second integer

user() public method

Set which user the command should run as.
public user ( string $user )
$user string

wednesdays() public method

Schedule the event to run only on Wednesdays.
public wednesdays ( )

weekdays() public method

Schedule the event to run only on weekdays.
public weekdays ( )

weekly() public method

Schedule the event to run weekly.
public weekly ( )

weeklyOn() public method

Schedule the event to run weekly on a given day and time.
public weeklyOn ( integer $day, string $time = '0:0' )
$day integer
$time string

when() public method

Register a callback to further filter the schedule.
public when ( Closure $callback )
$callback Closure

yearly() public method

Schedule the event to run yearly.
public yearly ( )

Property Details

$afterCallbacks protected property

The array of callbacks to be run after the event is finished.
protected array $afterCallbacks
return array

$beforeCallbacks protected property

The array of callbacks to be run before the event is started.
protected array $beforeCallbacks
return array

$command protected property

The command string.
protected string $command
return string

$cwd protected property

Current working directory
protected string $cwd
return string

$description public property

The human readable description of the event.
public string $description
return string

$expression protected property

The cron expression representing the event's frequency.
protected string $expression
return string

$fieldsPosition protected property

Position of cron fields
protected array $fieldsPosition
return array

$filters protected property

The array of filter callbacks.
protected array $filters
return array

$id protected property

The event's unique identifier
protected string $id
return string

$output public property

The location that output should be sent to.
public string $output
return string

$outputStream public property

Event generated output
public string $outputStream
return string

$preventOverlapping public property

Indicates if the command should not overlap itself.
public bool $preventOverlapping
return boolean

$process protected property

Process that runs the event
protected Process,Symfony\Component\Process $process
return Symfony\Component\Process\Process

$rejects protected property

The array of reject callbacks.
protected array $rejects
return array

$shouldAppendOutput public property

Indicates whether output should be appended.
public bool $shouldAppendOutput
return boolean

$timezone protected property

The timezone the date should be evaluated on.
protected DateTimeZone|string $timezone
return DateTimeZone | string

$user protected property

The user the command should run as.
protected string $user
return string