Download the PHP package sebastiaanluca/php-helpers without Composer
On this page you can find all versions of the php package sebastiaanluca/php-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sebastiaanluca/php-helpers
More information about sebastiaanluca/php-helpers
Files in sebastiaanluca/php-helpers
Package php-helpers
Short Description An extensive set of PHP helper functions and classes.
License MIT
Homepage https://github.com/sebastiaanluca/php-helpers
Informations about the package php-helpers
An extensive set of PHP helper functions and classes
Table of contents
- Requirements
- How to install
- Global helper functions
- rand_bool
- str_wrap
- is_assoc_array
- array_expand
- array_without
- array_pull_value
- array_pull_values
- array_hash
- object_hash
- has_public_method
- carbon
- temporary_file
- Class helpers
- Constants trait
- Retrieving constants
- Retrieving constant keys
- Retrieving constant values
- ProvidesClassInfo trait
- MethodHelper
- Constants trait
- License
- Change log
- Testing
- Contributing
- Security
- Credits
- About
Requirements
- PHP 8 or higher
How to install
Via Composer:
All function helpers will be enabled by default (if those functions haven't already been defined). Class helpers are enabled per-case when used.
You can find more info on how to use a helper and what there requirements are in their respective section (see the table of contents above for an overview).
Global helper functions
rand_bool
Randomly return true
or false
.
str_wrap
Wrap a string with another string.
is_assoc_array
Check if an array is associative.
Performs a simple check to determine if the given array's keys are numeric, start at 0, and count up to the amount of values it has.
array_expand
Expand a flat dotted array into a multi-dimensional associative array.
If a key is encountered that is already present and the existing value is an array, each new value will be added to that array. If it's not an array, each new value will override the existing one.
array_without
Get the array without the given values.
Accepts either an array or a value as parameter to remove.
array_pull_value
Pull a single value from a given array.
Returns the given value if it was successfully removed from the source array or null
if it was not found.
array_pull_values
Pull an array of values from a given array.
Returns the values that were successfully removed from the source array or an empty array if none were found.
array_hash
Create a unique string identifier for an array.
The identifier will be entirely unique for each combination of keys and values.
object_hash
Create a unique string identifier for an object.
Similar to array_hash, this uses serialize
to stringify all public properties first. The identifier will be entirely unique based on the object class, properties, and its values.
has_public_method
Check if a class has a certain public method.
carbon
Create a Carbon datetime object from a string or return a new object referencing the current date and time.
Requires the nesbot/carbon package.
temporary_file
Create a temporary file.
Returns an array with the file handle (resource) and the full path as string.
The temporary file is readable and writeable by default. The file is automatically removed when closed (for example, by calling fclose() on the handle, or when there are no remaining references to the file handle), or when the script ends.
Class helpers
Enum trait
The primary use of the Enum
trait is to enable you to store all cases of a specific type in a single class or value object and have it return those with a single call.
This can be useful for instance when your database uses integers to store states, but you want to use descriptive strings throughout your code (i.e. enums). It also allows you to refactor these elements at any time without having to waste time searching your code for any raw values (and probably miss a few, introducing new bugs along the way).
Retrieving elements
Returns an array of element keys and their values.
Retrieving element keys
Returns all the keys of the elements in an enum.
Retrieving constant values
Returns all the values of the elements in an enum.
ProvidesClassInfo trait
The ProvidesClassInfo
trait provides an easy-to-use getClassDirectory()
helper method that returns the directory of the current class.
MethodHelper
A static class helper to help you figure out the visibility/accessibility of an object's methods.
License
This package operates under the MIT License (MIT). Please see LICENSE for more information.
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
Contributing
Please see CODE OF CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Sebastiaan Luca
- All Contributors
About
My name is Sebastiaan and I'm a freelance back-end developer specializing in building custom Laravel applications. Check out my portfolio for more information, my blog for the latest tips and tricks, and my other packages to kick-start your next project.
Have a project that could use some guidance? Send me an e-mail at [email protected]!