Download the PHP package cosmologist/gears without Composer
On this page you can find all versions of the php package cosmologist/gears. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package gears
php-gears
Collection of useful PHP functions/classes/utils.
- Installation
- Common
- Array functions
- Object functions
- String functions
- Number functions
- Callable functions
- Class functions
- Symfony
- Form utils
- Validator utils
Installation
Array functions
Get an item from the array by key
Adds a value to an array with a specific key only if key not presents in an array
It's more intuitive variant to <code>$array += [$key => $value];
Push element onto the end of array and returns the modified array
Prepend element to the beginning of an array and returns the modified array
Calculate the average of values in an array (array_avg)
Check if array is associative
Check if a value exists in an array
Inserts an array after the key
Inserts an array before the key
Convert list of items to ranges
Unset array item by value
Calculate the standard deviation of values in an array
Cast to an array
Behavior for different types:
- array - returns as is
- iterable - converts to a native array (
iterator_to_array()
) - another - creates an array with argument ([value])
Get the array encoded in json
If encoded value is false, true or null then returns empty array.
JSON_THROW_ON_ERROR always enabled.
Object functions
Reads the value at the end of the property path of the object graph
Uses Symfony PropertyAccessor
Sets the value at the end of the property path of the object graph
Uses Symfony PropertyAccessor
Reads the value of internal object property (protected and private)
Read ocramius
Writes the value to internal object property (protected and private)
Read ocramius
Calls the internal object method (protected and private) and returns result
Read ocramius
Get a string representation of the object or enum
- Result of __toString method if presents
- String value of case for the BackedEnum
- Name of case for the UnitEnum
- or generated string like "FQCN@spl_object_id"
PHP default behavior: if the method is not defined, an error (Object of class X could not be converted to string
) is triggered.
Cast an object or a FQCN to FQCN
Returns the result of __toString
or null if the method is not defined.
PHP default behavior: if the method is not defined, an error (Object of class X could not be converted to string
) is triggered.
String functions
Determine if a given string contains a given substring
Simple symmetric decryption of a string with a key (using libsodium)
Simple symmetric encryption of a string with a key (using libsodium)
Convenient way to perform a regular expression match
Default behaviour like preg_match_all(..., ..., PREG_SET_ORDER)
Exclude full matches from regular expression matches
Get only first set from regular expression matches (exclude full matches)
Get only first match of each set from regular expression matches (exclude full matches)
Get only first match of the first set from regular expression matches as single scalar value
Replace first string occurrence in a string
Wrap string
Guess the MIME-type of the string data
Guess the file extension from the string data.
Check if a string is a binary string
Convert string to CamelCase
Convert string to snake_case
ltrim()/rtrim()/trim() replacements supports UTF-8 chars in the charlist
Use these only if you are supplying the charlist optional arg and it contains UTF-8 characters. Otherwise trim will work normally on a UTF-8 string.
Split text into sentences
returns
Split text into words
Remove word from text
Number functions
Parse a float or integer value from the argument
Remove all characters except digits, +-.,eE from the argument and returns result as the float value or NULL if the parser fails.
Parse a float value from the argument
Remove all characters except digits, +-.,eE from the argument and returns result as the float value or NULL if the parser fails.
Parse a integer value from the argument
Remove all characters except digits, plus and minus sign and returns result as the integer value or NULL if the parser fails.
Returns fractions of the float value
Checks if the value is odd
Checks if the value is even
Round to nearest multiple
Round down to nearest multiple
Round up to nearest multiple
Spell out
Division with zero tolerance
Percent calculation
The first argument is a value for calculating the percentage. The second argument is a base value corresponding to 100%.
Unsign a number
A negative value will be converted to zero, positive or zero value will be returned unchanged.
Converts a number to string with sign.
Callable functions
Get a suitable reflection object for the callable
Class functions
Get the class or an object class short name
Get the class and the parent classes
Get the class and the parent classes
Get the corresponding basic enum case dynamically from variable
Basic enumerations does not implement from() or tryFrom() methods, but it is possible to return the corresponding enum case using the constant() function.
Symfony Forms utils
Convert domain model constraint violation to the form constraint violation
It's maybe useful when you validate your model from form on the domain layer and want to map violations to the form.
Trait with a method implementing DataMapperInterface::mapDataToForms with default behavior
This is convenient for mapping of form data to a model via DataMapperInterface::mapFormsToData(), for example, to create a model via a constructor, in this case, the mapping of model data to a form via DataMapperInterface::mapDataToForms() will remain unchanged, and you cannot not define it, since it is required by the DataMapperInterface.