PHP Class Toplan\PhpSms\Sms

Show file Open project: toplan/phpsms Class Usage Examples

Protected Properties

Property Type Description
$_status_before_enqueue_ array Status container, store some configuration information before serialize current instance(before enqueue).
$agents array The instances of Agent.
$agentsConfig array The configuration information of agents.
$availableHooks array The available hooks for balancing task.
$enableQueue boolean Whether to use the queue.
$firstAgent string | null The name of first agent.
$howToUseQueue Closure How to use the queue.
$pushedToQueue boolean Whether the current instance has already pushed to the queue system.
$scheme array example: [ 'Agent1' => '10 backup', 'Agent2' => '20 backup', ]
$serializer SuperClosure\Serializer An instance of class [SuperClosure\Serializer] for serialize closure objects.
$smsData array The data container of SMS/voice verify.

Public Methods

Method Description
__call ( string $name, array $args ) Overload method.
__callStatic ( string $name, array $args ) Overload static method.
__construct ( boolean $autoBoot = true ) Constructor
__sleep ( ) : array Serialize magic method.
__wakeup ( ) Deserialize magic method.
agent ( string $name ) Set the first agent by name.
bootstrap ( ) Boot balancing task for send SMS/voice verify.
cleanConfig ( ) Tear down all the configuration information of agent.
cleanScheme ( ) Tear down agent use scheme and prepare to create and start a new balancing task, so before do it must destroy old task instance.
config ( mixed $name = null, mixed $config = null, boolean $override = false ) : array Set or get configuration information by agent name.
content ( string $content ) Set the content for content SMS.
data ( array $data ) Set the template data for template SMS.
getAgent ( string $name ) : mixed Get a sms agent instance by agent name, if null, will try to create a new agent instance.
getData ( null | string $name = null ) : mixed Get all the data of SMS/voice verify.
getTask ( ) : Toplan\TaskBalance\Task Get or generate a balancing task instance for send SMS/voice verify.
hasAgent ( string $name ) : boolean Whether to has specified agent.
make ( mixed $agentName = null, mixed $tempId = null ) : Sms Create a sms instance send SMS, your can also set SMS templates or content at the same time.
push ( ) : mixed Push to the queue by a custom method.
queue ( mixed $enable = null, mixed $handler = null ) : boolean Set whether to use the queue system, and define how to use it.
scheme ( mixed $name = null, mixed $scheme = null ) : mixed Set or get the dispatch scheme of agent by name.
send ( boolean $immediately = false ) : mixed Start send SMS/voice verify.
template ( mixed $name, mixed $tempId = null ) Set the template id for template SMS.
to ( string $mobile ) Set the recipient`s mobile number.
voice ( integer | string | null $code = null ) : Sms Create a sms instance send voice verify, your can also set verify code at the same time.

Protected Methods

Method Description
configuration ( ) Configuration.
getSerializer ( ) : SuperClosure\Serializer Get a closure serializer.
initAgentsConfig ( array $agents, array &$config ) Try to initialize the specified agents` configuration information.
initScheme ( array &$config ) Try to read the dispatch scheme of agent from config file.
initTask ( ) Initialize the task.
modifyConfig ( string $key, array $value ) Modify the configuration information of agent by name.
modifyScheme ( $key, $value ) Modify the dispatch scheme of agent by name.
parseScheme ( array $options ) : array Parsing the dispatch scheme.
reinstallHandlers ( array $handlers ) Reinstall hooks` handlers for balancing task.
serializeHandlers ( ) : array Serialize the hooks` handlers of balancing task
serializeOrDeserializeClosureAndReplace ( array &$options, integer | string $key ) Serialize/deserialize the specified closure and replace the origin value.
serializeOrDeserializeScheme ( array $scheme ) : array Serialize or deserialize the agent use scheme.
taskInitialized ( ) : boolean Whether task initialized.
validateAgentName ( string $name ) Validate the agent name.
validateConfig ( ) validate configuration.

Method Details

__call() public method

Overload method.
public __call ( string $name, array $args )
$name string
$args array

__callStatic() public static method

Overload static method.
public static __callStatic ( string $name, array $args )
$name string
$args array

__construct() public method

Constructor
public __construct ( boolean $autoBoot = true )
$autoBoot boolean

__sleep() public method

Serialize magic method.
public __sleep ( ) : array
return array

__wakeup() public method

Deserialize magic method.
public __wakeup ( )

agent() public method

Set the first agent by name.
public agent ( string $name )
$name string

bootstrap() public static method

Boot balancing task for send SMS/voice verify.
public static bootstrap ( )

cleanConfig() public static method

Tear down all the configuration information of agent.
public static cleanConfig ( )

cleanScheme() public static method

Tear down agent use scheme and prepare to create and start a new balancing task, so before do it must destroy old task instance.
public static cleanScheme ( )

config() public static method

Set or get configuration information by agent name.
public static config ( mixed $name = null, mixed $config = null, boolean $override = false ) : array
$name mixed
$config mixed
$override boolean
return array

configuration() protected static method

Configuration.
protected static configuration ( )

content() public method

Set the content for content SMS.
public content ( string $content )
$content string

data() public method

Set the template data for template SMS.
public data ( array $data )
$data array

getAgent() public static method

Get a sms agent instance by agent name, if null, will try to create a new agent instance.
public static getAgent ( string $name ) : mixed
$name string
return mixed

