xdevor / type
A Laravel package which object type collection powered by Laravel's validation components.
Requires
- php: ^7.4
Requires (Dev)
- orchestra/testbench: ^6.38
- pestphp/pest: ^1.23
This package is auto-updated.
Last update: 2024-10-11 09:58:05 UTC
README
In this package we've introduced a new type package that focuses on validating object types.
This package not only allows you to validate basic data types but also supports complex object structures. Using Laravel's fluent validation syntax, you can define the expected properties of an object to ensure their types and existence.
Installation
Require this package with composer:
composer require xdevor/type
Usage
- ❌ Without object type
function increase(int $count) { if ($count < 1) { throw new InvalidArgumentException('Receive invalid argument'); } return $this->value + $count; }
- ✅ With object type
use Xdevor\Type\Numbers\PositiveInt; function increase(PositiveInt $count) { return $this->value + $count->value(); }
Features
Supports
- PositiveInt: Positive integer
- NegativeInt: Negative integer
Todo
- NonZeroInt: Non-zero integer
- PositiveFloat: Positive floating-point number
- NegativeFloat: Negative floating-point number
- NonZeroFloat: Non-zero floating-point number
- NonEmptyString: Non-empty string
- EmailAddress: Email address
- Url: URL
- PhoneNumber: Phone number
- Date: Date
- DateTime: Date and time
- Uuid: Universally Unique Identifier (UUID)
- IPv4Address: IPv4 address
- IPv6Address: IPv6 address
- HexColorCode: Hexadecimal color code
- AlphanumericString: Alphanumeric string
- Json: JSON string
- ArrayOfType: Array of a specific type
- CustomEnum: Custom enumeration type
- CreditCardNumber: Credit card number
- SocialSecurityNumber: Social Security number
- LatitudeLongitude: Latitude and longitude coordinates
- CurrencyAmount: Currency amount
- Percentage: Percentage value
- FileSize: File size
- TimeInterval: Time interval
- ISBN: International Standard Book Number (ISBN)
- MACAddress: MAC address
- IBAN: International Bank Account Number (IBAN)
- Password: Password with specific constraints
- PostalCode: Postal code
- CreditScore: Credit score
- FahrenheitTemperature: Temperature in Fahrenheit
- CelsiusTemperature: Temperature in Celsius
- BinaryData: Binary data
- Gender: Gender (Male/Female/Other)
- Latitude: Latitude coordinate
- Longitude: Longitude coordinate
- ISBN13: ISBN-13
- IMEI: International Mobile Equipment Identity (IMEI)
- CreditCardExpirationDate: Credit card expiration date
- VATNumber: Value Added Tax (VAT) number
- HexadecimalNumber: Hexadecimal number
- BooleanString: Boolean represented as a string
- RomanNumeral: Roman numeral
- PassportNumber: Passport number
- MIMEType: Multipurpose Internet Mail Extensions (MIME) type
- MACAddressOUI: MAC address Organizationally Unique Identifier (OUI)
- EAN13: International Article Number (EAN-13)
- EAN8: International Article Number (EAN-8)
- VehicleIdentificationNumber (VIN): VIN for vehicles
- ISSN: International Standard Serial Number (ISSN)
- UPC: Universal Product Code (UPC)
- GS1Barcode: GS1 Barcode
- MD5Hash: MD5 hash
- SHA1Hash: SHA-1 hash
- SHA256Hash: SHA-256 hash
- SHA512Hash: SHA-512 hash
- RGBColor: RGB color
- RGBAColor: RGBA color (with alpha channel)
- HSLColor: HSL color
- HSLAColor: HSLA color (with alpha channel)
- HTMLColorName: HTML color name
- Base64EncodedString: Base64-encoded string
- ISBN10: ISBN-10
- USStateAbbreviation: US state abbreviation
- CanadianPostalCode: Canadian postal code
- SocialMediaUsername: Social media username
- HexadecimalRGBColor: Hexadecimal RGB color
- AlphabeticalString: Alphabetical string
- MongoDBObjectId: MongoDB Object ID
- JWToken: JSON Web Token (JWT)
- UnixTimestamp: Unix timestamp
- YouTubeVideoId: YouTube video ID
- HexadecimalUUID: Hexadecimal UUID
- HTTPStatusCode: HTTP status code
- SemVer: Semantic versioning string
- EpochTime: Epoch time
- HexadecimalMACAddress: Hexadecimal MAC address
- GoogleAnalyticsTrackingId: Google Analytics tracking ID
- USZipCode: US ZIP code
- Slug: URL-friendly slug
- TwitterHandle: Twitter handle
- HexadecimalBinary: Hexadecimal binary data
- RandomGuid: Randomly generated GUID
- ICAOAirportCode: ICAO airport code
- HexadecimalHTMLColor: Hexadecimal HTML color code
- GitCommitHash: Git commit hash
- CustomMimeType: Custom MIME type
- GPSCoordinates: GPS coordinates
- AmericanExpressCardNumber: American Express credit card number
- MasterCardNumber: MasterCard credit card number
- VisaCardNumber: Visa credit card number
- DinersClubCardNumber: Diners Club credit card number
- DiscoverCardNumber: Discover credit card number
- JCBCardNumber: JCB credit card number
- DebitCardNumber: Debit card number
- WindowsFilePath: Windows file path
- UnixFilePath: Unix file path
- CurrencyCode: Represents the code of a currency (e.g., USD, EUR).
- CurrencyAmount: Represents the numerical value of an amount in a specific currency.
- ExchangeRate: Represents the exchange rate between two currencies.
- CryptocurrencyCode: Represents the code of a cryptocurrency (e.g., BTC, ETH).
- CryptocurrencyAmount: Represents the numerical value of an amount in a specific cryptocurrency.
- BitcoinAddress: Represents a Bitcoin wallet address.
- EthereumAddress: Represents an Ethereum wallet address.
- LitecoinAddress: Represents a Litecoin wallet address.
- RippleAddress: Represents a Ripple wallet address.
- MoneroAddress: Represents a Monero wallet address.
- StellarAddress: Represents a Stellar wallet address.
- EOSAddress: Represents an EOS wallet address.
- DashAddress: Represents a Dash wallet address.
- ZcashAddress: Represents a Zcash wallet address.
- USDCurrency: Represents the United States Dollar (USD).
- EuroCurrency: Represents the Euro (EUR).
- BritishPoundCurrency: Represents the British Pound (GBP).
- JapaneseYenCurrency: Represents the Japanese Yen (JPY).
- CanadianDollarCurrency: Represents the Canadian Dollar (CAD).
- AustralianDollarCurrency: Represents the Australian Dollar (AUD).
- SwissFrancCurrency: Represents the Swiss Franc (CHF).
- ChineseYuanCurrency: Represents the Chinese Yuan (CNY).
- IndianRupeeCurrency: Represents the Indian Rupee (INR).
- BrazilianRealCurrency: Represents the Brazilian Real (BRL).
- SouthAfricanRandCurrency: Represents the South African Rand (ZAR).
- SwedishKronaCurrency: Represents the Swedish Krona (SEK).
- NorwegianKroneCurrency: Represents the Norwegian Krone (NOK).
- SingaporeDollarCurrency: Represents the Singapore Dollar (SGD).
- NewZealandDollarCurrency: Represents the New Zealand Dollar (NZD).
- MexicanPesoCurrency: Represents the Mexican Peso (MXN).
Contributing
Please see CONTRIBUTING for details.
Code of Conduct
In order to ensure that the php community is welcoming to all, please review and abide by the Code of Conduct.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
This package is open-sourced software licensed under the MIT license.