public function __construct($value) { if (filter_var($value, FILTER_VALIDATE_URL) === false) { throw new \InvalidArgumentException('Invalid url format.'); } parent::__construct($value); }
public static function get($native, $type = self::STRING) { switch ($type) { case self::FILEPATH: return Filepath::fromNative($native); break; case self::STRING: return StringLiteral::fromNative($native); break; case self::URL: return Url::fromNative($native); break; default: $oReflection = new \ReflectionObject(new self()); $allowedTypes = array_keys($oReflection->getConstants()); throw new InvalidNativeArgumentException($type, $allowedTypes); break; } }