nette/utils
Handy PHP utility library from Nette: strings, arrays, filesystem, safe JSON, and more. Includes proven helpers like Strings, Arrays, FileSystem, and Validators to simplify everyday tasks with clean APIs, good performance, and broad compatibility.
This release adds an immutable date/time class, makes file writes safer, background processes possible, and Finder masks smarter. Plus a couple of bug fixes worth picking up.
Nette\Utils\DateTime. It extends PHP's \DateTimeImmutable with strict validation (invalid dates and times throw instead of being silently rolled over), convenient factories from() and fromParts(), DST-safe relative modifications, and JSON serialization.Process object is destroyed, instead of being killed by the destructor. Output must go to a file or be discarded, since nobody reads the pipes after detaching.stream_select().addHtml(), plain strings are escaped by default and nulls are skipped.fromText() and fromHtml(), which are now deprecated.**/foo together with in() searches recursively, and the ** short form expands like in zsh, so test/** means test/**/* and **.c means **/*.c (previously such masks silently degraded to a single *).find() mask matches directories only: find('temp/').find(): **.txt works, ./ anchors to the search root, and a trailing /, /* or /** controls whether the directory itself, its contents, or both are excluded.http://999.1.1.1 no longer passes as a valid URL.mbstring nor iconv is available no longer relies on the deprecated utf8_decode(), so it stays quiet on PHP 8.2+.exclude('subdir/') silently excluded nothing due to a greedy regex; the trailing /, /* and /** variants now work as documented.Process::runExecutable() passes arguments as an array so there's zero shell involvement and no risk of shell injection, while Process::runCommand() is there when you really do want the shell. Comes with timeouts, incremental output consumption (consumeStdOutput() / consumeStdError()), and works on Windows too.CON or LPT1.$warnings parameter – pass it in and any GD warnings are handed back to you as a string instead of being emitted as a PHP warning, so you can log or display them on your own terms.A maintenance release focused on code quality: stricter types, better PHPDoc annotations, and PHPStan now runs as a mandatory CI check. No breaking changes.
Type::with()Type::fromValue()Helpers::splitClassName()Iterables::repeatable()is_file() does not work with symlinks under Windowssupport for PHP 8.5
Strings::trim() trims Line Separator and Ideographic Space (#326)DateTime::relativeToSeconds() checks for errormodify() correctly handle the relative time even if the daylight saving time is changedrelativeToSeconds() for converting relative time string to secondsFileSystem::resolvePath() #308Strings::matchAll(): added option 'lazy'Arrays::mapWithKeys() & Iterables::mapWithKeys()Iterables::memoize() & toIterator()IterablesArrays::firstKey(), lastKey()Arrays::filter()Arrays::first() & last(): added parameter $elseArrays::first() & last(): added parameter $predicate #305Image::getSupportedTypes()Strings::trim() trims unicode spaces and ZWSP (#304)Image::rgb()Image::rectangleWH(), filledRectangleWH(), calculateTextBox()Strings::length() uses mbstring, iconv and then utf8_decode #299getType() replaced with isDir() / isFile()some(), every() and map() (#298)Callback::unwrap() returns correct class name for private methodsgetParameterType(), getReturnType() and getPropertyType() marked as deprecatedImage::isTypeSupported()collect() returns listCallback::unwrap() returns correct class name for private methodsnew methods:
new parameters:
removed
isTypeDeclaration(), isBuiltinType(), isClassKeyword()Types::isSingle() -> isSimple()Image::clone() uses PNG format because GD2 is disabled since libgd 2.3.3extensionToType()Arrays::isList() uses array_is_list() is PHP 8.1Deprecated properties are written as [@property-deprecated](https://github.com/property-deprecated), no standard here exists. PhpStorm and static analysis tools do not see them, which is the intention.
Strings::indexOf() fixed empty $haystack and negative $nth #271Helpers::clamp()Validators::isPhpIdentifier(): Value is always string. (#268)Reflection::expandClassName() recognizes 'parent'Reflection::isClassKeyword(), Type::isClassKeyword()Reflection::getReturnType() & Type::fromReflection() return tentative type in PHP 8.1getReturnTypes(), getParameterTypes(), getPropertyTypes() are deprecatedArrayList::from()getReturnTypes(), getParameterTypes(), getPropertyTypes() are deprecatedmakeWritable() (#244)wrap() method (#180)Arrays::insertAfter() & insertBefore() fixed when $key is nullDateTime::fromParts() is non-locale aware #248first(), last() & contains()invoke() & invokeMethod()toAscii() fixed to correctly convert german umlauts (BC break) (#240)For the details you can have a look at the diff.
getReturnTypes(), getParameterTypes() and getPropertyTypes()getReturnType(), getParameterType() and getPropertyType() throws exception on union typesfromString() throws UnknownImageFileException when file type is unknownFor the details you can have a look at the diff.
fromString() throws UnknownImageFileException when file type is unknownFor the details you can have a look at the diff.
getText() decodes 'For the details you can have a look at the diff.
renameKey() fixed incorrect replacement for existing new keys #230renameKey() returns true if $oldKey was foundtoKey()isBuiltinType() added PHP 8 types mixed & falsegetReturnType() fixed for functionsFor the details you can have a look at the diff.
getMethodDeclaringMethod()toAscii() removes non-ascii characters when iconv is not supported #216For the details you can have a look at the diff.
How can I help you explore Laravel packages today?