Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 58 additions & 47 deletions src/Http/Middleware/InlineQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jorbascrumps\QueueIt\Http\Middleware;

use BadMethodCallException;
use Closure;
use Illuminate\Container\Container;
use Illuminate\Http\Request;
Expand All @@ -11,8 +12,26 @@
use QueueIT\KnownUserV3\SDK\KnownUser;
use QueueIT\KnownUserV3\SDK\KnownUserException;
use QueueIT\KnownUserV3\SDK\QueueEventConfig;
use ReflectionClass;
use Stringable;

/**
* @method static self eventId(string $eventId)
* @method static self queueDomain(string $queueDomain)
* @method static self cookieDomain(string $cookieDomain)
* @method static self cookieValidityMinute(int $cookieValidityMinute)
* @method static self extendCookieValidity(bool $extendCookieValidity)
* @method static self culture(string $culture)
* @method static self layoutName(string $layoutName)
*
* @method self eventId(string $eventId)
* @method self queueDomain(string $queueDomain)
* @method self cookieDomain(string $cookieDomain)
* @method self cookieValidityMinute(int $cookieValidityMinute)
* @method self extendCookieValidity(bool $extendCookieValidity)
* @method self culture(string $culture)
* @method self layoutName(string $layoutName)
*/
class InlineQueue implements Stringable
{
public const ALIAS = 'queue-it.inline-queue';
Expand Down Expand Up @@ -119,53 +138,6 @@ public function handle(Request $request, Closure $next, ...$eventConfigParams)
return $next($request);
}

public static function eventId(string $eventId): self
{
return new self($eventId);
}

public function cookieDomain($cookieDomain): self
{
$this->cookieDomain = $cookieDomain;

return $this;
}

public function cookieValidityMinute($cookieValidityMinute): self
{
$this->cookieValidityMinute = $cookieValidityMinute;

return $this;
}

public function culture($culture): self
{
$this->culture = $culture;

return $this;
}

public function extendCookieValidity($extendCookieValidity): self
{
$this->extendCookieValidity = $extendCookieValidity;

return $this;
}

public function layoutName($layoutName): self
{
$this->layoutName = $layoutName;

return $this;
}

public function queueDomain($queueDomain): self
{
$this->queueDomain = $queueDomain;

return $this;
}

private function getEventConfig(
string $eventId = '',
string $queueDomain = '',
Expand Down Expand Up @@ -213,4 +185,43 @@ public function __toString(): string

return self::ALIAS . ':' . $params;
}

protected function setParameter(string $name, $value): self
{
$this->$name = $value;

return $this;
}

public static function __callStatic($name, $arguments)
{
if (self::isValidParameter($name)) {
return (new self)->setParameter($name, $arguments[0]);
}

throw new BadMethodCallException("Parameter $name does not exist.");
}

public function __call($name, $arguments)
{
if (self::isValidParameter($name)) {
return $this->setParameter($name, $arguments[0]);
}

throw new BadMethodCallException("Parameter $name does not exist.");
}

private static function isValidParameter(string $name): bool
{
static $params = null;

if ($params === null) {
$reflectionClass = new ReflectionClass(self::class);
$reflectionConstructor = $reflectionClass->getConstructor();
$params = collect($reflectionConstructor->getParameters())
->pluck('name');
}

return $params->contains($name);
}
}