diff --git a/composer.json b/composer.json index 6ee985a..c39c926 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "kwaadpepper/enum", "description": "Enums to use for any project", "license": "MIT", + "version": "2.0.0", "authors": [ { "name": "Jérémy Munsch", diff --git a/src/BaseEnum.php b/src/BaseEnum.php index a6e673f..7c6f1f5 100644 --- a/src/BaseEnum.php +++ b/src/BaseEnum.php @@ -4,16 +4,14 @@ namespace Kwaadpepper\Enum; use BadMethodCallException; use Closure; -use Illuminate\Contracts\Routing\UrlRoutable; use JsonSerializable; use Kwaadpepper\Enum\Exceptions\DuplicateLabelsException; use Kwaadpepper\Enum\Exceptions\DuplicateValuesException; -use Kwaadpepper\Enum\Exceptions\NotImplementedException; use Kwaadpepper\Enum\Exceptions\UnknownEnumProperty; use ReflectionClass; use TypeError; -abstract class BaseEnum implements JsonSerializable, UrlRoutable +abstract class BaseEnum implements JsonSerializable { /** * @var string|int @@ -278,63 +276,6 @@ abstract class BaseEnum implements JsonSerializable, UrlRoutable return (string) $this->value; } - /** - * Get the value of the model's route key. - * - * @return mixed - */ - public function getRouteKey() - { - return $this->value; - } - - /** - * Get the route key for the model. - * - * @return string - */ - public function getRouteKeyName() - { - throw new NotImplementedException('getRouteKeyName not implemented, should not be used'); - } - - /** - * Retrieve the model for a bound value. - * - * @param mixed $value - * @param string|null $field - * @return \Illuminate\Database\Eloquent\Model|null - */ - public function resolveRouteBinding($value, $field = null) - { - // try to cast numeric value first - try { - return static::make(is_numeric($value) ? intval($value) : $value); - } catch (BadMethodCallException $e) { - } - // try string value after that - try { - return static::make($value); - } catch (BadMethodCallException $e) { - } - // could not find a suitable value - return null; - } - - /** - * Retrieve the child model for a bound value. - * - * @param string $childType - * @param mixed $value - * @param string|null $field - * @return \Illuminate\Database\Eloquent\Model|null - * @throws NotImplementedException - */ - public function resolveChildRouteBinding($childType, $value, $field) - { - throw new NotImplementedException('resolveChildRouteBinding not implemented, should not be used'); - } - /** * Get the Enum name from class name * diff --git a/src/BaseEnumRoutable.php b/src/BaseEnumRoutable.php new file mode 100644 index 0000000..a4ea8a2 --- /dev/null +++ b/src/BaseEnumRoutable.php @@ -0,0 +1,78 @@ +value; + } + + /** + * Get the route key for the model. + * + * @return string + */ + public function getRouteKeyName() + { + throw new NotImplementedException('getRouteKeyName not implemented, should not be used'); + } + + /** + * Retrieve the model for a bound value. + * + * @param mixed $value + * @param string|null $field + * @return \Illuminate\Database\Eloquent\Model|null + */ + public function resolveRouteBinding($value, $field = null) + { + // try to cast numeric value first + try { + return static::make(is_numeric($value) ? intval($value) : $value); + } catch (BadMethodCallException $e) { + } + // try string value after that + try { + return static::make($value); + } catch (BadMethodCallException $e) { + } + // could not find a suitable value + return null; + } + + /** + * Retrieve the child model for a bound value. + * + * @param string $childType + * @param mixed $value + * @param string|null $field + * @return \Illuminate\Database\Eloquent\Model|null + * @throws NotImplementedException + */ + public function resolveChildRouteBinding($childType, $value, $field) + { + throw new NotImplementedException('resolveChildRouteBinding not implemented, should not be used'); + } + + /** + * Get the Enum name from class name + * + * @return string + */ + public static function getEnumName() + { + $cls = explode('\\', static::class); + return array_pop($cls); + } +}