2019-05-09 18:54:39 +12:00
|
|
|
<?php
|
|
|
|
|
2020-03-25 06:56:32 +13:00
|
|
|
namespace Appwrite\Event;
|
2019-05-09 18:54:39 +12:00
|
|
|
|
|
|
|
use Resque;
|
|
|
|
|
|
|
|
class Event
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $queue = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $class = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $params = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event constructor.
|
2019-09-07 05:04:26 +12:00
|
|
|
*
|
2019-05-09 18:54:39 +12:00
|
|
|
* @param string $queue
|
|
|
|
* @param string $class
|
|
|
|
*/
|
2020-07-05 01:06:23 +12:00
|
|
|
public function __construct(string $queue, string $class)
|
2019-05-09 18:54:39 +12:00
|
|
|
{
|
|
|
|
$this->queue = $queue;
|
|
|
|
$this->class = $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $key
|
2019-09-07 05:04:26 +12:00
|
|
|
* @param mixed $value
|
|
|
|
*
|
2019-05-09 18:54:39 +12:00
|
|
|
* @return $this
|
|
|
|
*/
|
2020-07-05 01:06:23 +12:00
|
|
|
public function setParam(string $key, $value): self
|
2019-05-09 18:54:39 +12:00
|
|
|
{
|
|
|
|
$this->params[$key] = $value;
|
2019-09-07 05:04:26 +12:00
|
|
|
|
2019-05-09 18:54:39 +12:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $key
|
2019-09-07 05:04:26 +12:00
|
|
|
*
|
2019-05-09 18:54:39 +12:00
|
|
|
* @return mixed|null
|
|
|
|
*/
|
2020-07-05 01:06:23 +12:00
|
|
|
public function getParam(string $key)
|
2019-05-09 18:54:39 +12:00
|
|
|
{
|
|
|
|
return (isset($this->params[$key])) ? $this->params[$key] : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-09-07 05:04:26 +12:00
|
|
|
* Execute Event.
|
2019-05-09 18:54:39 +12:00
|
|
|
*/
|
2020-07-05 01:06:23 +12:00
|
|
|
public function trigger(): void
|
2019-05-09 18:54:39 +12:00
|
|
|
{
|
|
|
|
Resque::enqueue($this->queue, $this->class, $this->params);
|
2020-07-05 01:06:23 +12:00
|
|
|
|
|
|
|
$this->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function reset(): self
|
|
|
|
{
|
|
|
|
$this->params = [];
|
|
|
|
|
|
|
|
return $this;
|
2019-05-09 18:54:39 +12:00
|
|
|
}
|
2019-09-07 05:04:26 +12:00
|
|
|
}
|