Just some classes helping to code with PHP in general. No dependencies. High quality code.
This repository follows semver.
composer require "nekland/tools"This library provide some tools to help you with your developments.
Here is the list of tools it provides:
Encoding arguments are optionals.
StringTools::camelize($str, $from, $encoding, $normalize = true) : string$strstring input$from(optional, default "_") input string format (can be "-" or "_")$encoding(optional, default "UTF-8") encoding of your input string$normalizedecide either you want to normalize (remove special characters) or not, that's what you want in most cases when camelizing
Say if the given string starts with needle or not.
StringTools::startsWith($str, $start) : bool$strstring input$startstring it should starts with
Say if the given string ends with needle or not.
StringTools::endsWith($str, $end) : bool$strstring input$endstring it should ends with
Removes the start of the string if it matches with the given one.
StringTools::removeStart($str, $toRemove) : string$strstring input$toRemovestring to remove at the start of$str
Removes the end of the string if it matches with the given text to remove.
StringTools::removeEnd($str, $toRemove) : string$strstring input$toRemovestring to remove at the end of$str
StringTools::contains($str, $needle) : bool$strstring input$needlepotentially contained string
Adds missing multi-byte PHP function for ucfirst standard function.
StringTools::mb_ucfirst($str, $encoding) : string$strstring input$encoding(optional, default "UTF-8") encoding of your input string
ArrayTools::removeValue($array, $value) : void$arrayinput array passed by reference$valueThe value to remove from the $array
Helps you equals on objects on a similar way as java.
Method that you must implements to check if the object taking as parameter is equals or not.
For following methods lowest and greatest, you can provide unlimited DateTimeInterface objects.
Please note that non DateTimeInterface objects will be ignored by functions.
Compare \DateTimeInterface from parameters and return the greatest
DateTimeComparator::greatest($dateTime1, $dateTime2, $dateTime3, ...) : ?\DateTimeInterfaceCompare \DateTimeInterface from parameters and return the lowest
DateTimeComparator::lowest($dateTime1, $dateTime2, $dateTime3, ...) : ?\DateTimeInterfaceThe class TemporaryFile helps you to create temporary file with ease.
TemporaryFile::__construct(TemporaryDirectory $dir = null, string $prefix = '')Examples:
// Create a file in temporary folder
$file = new TemporaryFile();
// Create a file inside a temporary directory (see TemporaryDirectory class)
$file = new TemporaryFile($temporaryDir);
// Create a file in a temporary folder with php_ prefix.
$file = new TemporaryFile(null, 'php_');TemporaryFile::setContent(string $content)
TemporaryFile::getContent(): stringReturns the complete path to the file (ie: /tmp/generated-folder/filename)
TemporaryFile::getPathname(): stringRemoves the file from filesystem.
TemporaryFile::remove()TemporaryDirectory::__construct(string $dir = null, string $prefix = 'phpgenerated')Examples:
// create a new directory
$directory = new TemporaryDirectory();Create a TemporaryFile from the directory generated.
TemporaryDirectory::getTemporaryFile(): TemporaryFileRemoves the directory.
TemporaryDirectory::remove(bool $force = false): voidIf force is specified to true, it will remove the directory even if it has files inside.
Returns the complete path to the folder (ie: /tmp/folder-name)
TemporaryDirectory::getPathname(): string