Componette

Componette

nette

nette / utils v4.0.5

🛠 Lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating…

download-cloud-line composer require nette/utils

Nette Utils

Downloads this Month Tests Coverage Status Latest Stable Version License

Introduction

In package nette/utils you will find a set of useful classes for everyday use:

Arrays
Callback - PHP callbacks
Filesystem - copying, renaming, …
Finder - finds files and directories
Floats - floating point numbers
Helper Functions
HTML elements - generate HTML
Images - crop, resize, rotate images
Iterables
JSON - encoding and decoding
Generating Random Strings
Paginator - pagination math
PHP Reflection
Strings - useful text functions
SmartObject - PHP object enhancements
Type - PHP data type
Validation - validate inputs

 

Installation

The recommended way to install is via Composer:

composer require nette/utils

Nette Utils 4.0 is compatible with PHP 8.0 to 8.4.

 

Do you like Nette Utils? Are you looking forward to the new features?

Buy me a coffee

Thank you!

  • v4.0.5 Released version 4.0.5

    • Strings::matchAll(): added option 'lazy'
    • added Arrays::mapWithKeys() & Iterables::mapWithKeys()
    • added Iterables::memoize() & toIterator()
    • Image: GD extension detection added
    • support for PHP 8.4
  • v4.0.4 Released version 4.0.4

    • added Iterables
    • added Arrays::firstKey(), lastKey()
    • added Arrays::filter()
    • Arrays::first() & last(): added parameter $else
    • Arrays::first() & last(): added parameter $predicate #305
    • added Image::getSupportedTypes()
    • Arrays: improved phpDoc
    • utilizes Random\Randomizer in PHP 8.3
    • StaticClass: fixed compatibility with PHP 8.3.2
    • Strings::trim() trims unicode spaces and ZWSP (#304)
  • v4.0.3 Released version 4.0.3

    • added ImageColor, replaces Image::rgb()
    • added Image::rectangleWH(), filledRectangleWH(), calculateTextBox()
    • Type: fixed resolving of 'static' nette/di#295
  • v4.0.2 Released version 4.0.2

    • Strings::length() uses mbstring, iconv and then utf8_decode #299
    • Finder: getType() replaced with isDir() / isFile()
    • StaticClass: constructor is private nette/di#292
    • Arrays: add generic type declaration for some(), every() and map() (#298)
    • FileSystem: can be used as instance
  • v3.2.10 Released version 3.2.10

    • support for PHP 8.3
    • Callback::unwrap() returns correct class name for private methods
    • improved type annotations (#290)
    • Reflection: getParameterType(), getReturnType() and getPropertyType() marked as deprecated
  • v4.0.1 Released version 4.0.1

    • support for PHP 8.3
    • added Image::isTypeSupported()
    • added enum ImageType
    • Finder: collect() returns list
    • Finder: improved exception when directory is missing
    • Finder: default mask is '*'
    • improved type annotations (#290)
    • Callback::unwrap() returns correct class name for private methods
  • v4.0.0 Released version 4.0.0 🥳

    • uses PHP 8 featurs
    • includes a completely rewritten Finder
    • PascalCase constants
    • Strings: added support for UTF-8 offsets in regexp
    • Translator: improved interface, accepts and returns string|Stringable [Closes #231]
    • ArrayHash & ArrayList: support iteration with reference (#289)

    new methods:

    • Nette\Utils\Json::decodeFile() reads JSON from a file
    • Nette\Utils\FileSystem::unixSlashes() & platformSlashes() converts slashes to Unix slashes
    • Nette\Utils\Strings::ord(), unixNewLines() & platformNewLines()
    • Nette\Utils\Helpers::compare() compare using the operator

    new parameters:

    • Nette\Utils\Strings::split() added parameter $limit
    • Nette\Utils\Strings::replace() added parameters $captureOffset, $unmatchedAsNull
    • Nette\Utils\Strings, Nette\Utils\Arrays, Nette\Utils\Json: flags replaced with parameters

    removed

    • Reflection: removed obsolete getReturnType(), getParameterType(), getPropertyType() (BC break)
  • v3.2.9 Released version 3.1.9

    • Type: supports Disjunctive Normal Form Types
    • Validators: added isTypeDeclaration(), isBuiltinType(), isClassKeyword()
    • used PhpStorm Language attribute (#277)
    • Types::isSingle() -> isSimple()
  • v3.2.8 Released version 3.2.8

    • support for PHP 8.2
    • tests: deprecated GD changed to PNG
    • Image::clone() uses PNG format because GD2 is disabled since libgd 2.3.3
    • Image::detectTypeFromFile & detectTypeFromString returns width & height
    • Image: added extensionToType()
    • private constants are PascalCase
    • ObjectHelpers: fixed parsing static @methods #278
  • v3.2.7 Released version 3.2.7

    • SmartObject: supports property deprecation
    • Image: added support for AVIF
    • Image: distinguishes between fatal errors and warnings
    • Validators: isNumeric support string number '1.' (#276)
    • Json: accepts native JSON_* constants #275
    • Arrays::isList() uses array_is_list() is PHP 8.1

    Deprecated properties are written as @property-deprecated, no standard here exists. PhpStorm and static analysis tools do not see them, which is the intention.

  • v3.2.6 Released version 3.2.6

    • FileSystem: messages use normalized paths (#250)
    • Strings::indexOf() fixed empty $haystack and negative $nth #271
    • Strings: improved things around flags
    • Callback::unwrap can return non-callable #270
    • used @return never
    • added Helpers::clamp()
    • Validators::isPhpIdentifier(): Value is always string. (#268)
    • Reflection::expandClassName() recognizes 'parent'
    • added Reflection::isClassKeyword(), Type::isClassKeyword()
  • v3.2.5 Released version 3.2.5

    • support for PHP 8.1
    • added Type
    • Type, Reflection: supports intersection types
    • Reflection::getReturnType() & Type::fromReflection() return tentative type in PHP 8.1
    • Reflection::getUseStatements supports enums
    • Reflection: added 'never' built-in type
    • Reflection: getReturnTypes(), getParameterTypes(), getPropertyTypes() are deprecated
    • improved phpDoc, used generics
    • added ArrayList::from()
  • v3.1.6 Released version 3.1.6 (end of life)

    • added Type
    • improved phpDoc, used generics
    • Strings::replace: default replacement is empty string #241
    • Reflection: getReturnTypes(), getParameterTypes(), getPropertyTypes() are deprecated
  • v3.2.3 Released version 3.2.3

    • FileSystem: Add method makeWritable() (#244)
    • Paginator: add firstItemOnPage & lastItemOnPage #262 (#263)
    • ObjectHelpers: improved error messages, added scope
  • v3.2.2 Released version 3.2.2

    • Arrays: added wrap() method (#180)
    • Arrays::insertAfter() & insertBefore() fixed when $key is null
    • DateTime::fromParts() is non-locale aware #248
    • compatibility: improved code hinting
  • v3.2.1 Released version 3.2.1

    • added Arrays::first(), last() & contains()
    • added Array::invoke() & invokeMethod()
    • Arrays: some methods accepts iterable
    • Strings::toAscii() fixed to correctly convert german umlauts (BC break) (#240)
    • Strings::replace: default replacement is empty string #241

    For the details you can have a look at the diff.

  • v3.2.0 Released version 3.2.0

    • requires PHP 7.2
    • Added Nette\Utils\Floats class for comparing floats (#221)
    • Arrays: searchKey() silently renamed to getKeyOffset()
    • Callback::closure() triggers deprecation notice
    • Image: added detectTypeFromFile() and detectTypeFromString()
    • Reflection::toString() appends () after function/method name
    • Strings::toAscii - triggers E_USER_NOTICE when ext-intl is not present
    • renamed Nette\Localization\ITranslator -> Translator, added class alias
    • renamed Nette\Utils\IHtmlString -> Nette\HtmlStringable, added class alias
  • v3.1.4 Released version 3.1.4

    • Reflection: added getReturnTypes(), getParameterTypes() and getPropertyTypes()
    • Reflection::getReturnType(), getParameterType() and getPropertyType() throws exception on union types
    • Image::fromString() throws UnknownImageFileException when file type is unknown

    For the details you can have a look at the diff.

  • v3.0.4 Released version 3.0.4

    • compatible with PHP 8.0
    • Image::fromString() throws UnknownImageFileException when file type is unknown
    • Image: better processing and checking dimensions in strings #217
    • DateTime::from(null) fixed #211

    For the details you can have a look at the diff.

  • v2.5.5 Released version 2.5.5

    • compatible with PHP 8.0
    • Image: better processing and checking dimensions in strings #217
    • Html::getText() decodes '

    For the details you can have a look at the diff.

  • v3.1.3 Released version 3.1.3

    • compatible with PHP 8.0
    • Arrays::renameKey() fixed incorrect replacement for existing new keys #230
    • Arrays::renameKey() returns true if $oldKey was found
    • Arrays: added toKey()
    • improved PHP doc
    • Reflection: fixed parseUseStatements for PHP 8 #229
    • SmartObject: better support for $onEvent with typehint
    • Image: added new PHP functions
    • Strings: ICONV_IMPL can be quoted
    • FileSystem: Added $mode to all exceptions.
    • Image: compatibility with PHP 8.0
    • Reflection: added PHP 8 type 'static'
    • Reflection::isBuiltinType() added PHP 8 types mixed & false
    • Reflection::getReturnType() fixed for functions
    • SmartObject: removed return void

    For the details you can have a look at the diff.

  • v3.1.2 Released version 3.1.2

    • Image: better processing and checking dimensions in strings #217
    • added Reflection::getMethodDeclaringMethod()
    • Strings: throws exception when iconv is missing #215
    • Strings::toAscii() removes non-ascii characters when iconv is not supported #216

    For the details you can have a look at the diff.

  • v3.1.1 Released version 3.1.1

    • Reflection::getParameterDefaultValue() supports parent::CONST nette/di#231
    • improved phpDoc
    • Image: added typeToExtension() & typeToMimeType()
    • Reflection: ensures that getType() returns ReflectionNamedType
    • Json: missing @throws JsonException (#212)
    • Image: added imagecrop() workaround because it loses transparency on ubuntu on Github Actions
    • DateTime::from(null) fixed #211
    • Html::htmlToText() decodes '
    • Strings::toAscii - simplified process when Transliterate is available

    For the details you can have a look at the diff.

  • v3.1.0 Released version 3.1.0

    • Strings::toAscii transliterates я/ю as ya/yu [Closes #203]
    • Helpers: added capture(), falseToNull(), getLastError(), getSuggestion()
    • FileSystem: added joinPaths(), normalizePath()
    • Strings, Validator: throw exception on invalid regexp patterns / malformed input
    • Strings: throw exception on malformed UTF-8 in webalize() and to… (#205)
    • Html: added helper htmlToText()
    • Html: added fromText() & fromHtml(), toText() & toHtml()
    • Image: added support for BMP
  • v3.0.3 Released version 3.0.3

    • Strings: Fix boolean return of Normalizer. (#210)
    • Html: added @​property & @​method
    • phpStan fixes
    • Image: muted warnings
    • Image: added new PHP 7.2 functions

    For the details you can have a look at the diff.

  • v2.5.4 Released version 2.5.4

    • supports PHP 7.4
    • throwing exceptions from __toString() is allowed since PHP 7.4
    • LegacyObject: removed deprecation warning for extension methods
    • added PhpStorm metadata for autocompletion

    For the details you can have a look at the diff.

  • v3.0.2 Released version 3.0.2

    • Image: fixed lost of alpha after imagecrop() #202
    • Validators: accepts URL "https://example.com/?query" #190
    • composer: added suggestion for tokenizer #187
    • Json: added ESCAPE_UNICODE
    • throwing exceptions from __toString() is allowed since PHP 7.4
    • tested against PHP 7.4
    • regexp: \z replaced with D modifier
    • FileSystem: copy: Add binary safe parameter
    • Strings: Optimalize strlen() for better performance. (#193)

    For the details you can have a look at the diff.

  • v3.0.1 Released version 3.0.1

    • Reflection::getUseStatements() throw exceptions on anonymous class
    • Reflection: added 'null' to builtin types (in fact it is reserved type since PHP 7.0)
    • added Reflection::getPropertyType() (for PHP 7.4)
    • Validators: better exception message
    • Validators: added 'file', 'directory', 'class', 'interface' & mixed
    • Validators: added support for ?nullable types
    • Validators: grouped & sorted $validators
    • Validators: catches TypeError for incompatible types
    • Validator:: accepts the plus character as a valid option in numeric strings (#184)
    • added Arrays::toObject()
    • Image: fixed empty error_get_last() #183

    For the details you can have a look at the diff.

  • v3.0.0 Released version 3.0.0 🎉

    • requires PHP 7.1
    • uses declare(strict_types=1)
    • uses PHP 7.1 scalar and return type hints
    • Object, ObjectMixin: silently marked as deprecated
    • added PhpStorm metadata for autocompletion

    Changes

    • Strings::before(), after(), indexOf() and pos() return NULL instead of FALSE if the needle was not found
    • Arrays::searchKey() returns NULL instead of FALSE when item is not found
    • Image::save() and send() throws ImageException on failure (BC break)
    • Validators::assertField: first argument has type hint array
    • Callback::toReflection() removed support for Nette\Reflection
    • some classes & members marked as final
    • ITranslator: allow multiple parameters for translated messages (#178)
    • deprecated ObjectMixin::getSuggestion()
    • MemberAccessException extends from Error (BC break)
    • removed StaticClassException, StaticClass throws Error
    • Image::save() $file cannot be null, added output()
    • DateTime: removed setTimestamp() and getTimestamp(), big int are supported in x64 PHP versions
    • Strings::findPrefix accepts only string[] (BC break)
    • Removed Nette\Object & ObjectMixin (BC break)
    • Callback::invoke() and invokeArgs() are deprecated in favor of native invocation
    • Callback: deprecated closure()
    • Validators::everyIs: first argument has typehint iterable (BC break)
    • Strings::normalize() a compare() dependency on Normalizer is optional
    • Strings::normalize() a compare() normalize strings into UTF-8 NFC (#150)
    • Filesystem::write() accept NULL in $mode parameter (#139)
  • v2.5.3 Released version 2.5.3

    • Callback: removes HTML from error message nette/mail#54
    • test: fixed compatiblity with PHP 7.3
    • Callback: fixed bug in is_callable($object, true) #176
    • Reflection: token_get_all() uses flag TOKEN_PARSE
    • FileSystem: better error messages

    For the details you can have a look at the diff.

Componette Componette felix@nette.org