fix: event class
This commit is contained in:
parent
0f89e28116
commit
7dc5d0e2be
2 changed files with 53 additions and 10 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Resque;
|
use Resque;
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
|
@ -98,6 +97,12 @@ class Event
|
||||||
return $this->event;
|
return $this->event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set project for this event.
|
||||||
|
*
|
||||||
|
* @param Document $project
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
public function setProject(Document $project): self
|
public function setProject(Document $project): self
|
||||||
{
|
{
|
||||||
$this->project = $project;
|
$this->project = $project;
|
||||||
|
@ -105,11 +110,22 @@ class Event
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get project for this event.
|
||||||
|
*
|
||||||
|
* @return Document
|
||||||
|
*/
|
||||||
public function getProject(): Document
|
public function getProject(): Document
|
||||||
{
|
{
|
||||||
return $this->project;
|
return $this->project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set user for this event.
|
||||||
|
*
|
||||||
|
* @param Document $user
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
public function setUser(Document $user): self
|
public function setUser(Document $user): self
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
@ -117,11 +133,22 @@ class Event
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get project for this event.
|
||||||
|
*
|
||||||
|
* @return Document
|
||||||
|
*/
|
||||||
public function getUser(): Document
|
public function getUser(): Document
|
||||||
{
|
{
|
||||||
return $this->user;
|
return $this->user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set payload for this event.
|
||||||
|
*
|
||||||
|
* @param Document $payload
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
public function setPayload(array $payload): self
|
public function setPayload(array $payload): self
|
||||||
{
|
{
|
||||||
$this->payload = $payload;
|
$this->payload = $payload;
|
||||||
|
@ -129,11 +156,22 @@ class Event
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get payload for this event.
|
||||||
|
*
|
||||||
|
* @return Document
|
||||||
|
*/
|
||||||
public function getPayload(): array
|
public function getPayload(): array
|
||||||
{
|
{
|
||||||
return $this->payload;
|
return $this->payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set context for this event.
|
||||||
|
*
|
||||||
|
* @param Document $context
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
public function setContext(Document $context): self
|
public function setContext(Document $context): self
|
||||||
{
|
{
|
||||||
$this->context = $context;
|
$this->context = $context;
|
||||||
|
@ -141,6 +179,11 @@ class Event
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get context for this event.
|
||||||
|
*
|
||||||
|
* @return Document
|
||||||
|
*/
|
||||||
public function getContext(): ?Document
|
public function getContext(): ?Document
|
||||||
{
|
{
|
||||||
return $this->context;
|
return $this->context;
|
||||||
|
@ -149,7 +192,7 @@ class Event
|
||||||
/**
|
/**
|
||||||
* Set class used for this event.
|
* Set class used for this event.
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @return Event
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setClass(string $class): self
|
public function setClass(string $class): self
|
||||||
{
|
{
|
||||||
|
@ -173,7 +216,7 @@ class Event
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return Event
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setParam(string $key, mixed $value): self
|
public function setParam(string $key, mixed $value): self
|
||||||
{
|
{
|
||||||
|
@ -223,7 +266,7 @@ class Event
|
||||||
/**
|
/**
|
||||||
* Resets event.
|
* Resets event.
|
||||||
*
|
*
|
||||||
* @return Event
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function reset(): self
|
public function reset(): self
|
||||||
{
|
{
|
||||||
|
@ -244,7 +287,7 @@ class Event
|
||||||
$count = \count($parts);
|
$count = \count($parts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identify all sestions of the pattern.
|
* Identify all sections of the pattern.
|
||||||
*/
|
*/
|
||||||
$type = $parts[0] ?? false;
|
$type = $parts[0] ?? false;
|
||||||
$resource = $parts[1] ?? false;
|
$resource = $parts[1] ?? false;
|
||||||
|
@ -291,7 +334,7 @@ class Event
|
||||||
*/
|
*/
|
||||||
static function generateEvents(string $pattern, array $params = []): array
|
static function generateEvents(string $pattern, array $params = []): array
|
||||||
{
|
{
|
||||||
$params = \array_filter($params, fn($param) => !\is_array($param));
|
// $params = \array_filter($params, fn($param) => !\is_array($param));
|
||||||
$paramKeys = \array_keys($params);
|
$paramKeys = \array_keys($params);
|
||||||
$paramValues = \array_values($params);
|
$paramValues = \array_values($params);
|
||||||
|
|
||||||
|
|
|
@ -73,11 +73,11 @@ class Event extends Validator
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($subtype ?? false) {
|
if ($subType) {
|
||||||
if ($action && !\array_key_exists($action, $events[$type][$subType])) {
|
if ($action && !\array_key_exists($action, $events[$type][$subType])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!($subResource ?? false) || !\array_key_exists($subType, $events[$type])) {
|
if (!($subResource) || !\array_key_exists($subType, $events[$type])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,8 +86,8 @@ class Event extends Validator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($attribute ?? false) {
|
if ($attribute) {
|
||||||
if (($subType ?? false)) {
|
if (($subType)) {
|
||||||
if (!\array_key_exists($attribute, $events[$type][$subType][$action])) {
|
if (!\array_key_exists($attribute, $events[$type][$subType][$action])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue