Missing data types for PHP. Highly extendable.

Overview

SmartEmailing \ Types

Missing data types for PHP 7.2, 7.3, 7.4 and 8.0. Highly extendable, production tested.

MIT license Latest release Downloads

Build Status Code coverage CodeClimate

Neverending data validation can be exhausting. Either you have to validate your data over and over again in every function you use it, or you have to rely it has already been validated somewhere else and risk potential problems.

Smelly, right?

Replacing validation hell with Types will make your code much more readable and less vulnerable to bugs.

Types wrap your data in value objects that are guaranteed to be valid and normalized; or not to exist at all. It allows you to use specific type hints instead of primitive types or arrays. Your code will be unbreakable and your IDE will love it.

Table of Contents

Installation

The recommended way to install is via Composer:

composer require smartemailing/types

How does it work

It is easy. You just initialize desired value object by simple one-liner. From this point, you have sanitized, normalized and valid data; or SmartEmailing\Types\InvalidTypeException to handle.

Types consist from:

  • String-extractable types - validated strings (E-mail address, Domains, Hexadecimal strings, ...)
  • Int-extractable types - validated integers (Port)
  • Float-extractable types - validated floats (SigmoidValue, Part, ...)
  • Enum-extractable types - enumerables (CountryCode, CurrencyCode, GDPR's Lawful purpose, ...)
  • Composite (Array-extractable) types - structures containing multiple another types (Address, ...)
  • DateTimes - extraction of DateTime and DateTimeImmutable
  • Primitive types extractors and unique arrays

Different types provide different methods related to them, but all types share this extraction API:

Wrapping raw value



declare(strict_types = 1);

use SmartEmailing\Types\Emailaddress;
use SmartEmailing\Types\InvalidTypeException;

// Valid input

$emailaddress = Emailaddress::from('[email protected]'); // returns Emailaddress object
$emailaddress = Emailaddress::from($emailaddress); // returns original $emailaddress

// Invalid input

$emailaddress = Emailaddress::from('bla bla'); // throws InvalidTypeException
$emailaddress = Emailaddress::from(1); // throws InvalidTypeException
$emailaddress = Emailaddress::from(false); // throws InvalidTypeException
$emailaddress = Emailaddress::from(null); // throws InvalidTypeException
$emailaddress = Emailaddress::from([]); // throws InvalidTypeException
$emailaddress = Emailaddress::from(new \StdClass()); // throws InvalidTypeException

// Nullables

$emailaddress = Emailaddress::fromOrNull(null); // returns NULL
$emailaddress = Emailaddress::fromOrNull('bla bla'); // throws InvalidTypeException
$emailaddress = Emailaddress::fromOrNull('bla bla', true); // returns null instead of throwing

Extraction from array

This is really useful for strict-typing (validation) multidimensional arrays like API requests, forms or database data.



use SmartEmailing\Types\Emailaddress;
use SmartEmailing\Types\InvalidTypeException;

$input = [
	'emailaddress' => '[email protected]',
	'already_types_emailaddress' => Emailaddress::from('[email protected]'),
	'invalid_data' => 'bla bla',
];

// Valid input

$emailaddress = Emailaddress::extract($input, 'emailaddress'); // returns Emailaddress object
$emailaddress = Emailaddress::extract($input, 'already_types_emailaddress'); // returns original Emailaddress object

// Invalid input

$emailaddress = Emailaddress::extract($input, 'invalid_data'); // throws InvalidTypeException
$emailaddress = Emailaddress::extract($input, 'not_existing_key'); // throws InvalidTypeException

// Nullables 

$emailaddress = Emailaddress::extractOrNull($input, 'not_existing_key'); // returns null
$emailaddress = Emailaddress::extractOrNull($input, 'invalid_data'); //  throws InvalidTypeException
$emailaddress = Emailaddress::extractOrNull($input, 'invalid_data', true); // returns null instead of throwing

// Default values
$emailaddress 
	= Emailaddress::extractOrNull($input, 'not_existing_key') 
	?? Emailaddress::from('[email protected]'); 
	// uses null coalescing operator to assign default value if key not present or null

$emailaddress 
	= Emailaddress::extractOrNull($input, 'not_existing_key', true) 
	?? Emailaddress::from('[email protected]'); 
	// uses null coalescing operator to assign default value if key not present or null or invalid

String-extractable types

String-extractable types are based on validated strings. All values are trimmed before validation.

They can be easily converted back to string by string-type casting or calling $type->getValue().

E-mail address

SmartEmailing\Types\Emailaddress

Lowercased and ASCII-transformed e-mail address ([email protected])

Type-specific methods:

  • getLocalPart() : string returns local part of e-mail address (hello)
  • getDomain() : \SmartEmailing\Types\Domain returns domain part (gmail.com, represented as Types\Domain)

Non-empty string

SmartEmailing\Types\NonEmptyString

Trimmed non-empty string.

Domain

SmartEmailing\Types\Domain

Lowercased domain name (mx1.googlemx.google.com)

Type-specific methods:

  • getSecondLevelDomain() : \SmartEmailing\Types\Domain returns second-level domain. (google.com)

Hex 32

SmartEmailing\Types\Hex32

Lowercased 32-characters long hexadecimal string useful as container for MD5 or UUID without dashes. (741ecf779c9244358e6b85975bd13452)

Hex color

SmartEmailing\Types\HexColor

Uppercased 7-characters long string useful as container for color. (#006EDB)

GUID

SmartEmailing\Types\Guid

Lowercased Guid with dashes (741ecf77-9c92-4435-8e6b-85975bd13452)

IP address

SmartEmailing\Types\IpAddress

IP address v4 or v6. (127.0.0.1, [2001:0db8:0a0b:12f0:0000:0000:0000:0001], 2001:db8:a0b:12f0::1)

Type-specific methods:

  • getVersion() : int returns IP address version, 4 or 6

URL

SmartEmailing\Types\UrlType

URL based on Nette\Http\Url (https://www.google.com/search?q=all+work+and+no+play+makes+jack+a+dull+boy)

  • all spaces in string are urlencoded
  • all non-ascii characters are urlencoded

Type-specific methods:

  • getAuthority() : string returns authority (www.google.com)
  • getHost() : string returns Host (www.google.com)
  • getQueryString() : string returns Query string (q=all%20work%20and%20no%20play%20makes%20jack%20a%20dull%20boy)
  • getPath() : string returns URl Path (/search)
  • getAbsoluteUrl() : string Complete URL as string, alias for getValue()
  • getQueryParameter(string $name, mixed $default = null): mixed Return value of parameter $name
  • getBaseUrl(): string Return URL without path, query string and hash part (https://www.google.cz/)
  • getScheme(): string Return URL scheme (https)
  • hasParameters(string[] $names): bool Returns true if URL parameters contain all parameters defined in $names array
  • getParameters(): array Returns all URL parameters as string-indexed array
  • withQueryParameter(string $name, mixed $value): UrlType Returns new instance with added query parameter.

Company registration number

SmartEmailing\Types\CompanyRegistrationNumber

Whitespace-free company registration number for following countries: CZ, SK, CY

Phone number

SmartEmailing\Types\PhoneNumber

Whitespace-free phone number in international format for following countries: CZ, SK, AT, BE, FR, HU, GB, DE, US, PL, IT, SE, SI, MH, NL, CY, IE, DK, FI, LU, TR

Type-specific methods:

  • getCountry() : SmartEmailing\Types\CountryCode Originating country (CZ)

ZIP code

SmartEmailing\Types\ZipCode

Whitespace-free ZIP code valid in following countries: CZ, SK, UK, US

JSON

SmartEmailing\Types\JsonString

Valid JSON-encoded data as string

Type-specific methods:

  • static from(mixed $data) : SmartEmailing\Types\JsonString Accepts string or array. Crates JsonString from valid json string or raw data (array)
  • static encode(mixed $data) : SmartEmailing\Types\JsonString create JsonString from raw data (array)
  • getDecodedValue() : mixed decode JsonString back to raw data

Base 64

SmartEmailing\Types\Base64String

Valid Base 64-encoded data as string

Type-specific methods:

  • static encode(string $value) : SmartEmailing\Types\Base64String create Base64String from string
  • getDecodedValue() : string decode Base64String back to original string

Iban

SmartEmailing\Types\Iban

Type-specific methods:

  • getFormatted(string $type = SmartEmailing\Types\Iban::FORMAT_ELECTRONIC): string returns formatted Iban string. Format types: FORMAT_ELECTRONIC, FORMAT_PRINT.
  • getCountry(): SmartEmailing\Types\CountryCode
  • getChecksum(): int

SwiftBic

SmartEmailing\Types\SwiftBic

Valid Swift/Bic codes.

VatId

SmartEmailing\Types\VatId

Type-specific methods:

  • static isValid(string $vatId): bool returns true if the vat id is valid otherwise returns false
  • getCountry(): ?Country returns Country under which the subject should falls or null.
  • getPrefix(): ?string returns string that prefixing vat id like EL from EL123456789 or null.
  • getVatNumber(): string returns vat number without prefix like 123456789
  • getValue(): string return whole vat id EL123456789

CurrencyCode

SmartEmailing\Types\CurrencyCode

Valid currency codes by ISO 4217

CountryCode

SmartEmailing\Types\CountryCode

Valid country codes by ISO 3166-1 alpha-2

Int-extractable types

Int-extractable types are based on validated integers.

They can be easily converted back to int by int-type casting or calling $type->getValue().

Port

SmartEmailing\Types\Port

Port number

Integer interval, <0, 65535>

Quantity

SmartEmailing\Types\Quantity

Quantity of items

Integer interval, <1, PHP_INT_MAX>

Unsigned Integer

SmartEmailing\Types\UnsignedInt

Usigned integer

Integer interval, <0, PHP_INT_MAX>

Float-extractable types

Float-extractable types are based on validated floats.

They can be easily converted back to float by float-type casting or calling $type->getValue().

Part

SmartEmailing\Types\Part

Portion of the whole

Float interval <0.0, 1.0>

Type-specific methods:

  • static fromRatio(float $value, float $whole): Part creates new instance by division $value and $whole.
  • getPercent(): float returns (Ratio's value) * 100 to get percent representation

Sigmoid function value

SmartEmailing\Types\SigmoidValue

Result of Sigmoid function, useful when building neural networks.

Float interval <-1.0, 1.0>.

Rectified Linear Unit function value

SmartEmailing\Types\ReLUValue

Result of Rectified Linear Unit function, useful when building neural networks.

Float interval <0.0, Infinity).

Unsigned Float

SmartEmailing\Types\UnsignedFloat

Usigned float

Float interval, <0, PHP_FLOAT_MAX>

Array-extractable types

Array-extractable types are composite types encapsulating one or more another types. They are created from associative array. All Array-extractable types implement method toArray() : array which returns normalized array or type's data.

DateTimeRange

SmartEmailing\Types\DateTimeRange

Range between two \DateTimeInterfaces. Safe for datetimes out of range of unix timestamp.

Can be created from:

DateTimeRange::from(
	[
		'from' => 'YYYY-MM-DD HH:MM:SS',
		'to' => 'YYYY-MM-DD HH:MM:SS',
	]
)

Type-specific methods:

  • getFrom(): \DateTimeImmutable returns From date and time as \DateTimeImmutable instance
  • getTo(): \DateTimeImmutable returns To date and time as \DateTimeImmutable instance
  • getDurationInSeconds(): int returns number of seconds between From and To dates
  • contains(\DateTimeInterface $dateTime): bool returns true if provided \DateTimeInterface lies between From and To dates.
  • getLengthInSeconds(): int returns duration length in seconds

Duration

SmartEmailing\Types\Duration

Human-readable time interval.

Can be created from:

Duration::from(
	[
		'value' => 1,
		'unit' => TimeUnit::HOURS,
	]
);

Duration::from(
	'1 hours'
);

Type-specific methods:

  • getDateTimeModify(): string returns string that is compatible with \DateTime::modify() and \DateTimeImmutable::modify()
  • getUnit(): TimeUnit returns TimeUnit enum type
  • getValue() int returns number of units
  • static fromDateTimeModify(string $dateTimeModify): self creates new instance from string compatible with \DateTime::modify() and \DateTimeImmutable::modify()

Address

SmartEmailing\Types\Address

Location address contains street and number, town, zip code and country.

Can be created from:

Address::from(
	[
		'street_and_number' => '29 Neibolt Street',
		'town' => 'Derry',
		'zip_code' => '03038',
		'country' => 'US',
	]
);

Type-specific methods:

  • getStreetAndNumber(): string returns street and number
  • getTown(): string returns Town
  • getZipCode(): ZipCode returns ZipCode instance
  • getCountry(): CountryCode returns CountryCode instance

Price

SmartEmailing\Types\Price

Price object containing number of currency units with VAT, number of currency units without VAT and currency.

Can be created from:

Price::from(
	[
		'with_vat' => 432.1,
		'without_vat' => 123.45,
		'currency' => CurrencyCode::EUR,
	]
);

Type-specific methods:

  • getWithoutVat(): float returns price without VAT
  • getWithVat(): float returns price with VAT
  • getCurrency(): CurrencyCode returns CurrencyCode instance

Login credentials

SmartEmailing\Types\LoginCredentials

Value object containing login and plain password. You should use it just in-memory in authentication process and than drop it.

Can be created from:

LoginCredentials::from(
	[
		'login' => 'admin',
		'password' => 'BLzW75kJxEa7YXuqF9Di',
	]
);

Type-specific methods:

  • getLogin(): string returns login
  • getPassword(): string returns password

Key-Value pair

SmartEmailing\Types\KeyValue

Value object containing string key and string value.

Can be created from:

KeyValuePair::from(
	[
		'key' => 'overlook',
		'value' => 'all_work_and_no_play_makes_jack_a_dull_boy',
	]
);

Type-specific methods:

  • getKey(): string returns key
  • getValue(): string returns value

Scalar leaves array

SmartEmailing\Types\ScalarLeavesArray

Value object containing single or multi-dimensional array with only scalar or NULL values in it's leaves. Array keys stay untouched.

Can be created from:

ScalarLeavesArray::from(
	[
		[
			'a',
		],
		[
			1,
		],
		[
			'b',
			[
				true,
				[
					null,
				],
				[],
			],
		],
	]
);

Array-types-specific extractors:

  • static extractOrEmpty(array $data, string $key): self Behaves like standard ::extract() method, but returns empty ScalarLeavesArray when $data[$key] is null or not set.

Array-types

Types provide another kind of Array-extractable types: Unique primitive-type arrays. Their purpose is to hold unique set of primitives. They implement \Countable and \IteratorAggregate and natively support set operations.

All Array-types share following features:

  • static empty() : self Creates new empty instance of desired array-type.
  • split(int $chunkSize): self[] Splits current instance into array of several instances, each with maximum data-set size of $chunkSize.
  • merge(self $toBeMerged): self Returns new instance with data-set combined from parent and $toBeMerged instances. Both source instances stay unchanged.
  • deduct(self $toBeDeducted): self Returns new instance with data-set containing all items from parent that are not contained in $toBeDeducted. Both source instances stay unchanged.
  • count(): int Returns data-set size.
  • isEmpty(): bool Returns true if data-set is empty, false otherwise.

Array-types-specific extractors:

  • static extractOrEmpty(array $data, string $key): self Behaves like standard ::extract() method, but returns empty set when $data[$key] is null or not set.
  • static extractNotEmpty(array $data, string $key): self Behaves like standard ::extract() method, but throws InvalidTypeException when $data[$key] is not set, null or empty array.

UniqueIntArray

SmartEmailing\Types\UniqueIntArray

UniqueIntArray is able to hold unique set of integers.

Can be created from:

// duplicate values will be discarted
// keys are ignored

UniqueIntArray::from(
	[
		1, 2, 2, 3, 3, 3, 4 
	]
);

Type-specific methods:

  • getValues(): int[] Returns data-set of unique integers as array.
  • toArray(): int[] Is just alias for getValues().
  • add(int $id): bool Adds another integer to the data-set. Returns false if integer has already been there.
  • remove(int $id): void Removes integer from the data-set, if present.
  • contains(int $id): bool Returns true if $id is contained in the data-set, false otherwise.

UniqueStringArray

SmartEmailing\Types\UniqueIntArray

UniqueStringArray is able to hold unique set of strings.

Can be created from:

// duplicate values will be discarted
// keys are ignored

UniqueStringArray::from(
	[
		'a', 
		'b', 
		'c', 
		'all work and no play makes jack a dull boy',
		'all work and no play makes jack a dull boy',
		'all work and no play makes jack a dull boy',
	]
);

Type-specific methods:

  • getValues(): string[] Returns data-set of unique strings as array.
  • toArray(): string[] Is just alias for getValues().
  • add(string $id): bool Adds another string to the data-set. Returns false if string has already been there.
  • remove(string $id): void Removes string from the data-set, if present.
  • contains(string $id): bool Returns true if $id is contained in the set, false otherwise.

Enum-extractable types

Enum-extractable types are types that can contain single value from defined set. They are based on kkk

All Enum-extractable types share following features:

  • getValue() : string Returns enum-value
  • equals(self $enum): bool Returns true if $enum contains same value as parent.
  • equalsValue(string $value): self Returns true if parent contains the same value as $value.

Enums can be created using standard extractors or using their constants:

CurrencyCode::from(
	CurrencyCode::EUR
);
CurrencyCode::from(
	'EUR'
);

Lawful Basis For Processing

SmartEmailing\Types\LawfulBasisForProcessing

GDPR's lawful basis for processing

Available values

Country code

SmartEmailing\Types\CountryCode

ISO-3166-1 Alpha 2 country code

Available values

Currency code

SmartEmailing\Types\CurrencyCode

ISO-4217 three-letter currency code

Available values

Field of Application

SmartEmailing\Types\FieldOfApplication

Most common fields of human applications.

Available values

Time unit

SmartEmailing\Types\TimeUnit

Time unit compatible with \DateTime::modify() argument format

Available values

Relation

SmartEmailing\Types\Relation

Represents Relation or Gate - AND / OR

Available values

Primitive types and Arrays

Types are able to get and extract primitives using IntType, IntArray, FloatType, FloatArray, StringType, StringArray, BoolType, BoolArray and Array classes. See examples below:



declare(strict_types = 1);

use SmartEmailing\Types\Arrays;
use SmartEmailing\Types\BoolArray;
use SmartEmailing\Types\BoolType;
use SmartEmailing\Types\FloatArray;
use SmartEmailing\Types\FloatType;
use SmartEmailing\Types\IntArray;
use SmartEmailing\Types\IntType;
use SmartEmailing\Types\StringArray;
use SmartEmailing\Types\StringType;
use SmartEmailing\Types\InvalidTypeException;

IntType::from(666); // 666
IntType::from('666'); // 666
IntType::from(666.1); // throws InvalidTypeException
IntType::from('abcd'); // throws InvalidTypeException
IntType::from('abcd'); // throws InvalidTypeException
IntType::fromOrNull(null); // null
IntType::fromOrNull(1); // 1
IntType::fromOrNull('abcd'); // throws InvalidTypeException
IntType::fromOrNull('abcd', true); // null

FloatType::from(1.1); // 1.1
FloatType::from('1.1'); // 1.1
FloatType::from(1); // 1.0
FloatType::from('1'); // 1.0
FloatType::from('xxx'); // throws InvalidTypeException
FloatType::fromOrNull(null); // null
FloatType::fromOrNull(1.0); // 1.0
FloatType::fromOrNull('abcd'); // throws InvalidTypeException
FloatType::fromOrNull('abcd', true); // null

StringType::from('xxx'); // 'xxx'
StringType::from(5); // '5'
StringType::from(5.0); // '5'
StringType::from(5.1); // '5.1'
StringType::fromOrNull(null); // null
StringType::fromOrNull('abcd'); // 'abcd'
StringType::fromOrNull([]); // throws InvalidTypeException
StringType::fromOrNull([], true); // null

BoolType::from(true); // true
BoolType::from(false); // false
BoolType::from(1); // true
BoolType::from(0); // false
BoolType::from('1'); // true
BoolType::from('0'); // false
BoolType::from('true'); // true
BoolType::from('false'); // false

Arrays::from([1, 2]); // [1, 2]
Arrays::from([1, 'abcd']); // [1, 'abcd']

IntArray::from([1, '2']); // [1, 2]
IntArray::fromOrNull([1, '2']); // returns int[]|null

FloatArray::from([1, '2']); // [1.0, 2.0]
FloatArray::fromOrNull([1, '2']); // returns float[]|null

StringArray::from([1, '2']); // ['1', '2']
StringArray::fromOrNull([1, '2']); // returns string[]|null

BoolArray::from([1, '1']); // [true, true]
BoolArray::fromOrNull([1, '1']); // returns bool[]|null

// All primitive types have their extract equivalent:

IntType::extract($data, 'key');
IntType::extractOrNull($data, 'key');
IntType::extractOrNull($data, 'key', true);

StringType::extract($data, 'key');
StringType::extractOrNull($data, 'key');
StringType::extractOrNull($data, 'key', true);

FloatType::extract($data, 'key');
FloatType::extractOrNull($data, 'key');
FloatType::extractOrNull($data, 'key', true);

Arrays::extract($data, 'key'); //returns mixed[]
Arrays::extractOrNull($data, 'key'); //returns mixed[]|null

IntArray::extract($data, 'key'); //returns int[]
IntArray::extractOrNull($data, 'key'); //returns int[]|null

FloatArray::extract($data, 'key'); //returns float[]
FloatArray::extractOrNull($data, 'key'); //returns float[]|null

StringArray::extract($data, 'key'); //returns string[]
StringArray::extractOrNull($data, 'key'); //returns string[]|null

BoolArray::extract($data, 'key'); //returns bool[]
BoolArray::extractOrNull($data, 'key'); //returns bool[]|null

DateTimes and DateTimesImmutable

Types are able to get and extract \DateTime and \DateTimeImmutable objects using DateTimes and DateTimesImmutable classes. Supported format Y-m-d H:s:i. API is the same as for other types, so available methods are (shown for DateTimes):

  • from(string $dateTime ) : \DateTime
  • extract(array $data, string $index) : \DateTime
  • extractOrNull(array $data, string $index, bool $getNullIfInvalid) : ?\DateTime

Dates and DatesImmutable

Types are able to get and extract \DateTime and \DateTimeImmutable objects using Dates and DatesImmutable classes. Dates are created with time sets on 00:00:00. Supported format Y-m-d. API is the same as for other types, so available methods are (shown for Dates):

  • from(string $dateTime ) : \DateTime
  • extract(array $data, string $index) : \DateTime
  • extractOrNull(array $data, string $index, bool $getNullIfInvalid) : ?\DateTime

Writing your own types

Implementing your custom type is easy! At first you have to decide what extractable-type should your new custom type be and use particular extractable-trait in it's class to enhance it by all extractable features. The only thing you have to do next is implement class construtor and throw InvalidTypeException in case of invalid data. You can see examples for every extractable-type below.

One more thought - if you think your new type will be useful for others, please, contribute!

How to contribute

Thank you for your interest in improving Types!️ ❤️ 🖖

Before you open pull request, please, make sure you did not forget to write tests for your code.

Then run following commands:

  1. vendor/bin/tester tests Run tests locally. It takes just two seconds :-)

  2. bin/cbf This will check the code and automatically fix some code style issues like indentation or line breaks.

  3. bin/cs This will run another code style check that will notify you about problems that must be fixed manually. Please, fix them, and re-run the command.

  4. bin/stan PHP Static analysis tool - this will check the code for some smelly constructions that should be refactored. Please, fix them, and re-run the command.

  5. PR ready!

We are hiring

Do you like our code? If you want to be part of SmartEmailing, we are hiring.

You might also like...
Yet Another LINQ to Objects for PHP [Simplified BSD]

YaLinqo: Yet Another LINQ to Objects for PHP Online documentation GitHub repository Features The most complete port of .NET LINQ to PHP, with many add

🗃 Array manipulation library for PHP, called Arrayy!

🗃 Arrayy A PHP array manipulation library. Compatible with PHP 7+ & PHP 8+ \Arrayy\Type\StringCollection::create(['Array', 'Array'])-unique()-appen

`LINQ to Object` inspired DSL for PHP

Ginq Array handling in PHP? Be happy with Ginq! Ginq is a DSL that can handle arrays and iterators of PHP unified. Ginq is inspired by Linq to Object,

Collections Abstraction library for PHP

Collections Collections Abstraction library for PHP The Collection library is one of the most useful things that many modern languages has, but for so

Leetcode for PHP,  five questions a week and weekends are updated irregularly
Leetcode for PHP, five questions a week and weekends are updated irregularly

✏️ Leetcode for PHP why do you have to sleep for a long time ,and naturally sleep after death 联系 说明 由于目前工作主要是 golang,我又新起了一个LeetCode-Go-Week项目,- Leetc

JsonMapper - map nested JSON structures onto PHP classes

Takes data retrieved from a JSON web service and converts them into nested object and arrays - using your own model classes.

All Algorithms implemented in Php

The Algorithms - PHP All algorithms implemented in Php (for education) These implementations are for learning purposes. They may be less efficient tha

A community driven collection of sorting algorithms in PHP

algorithms A community driven collection of sorting algorithms This repository includes a comma separated file that includes 10k numbers between 1 and

PHP logging library that is highly extendable and simple to use.

Analog - Minimal PHP logging library Copyright: (c) 2012-Present Johnny Broadway License: MIT A minimal PHP logging package based on the idea of using

SecLists is the security tester's companion. It's a collection of multiple types of lists used during security assessments, collected in one place. List types include usernames, passwords, URLs, sensitive data patterns, fuzzing payloads, web shells, and many more.
QuidPHP/Core is a PHP library that provides an extendable platform to create dynamic applications

QuidPHP/Core About QuidPHP/Core is a PHP library that provides an extendable platform to create dynamic applications. It is part of the QuidPHP packag

Easy to use, fast extendable small PHP Framework, like the one you ever missed. The skeleton-APP

About Tufu-Framework Easy to use, fast extendable PHP Framework, like the one you ever missed. Features included such as: Twig and extensions. Fast ro

Intranet Home Page is a highly-configurable self-hosted browser homepage with integrations for public and local data feeds.
Intranet Home Page is a highly-configurable self-hosted browser homepage with integrations for public and local data feeds.

Intranet-Home-Page Created in response to personal "dashboards" that are little more than pages with a list of frequently accessed links, Intranet Hom

A highly compressed version of the magento 1.9 sample data and a script to create it.

Compressed Magento 1.9 Sample Data The following variations are available: 65M compressed-magento-sample-data-1.9.2.4.tgz 64M compressed-magento-sampl

Light and extendable schema validation library

Light PHP validation library For everyone who uses MongoDB or other NoSQL solution and cares about what client sends to his/her database and looking f

The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which save hours of work time. All commands are extendable by a module API.

netz98 magerun CLI tools for Magento 2 The n98 magerun cli tools provides some handy tools to work with Magento from command line. Build Status Latest

A RESTful and extendable Backend as a Service that provides instant backend to develop sites and apps faster, with dead-simple integration for JavaScript, iOS, Android and more.

Welcome to hook ![Gitter](https://badges.gitter.im/Join Chat.svg) hook is a RESTful, extendable Backend as a Service that provides instant backend to

Extendable Interactive Make Command for Laravel
Extendable Interactive Make Command for Laravel

Extendable Interactive Make Command for Laravel Make your life easier with interactive make command! Installation composer require hydreflab/laravel-m

📦 "PHP type names" contains the list of constants for the available PHP data types.

PHP type names PHP type names 📄 Description Simple library containing the list of constants for the available PHP data types. Use those constant type

Comments
  • Duration and TimeUnit

    Duration and TimeUnit

    TimeUnit

    • [ ] ~add getSecondsCount()~
    • [x] add weeks ?

    Duration

    • [x] add getDateTimeModify()
    • [ ] ~add getLengthInSeconds()~
    • [x] allow negative values
    opened by slischka 4
  • Iban

    Iban

    @slischka what you think about adding jschaedl/iban-validation dependency using in Iban type from required section in composer to suggestion?

    Constructor in Iban type will be like below:

    public function __construct(
    	string $value
    )
    {
    
    	if (!\class_exists(\Iban\Validation\Iban::class) || !\class_exists(\Iban\Validation\Iban::class)) {
    		throw new \Exception('For using ' . self::class . ' type, please require "jschaedl/iban-validation" in your project composer.')
    	}
    
    	$this->iban = new \Iban\Validation\Iban($value);
    	$validator = new Validator();
    
    	...
    opened by aleswita 2
  • Update consistence/consistence dependency (use 2.0 when possible)

    Update consistence/consistence dependency (use 2.0 when possible)

    Would it be possible to change consistence dependency to ^1.0 || ^2.0 and tag new version?

    I tried to use library within new project and get dependency error...

    opened by khorsky 1
Releases(v3.0.0)
  • v3.0.0(Dec 23, 2022)

    • removed dependency jschaedl/iban-validation, now if you are using SmartEmailing\Types\Iban, you must require this library by your self in you project composer (BC break)
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Nov 25, 2022)

  • v1.2.0(Oct 12, 2022)

  • v1.1.0(May 25, 2021)

    Dependencies:

    • Dropped support for PHP 7.1
    • Removed consistence/consistence
    • Added egulias/email-validator

    Classes:

    • Added class NonEmptyString, HostName, DomainName
    • Added primitive type extractors IntType, FloatType, StringType, BoolType, IntArray, FloatArray, StringArray, BoolArray
    • Improved UrlType
    • Improved Emailaddress and PhoneNumber validation
    • Unified extracting API using ExtractableTypeInterface
    • Added missing countries in CountryCode enum

    Helpers:

    • Added StringHelpers::sanitizeUtf8Mb4 and StringHelpers::sanitizeUtf8Mb4OrNull
    • Added CountryCodeToPhoneCodeTable

    Deprecations:

    • PrimitiveTypes
    • Domain

    Updated code style.

    Thanks to @mstrouhal, @cezam, @slischka, @aleswita :tada:

    Source code(tar.gz)
    Source code(zip)
  • v1.0.12(Jan 31, 2021)

    Fixes:

    • JsonString throws correct exception on failure

    Improvements:

    • bool can now be extracted from 'true' and 'false' strings

    Worth mentioning:

    • added tests for multiple PHP versions
    • tests migrated to GitHub Actions

    Thanks @aleswita

    Source code(tar.gz)
    Source code(zip)
  • v1.0.11(Nov 7, 2020)

    Fixes:

    • Fixed Dates and DateTimes validation

    Added value objects:

    • UnsignedFloat

    Added extractors:

    • Arrays::getFloatArray
    • Arrays::getFloatArrayOrNull
    • Arrays::extractFloatArray
    • Arrays::extractFloatArrayOrNull

    Improvements:

    • Duration API allows extract from array or string
    • Improved API consistency for extracting arrays
    Source code(tar.gz)
    Source code(zip)
  • v1.0.10(Aug 16, 2020)

    New Minor version here, thanks @aleswita @slischka @cezam @kotmic

    Features

    • DateTime features can now work with microseconds
    • HttpMethod enum added
    • KeyValuePair composite-type added
    • ...and other minor tweaks and bugfixes
    Source code(tar.gz)
    Source code(zip)
  • v1.0.9(Jan 13, 2020)

    Bump, new minor release here!

    Bugfixes

    • Fixed error when only 1 array is sent to intersect array methods

    Dependencies

    • consistence/consistence dependency version constraint changed to ^1.0 || ^2.0

    Minor changes

    • added Arrays::getIntArray(), Arrays::getStringArray(), Arrays::extractIntArrayOrNull(), Arrays::extractStringArrayOrNull() methods
    • PrimitiveTypes::extractStringArray() and PrimitiveTypes::extractStringArray() moved to Arrays class (with backwards compatibility)

    Country code:

    • Added country code for Norway
    Source code(tar.gz)
    Source code(zip)
  • v1.0.8(Aug 6, 2019)

    Bump, new minor release here! Thanks @slischka for big help.

    Country code:

    • Added country code for Russia

    Phone number:

    • Added IL phone number support, added US EIN support

    UrlType:

    • added UrlType::withHost() method
    • added UrlType::withScheme() method
    • added UrlType::withPath() method

    Primitive types

    • comma supported as decimal point in PrimitiveTypes

    new meta-type: ScalarLeavesArray

    • support for multidimensional array with scalar leaves

    new type extractors: Dates and DatesImmutable

    new type: HexColor

    Array types

    • union() and intersect() methods added to UniqueIntArray and UniqueToStringArray
    Source code(tar.gz)
    Source code(zip)
  • v1.0.7(Dec 4, 2018)

    • added soft-hyphen support for StringHelpers::removeWhitespace
    • nette 3.0 support
    • added Quantity type
    • addedget<Type>OrNull methods to PrimitiveTypes class
    Source code(tar.gz)
    Source code(zip)
  • v1.0.6(Oct 16, 2018)

  • v1.0.5(Sep 29, 2018)

  • v1.0.4(Sep 28, 2018)

  • v1.0.3(Sep 18, 2018)

  • v1.0.1(Sep 16, 2018)

    Added types:

    IBAN, SwiftBic - thanks to @slischka Support for turkish phone number format - thanks to @emir Duration Port Part SigmoidValue ReLUValue

    Source code(tar.gz)
    Source code(zip)
Owner
SmartEmailing
SmartEmailing
Best FlexForm based content elements since 2012. With TCA mapping feature, simple backend view and much more features which makes it super easy to create own content element types.

DCE-Extension for TYPO3 What is DCE? DCE is an extension for TYPO3 CMS, which creates easily and fast dynamic content elements. Based on Extbase, Flui

Armin Vieweg 10 Nov 2, 2022
A repository with implementations of different data structures and algorithms using PHP

PHP Data Structures and Algorithms Data structure and Algorithm is always important for any programming language. PHP, being one of the most popular l

Mizanur Rahman 610 Jan 2, 2023
Output complex, flexible, AJAX/RESTful data structures.

Fractal Fractal provides a presentation and transformation layer for complex data output, the like found in RESTful APIs, and works really well with J

The League of Extraordinary Packages 3.5k Jan 8, 2023
Library for (de-)serializing data of any complexity (supports JSON, and XML)

jms/serializer Introduction This library allows you to (de-)serialize data of any complexity. Currently, it supports XML and JSON. It also provides yo

Johannes 2.2k Jan 1, 2023
:lipstick: Scalable and durable all-purpose data import library for publishing APIs and SDKs.

Porter Scalable and durable data imports for publishing and consuming APIs Porter is the all-purpose PHP data importer. She fetches data from anywhere

null 594 Jan 1, 2023
Changeset calculator between two states of a data

Totem \\\\//// |.)(.| | || | Changeset calculator between two state of a data \(__)/ Requires PHP 5.4 ; Compatible

Wisembly 75 May 6, 2021
PHP Integrated Query, a real LINQ library for PHP

PHP Integrated Query - Official site What is PINQ? Based off the .NET's LINQ (Language integrated query), PINQ unifies querying across arrays/iterator

Elliot Levin 465 Dec 30, 2022
True asynchronous PHP I/O and HTTP without frameworks, extensions, or annoying code. Uses the accepted Fibers RFC to be implemented into PHP 8.1

PHP Fibers - Async Examples Without External Dependencies True asynchronous PHP I/O and HTTP without frameworks, extensions, or annoying code behemoth

Cole Green 121 Jan 6, 2023
Map nested JSON structures onto PHP classes

JsonMapper - map nested JSON structures onto PHP classes Takes data retrieved from a JSON web service and converts them into nested object and arrays

Christian Weiske 1.4k Dec 30, 2022
A Collections library for PHP.

A Library of Collections for OO Programming While developing and helping others develop PHP applications I noticed the trend to use PHP's arrays in ne

Levi Morrison 629 Nov 20, 2022