mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-08 16:23:12 +08:00
Support dynamic redirects based on an after-date condition
This commit is contained in:
@@ -82,6 +82,11 @@ class RedirectCondition extends AbstractEntity implements JsonSerializable
|
||||
return new self(RedirectConditionType::BEFORE_DATE, $date->toAtomString());
|
||||
}
|
||||
|
||||
public static function forAfterDate(Chronos $date): self
|
||||
{
|
||||
return new self(RedirectConditionType::AFTER_DATE, $date->toAtomString());
|
||||
}
|
||||
|
||||
public static function fromRawData(array $rawData): self
|
||||
{
|
||||
$type = RedirectConditionType::from($rawData[RedirectRulesInputFilter::CONDITION_TYPE]);
|
||||
@@ -108,6 +113,7 @@ class RedirectCondition extends AbstractEntity implements JsonSerializable
|
||||
RedirectConditionType::GEOLOCATION_COUNTRY_CODE => self::forGeolocationCountryCode($cond->matchValue),
|
||||
RedirectConditionType::GEOLOCATION_CITY_NAME => self::forGeolocationCityName($cond->matchValue),
|
||||
RedirectConditionType::BEFORE_DATE => self::forBeforeDate(normalizeDate($cond->matchValue)),
|
||||
RedirectConditionType::AFTER_DATE => self::forAfterDate(normalizeDate($cond->matchValue)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -126,6 +132,7 @@ class RedirectCondition extends AbstractEntity implements JsonSerializable
|
||||
RedirectConditionType::GEOLOCATION_COUNTRY_CODE => $this->matchesGeolocationCountryCode($request),
|
||||
RedirectConditionType::GEOLOCATION_CITY_NAME => $this->matchesGeolocationCityName($request),
|
||||
RedirectConditionType::BEFORE_DATE => $this->matchesBeforeDate(),
|
||||
RedirectConditionType::AFTER_DATE => $this->matchesAfterDate(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -214,6 +221,11 @@ class RedirectCondition extends AbstractEntity implements JsonSerializable
|
||||
return Chronos::now()->lessThan(Chronos::parse($this->matchValue));
|
||||
}
|
||||
|
||||
private function matchesAfterDate(): bool
|
||||
{
|
||||
return Chronos::now()->greaterThan(Chronos::parse($this->matchValue));
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
@@ -244,7 +256,8 @@ class RedirectCondition extends AbstractEntity implements JsonSerializable
|
||||
RedirectConditionType::IP_ADDRESS => sprintf('IP address matches %s', $this->matchValue),
|
||||
RedirectConditionType::GEOLOCATION_COUNTRY_CODE => sprintf('country code is %s', $this->matchValue),
|
||||
RedirectConditionType::GEOLOCATION_CITY_NAME => sprintf('city name is %s', $this->matchValue),
|
||||
RedirectConditionType::BEFORE_DATE => sprintf('date before %s', $this->matchValue),
|
||||
RedirectConditionType::BEFORE_DATE => sprintf('date is before %s', $this->matchValue),
|
||||
RedirectConditionType::AFTER_DATE => sprintf('date is after %s', $this->matchValue),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ enum RedirectConditionType: string
|
||||
case GEOLOCATION_COUNTRY_CODE = 'geolocation-country-code';
|
||||
case GEOLOCATION_CITY_NAME = 'geolocation-city-name';
|
||||
case BEFORE_DATE = 'before-date';
|
||||
case AFTER_DATE = 'after-date';
|
||||
|
||||
/**
|
||||
* Tells if a value is valid for the condition type
|
||||
|
||||
Reference in New Issue
Block a user