getData() public method

Get all the data of SMS/voice verify.
public getData ( null | string $name = null ) : mixed
$name null | string
return mixed

getSerializer() protected static method

Get a closure serializer.
protected static getSerializer ( ) : SuperClosure\Serializer
return SuperClosure\Serializer

getTask() public static method

Get or generate a balancing task instance for send SMS/voice verify.
public static getTask ( ) : Toplan\TaskBalance\Task
return Toplan\TaskBalance\Task

hasAgent() public static method

Whether to has specified agent.
public static hasAgent ( string $name ) : boolean
$name string
return boolean

initAgentsConfig() protected static method

Try to initialize the specified agents` configuration information.
protected static initAgentsConfig ( array $agents, array &$config )
$agents array
$config array

initScheme() protected static method

Try to read the dispatch scheme of agent from config file.
protected static initScheme ( array &$config )
$config array

initTask() protected static method

Initialize the task.
protected static initTask ( )

make() public static method

Create a sms instance send SMS, your can also set SMS templates or content at the same time.
public static make ( mixed $agentName = null, mixed $tempId = null ) : Sms
$agentName mixed
$tempId mixed
return Sms

modifyConfig() protected static method

Modify the configuration information of agent by name.
protected static modifyConfig ( string $key, array $value )
$key string
$value array

modifyScheme() protected static method

Modify the dispatch scheme of agent by name.
protected static modifyScheme ( $key, $value )
$key
$value

parseScheme() protected static method

解析代理器的数组模式的调度配置
protected static parseScheme ( array $options ) : array
$options array
return array

push() public method

Push to the queue by a custom method.
public push ( ) : mixed
return mixed

queue() public static method

Set whether to use the queue system, and define how to use it.
public static queue ( mixed $enable = null, mixed $handler = null ) : boolean
$enable mixed
$handler mixed
return boolean

reinstallHandlers() protected static method

Reinstall hooks` handlers for balancing task.
protected static reinstallHandlers ( array $handlers )
$handlers array

scheme() public static method

Set or get the dispatch scheme of agent by name.
public static scheme ( mixed $name = null, mixed $scheme = null ) : mixed
$name mixed
$scheme mixed
return mixed

send() public method

If give a true parameter, this system will immediately start request to send SMS/voice verify whatever whether to use the queue. if you are already pushed sms instance to the queue, you can recall the method send() in queue system without true parameter, so this mechanism in order to make you convenient use the method send() in queue system.
public send ( boolean $immediately = false ) : mixed
$immediately boolean
return mixed

serializeHandlers() protected static method

Serialize the hooks` handlers of balancing task
protected static serializeHandlers ( ) : array
return array

serializeOrDeserializeClosureAndReplace() protected static method

Serialize/deserialize the specified closure and replace the origin value.
protected static serializeOrDeserializeClosureAndReplace ( array &$options, integer | string $key )
$options array
$key integer | string

serializeOrDeserializeScheme() protected static method

Serialize or deserialize the agent use scheme.
protected static serializeOrDeserializeScheme ( array $scheme ) : array
$scheme array
return array

taskInitialized() protected static method

Note: 判断drivers是否为空不能用'empty',因为在TaskBalance库的中Task类的drivers属性是受保护的(不可访问), 虽然通过魔术方法可以获取到其值,但在其目前版本(v0.4.2)其内部却并没有使用'__isset'魔术方法对'empty'或'isset'函数进行逻辑补救.
protected static taskInitialized ( ) : boolean
return boolean

template() public method

Set the template id for template SMS.
public template ( mixed $name, mixed $tempId = null )
$name mixed
$tempId mixed

to() public method

Set the recipient`s mobile number.
public to ( string $mobile )
$mobile string

validateAgentName() protected static method

Agent name must be a string, but not be a number string
protected static validateAgentName ( string $name )
$name string

validateConfig() protected static method

validate configuration.
protected static validateConfig ( )

voice() public static method

Create a sms instance send voice verify, your can also set verify code at the same time.
public static voice ( integer | string | null $code = null ) : Sms
$code integer | string | null
return Sms

Property Details

$_status_before_enqueue_ protected property

Status container, store some configuration information before serialize current instance(before enqueue).
protected array $_status_before_enqueue_
return array

$agents protected static property

The instances of Agent.
protected static array $agents
return array

$agentsConfig protected static property

The configuration information of agents.
protected static array $agentsConfig
return array

$availableHooks protected static property

The available hooks for balancing task.
protected static array $availableHooks
return array

$enableQueue protected static property

Whether to use the queue.
protected static bool $enableQueue
return boolean

$firstAgent protected property

The name of first agent.
protected string|null $firstAgent
return string | null

$howToUseQueue protected static property

How to use the queue.
protected static Closure $howToUseQueue
return Closure

$pushedToQueue protected property

Whether the current instance has already pushed to the queue system.
protected bool $pushedToQueue
return boolean

$scheme protected static property

example: [ 'Agent1' => '10 backup', 'Agent2' => '20 backup', ]
protected static array $scheme
return array

$serializer protected static property

An instance of class [SuperClosure\Serializer] for serialize closure objects.
protected static Serializer,SuperClosure $serializer
return SuperClosure\Serializer

$smsData protected property

The data container of SMS/voice verify.
protected array $smsData
return array