outcome = $outcome; $this->reason = $reason; $this->scheduled_for = $scheduled_for; $this->next_open = $next_open; $this->closure_label = $closure_label; } /** * Go ahead. * * @param string $reason Reason (default `open`). * @param int|null $next_open Next opening, when closed. * @param string $closure_label Closure label, when closed by one. * @return self */ public static function allowed( string $reason = self::REASON_OPEN, $next_open = null, string $closure_label = '' ) { return new self( self::ALLOWED, $reason, null, $next_open, $closure_label ); } /** * Reject. The message is added by `with_message()`. * * @param string $reason Reason. * @param int|null $next_open Next opening, or null when unknown. * @param string $closure_label Closure label. * @return self */ public static function blocked( string $reason, $next_open = null, string $closure_label = '' ) { return new self( self::BLOCKED, $reason, null, $next_open, $closure_label ); } /** * Accept for later. * * @param string $reason Reason. * @param int $scheduled_for When it can be fulfilled (UTC). * @param string $closure_label Closure label. * @return self */ public static function scheduled( string $reason, int $scheduled_for, string $closure_label = '' ) { return new self( self::SCHEDULED, $reason, $scheduled_for, $scheduled_for, $closure_label ); } /** * A copy with a plain-text message. * * @param string $message Message, tokens already replaced. * @return self */ public function with_message( string $message ) { $copy = clone $this; $copy->message = $message; return $copy; } /** * Whether to go ahead. * * @return bool */ public function is_allowed() { return self::ALLOWED === $this->outcome; } /** * Whether to reject. * * @return bool */ public function is_blocked() { return self::BLOCKED === $this->outcome; } /** * Whether to accept for later. * * @return bool */ public function is_scheduled() { return self::SCHEDULED === $this->outcome; } /** * Whether the store is closed to orders (paused, outside hours or a closure), whatever the outcome. * * @return bool */ public function is_closed() { return in_array( $this->reason, self::CLOSED_REASONS, true ); } /** * `allowed`, `blocked` or `scheduled`. * * @return string */ public function get_outcome() { return $this->outcome; } /** * One of the `REASON_*` constants. * * @return string */ public function get_reason() { return $this->reason; } /** * The plain-text message ('' when none). Escape it at output. * * @return string */ public function get_message() { return $this->message; } /** * When a scheduled order can be fulfilled (UTC), or null. * * @return int|null */ public function get_scheduled_for() { return $this->scheduled_for; } /** * When ordering is next possible (UTC), or null when unknown. * * @return int|null */ public function get_next_open() { return $this->next_open; } /** * The covering closure's label, or ''. * * @return string */ public function get_closure_label() { return $this->closure_label; } }