code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public static function makeWritable(string $path, int $dirMode = 0777, int $fileMode = 0666): void { if (is_file($path)) { if (!@chmod($path, $fileMode)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to chmod file '%s' to mode %s. %s", self::normalizePath($path), decoct($fileMode), Helpers::getLastError(), )); } } elseif (is_dir($path)) { foreach (new \FilesystemIterator($path) as $item) { static::makeWritable($item->getPathname(), $dirMode, $fileMode); } if (!@chmod($path, $dirMode)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to chmod directory '%s' to mode %s. %s", self::normalizePath($path), decoct($dirMode), Helpers::getLastError(), )); } } else { throw new Nette\IOException(sprintf("File or directory '%s' not found.", self::normalizePath($path))); } }
Sets file permissions to `$fileMode` or directory permissions to `$dirMode`. Recursively traverses and sets permissions on the entire contents of the directory as well. @throws Nette\IOException on error occurred
makeWritable
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function isAbsolute(string $path): bool { return (bool) preg_match('#([a-z]:)?[/\\\\]|[a-z][a-z0-9+.-]*://#Ai', $path); }
Determines if the path is absolute.
isAbsolute
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function normalizePath(string $path): string { $parts = $path === '' ? [] : preg_split('~[/\\\\]+~', $path); $res = []; foreach ($parts as $part) { if ($part === '..' && $res && end($res) !== '..' && end($res) !== '') { array_pop($res); } elseif ($part !== '.') { $res[] = $part; } } return $res === [''] ? DIRECTORY_SEPARATOR : implode(DIRECTORY_SEPARATOR, $res); }
Normalizes `..` and `.` and directory separators in path.
normalizePath
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function joinPaths(string ...$paths): string { return self::normalizePath(implode('/', $paths)); }
Joins all segments of the path and normalizes the result.
joinPaths
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function platformSlashes(string $path): string { return DIRECTORY_SEPARATOR === '/' ? strtr($path, '\\', '/') : str_replace(':\\\\', '://', strtr($path, '/', '\\')); // protocol:// }
Converts slashes to platform-specific directory separators.
platformSlashes
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function find(string|array $masks = ['*']): static { $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'dir')->addMask($masks, 'file'); }
Begins search for files and directories matching mask.
find
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public static function findFiles(string|array $masks = ['*']): static { $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'file'); }
Begins search for files matching mask.
findFiles
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public static function findDirectories(string|array $masks = ['*']): static { $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'dir'); }
Begins search for directories matching mask.
findDirectories
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function files(string|array $masks = ['*']): static { return $this->addMask((array) $masks, 'file'); }
Finds files matching the specified masks.
files
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function directories(string|array $masks = ['*']): static { return $this->addMask((array) $masks, 'dir'); }
Finds directories matching the specified masks.
directories
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function in(string|array $paths): static { $paths = is_array($paths) ? $paths : func_get_args(); // compatibility with variadic $this->addLocation($paths, ''); return $this; }
Searches in the given directories. Wildcards are allowed.
in
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function from(string|array $paths): static { $paths = is_array($paths) ? $paths : func_get_args(); // compatibility with variadic $this->addLocation($paths, '/**'); return $this; }
Searches recursively from the given directories. Wildcards are allowed.
from
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function childFirst(bool $state = true): static { $this->childFirst = $state; return $this; }
Lists directory's contents before the directory itself. By default, this is disabled.
childFirst
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function ignoreUnreadableDirs(bool $state = true): static { $this->ignoreUnreadableDirs = $state; return $this; }
Ignores unreadable directories. By default, this is enabled.
ignoreUnreadableDirs
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function sortBy(callable $callback): static { $this->sort = $callback; return $this; }
Set a compare function for sorting directory entries. The function will be called to sort entries from the same directory. @param callable(FileInfo, FileInfo): int $callback
sortBy
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function sortByName(): static { $this->sort = fn(FileInfo $a, FileInfo $b): int => strnatcmp($a->getBasename(), $b->getBasename()); return $this; }
Sorts files in each directory naturally by name.
sortByName
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function append(string|array|null $paths = null): static { if ($paths === null) { return $this->appends[] = new static; } $this->appends = array_merge($this->appends, (array) $paths); return $this; }
Adds the specified paths or appends a new finder that returns.
append
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function exclude(string|array $masks): static { $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic foreach ($masks as $mask) { $mask = FileSystem::unixSlashes($mask); if (!preg_match('~^/?(\*\*/)?(.+)(/\*\*|/\*|/|)$~D', $mask, $m)) { throw new Nette\InvalidArgumentException("Invalid mask '$mask'"); } $end = $m[3]; $re = $this->buildPattern($m[2]); $filter = fn(FileInfo $file): bool => ($end && !$file->isDir()) || !preg_match($re, FileSystem::unixSlashes($file->getRelativePathname())); $this->descentFilter($filter); if ($end !== '/*') { $this->filter($filter); } } return $this; }
Skips entries that matches the given masks relative to the ones defined with the in() or from() methods.
exclude
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function filter(callable $callback): static { $this->filters[] = \Closure::fromCallable($callback); return $this; }
Yields only entries which satisfy the given filter. @param callable(FileInfo): bool $callback
filter
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function descentFilter(callable $callback): static { $this->descentFilters[] = \Closure::fromCallable($callback); return $this; }
It descends only to directories that match the specified filter. @param callable(FileInfo): bool $callback
descentFilter
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function limitDepth(?int $depth): static { $this->maxDepth = $depth ?? -1; return $this; }
Sets the maximum depth of entries.
limitDepth
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function size(string $operator, ?int $size = null): static { if (func_num_args() === 1) { // in $operator is predicate if (!preg_match('#^(?:([=<>!]=?|<>)\s*)?((?:\d*\.)?\d+)\s*(K|M|G|)B?$#Di', $operator, $matches)) { throw new Nette\InvalidArgumentException('Invalid size predicate format.'); } [, $operator, $size, $unit] = $matches; $units = ['' => 1, 'k' => 1e3, 'm' => 1e6, 'g' => 1e9]; $size *= $units[strtolower($unit)]; $operator = $operator ?: '='; } return $this->filter(fn(FileInfo $file): bool => !$file->isFile() || Helpers::compare($file->getSize(), $operator, $size)); }
Restricts the search by size. $operator accepts "[operator] [size] [unit]" example: >=10kB
size
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function date(string $operator, string|int|\DateTimeInterface|null $date = null): static { if (func_num_args() === 1) { // in $operator is predicate if (!preg_match('#^(?:([=<>!]=?|<>)\s*)?(.+)$#Di', $operator, $matches)) { throw new Nette\InvalidArgumentException('Invalid date predicate format.'); } [, $operator, $date] = $matches; $operator = $operator ?: '='; } $date = DateTime::from($date)->format('U'); return $this->filter(fn(FileInfo $file): bool => !$file->isFile() || Helpers::compare($file->getMTime(), $operator, $date)); }
Restricts the search by modified time. $operator accepts "[operator] [date]" example: >1978-01-23
date
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function collect(): array { return iterator_to_array($this->getIterator(), preserve_keys: false); }
Returns an array with all found files and directories. @return list<FileInfo>
collect
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
private function traverseDir(string $dir, array $searches, array $subdirs = []): \Generator { if ($this->maxDepth >= 0 && count($subdirs) > $this->maxDepth) { return; } elseif (!is_dir($dir)) { throw new Nette\InvalidStateException(sprintf("Directory '%s' does not exist.", rtrim($dir, '/\\'))); } try { $pathNames = new \FilesystemIterator($dir, \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::UNIX_PATHS); } catch (\UnexpectedValueException $e) { if ($this->ignoreUnreadableDirs) { return; } else { throw new Nette\InvalidStateException($e->getMessage()); } } $files = $this->convertToFiles($pathNames, implode('/', $subdirs), FileSystem::isAbsolute($dir)); if ($this->sort) { $files = iterator_to_array($files); usort($files, $this->sort); } foreach ($files as $file) { $pathName = $file->getPathname(); $cache = $subSearch = []; if ($file->isDir()) { foreach ($searches as $search) { if ($search->recursive && $this->proveFilters($this->descentFilters, $file, $cache)) { $subSearch[] = $search; } } } if ($this->childFirst && $subSearch) { yield from $this->traverseDir($pathName, $subSearch, array_merge($subdirs, [$file->getBasename()])); } $relativePathname = FileSystem::unixSlashes($file->getRelativePathname()); foreach ($searches as $search) { if ( $file->{'is' . $search->mode}() && preg_match($search->pattern, $relativePathname) && $this->proveFilters($this->filters, $file, $cache) ) { yield $pathName => $file; break; } } if (!$this->childFirst && $subSearch) { yield from $this->traverseDir($pathName, $subSearch, array_merge($subdirs, [$file->getBasename()])); } } }
@param array<object{pattern: string, mode: string, recursive: bool}> $searches @param string[] $subdirs @return \Generator<string, FileInfo>
traverseDir
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
private function buildPlan(): array { $plan = $dirCache = []; foreach ($this->find as [$mask, $mode]) { $splits = []; if (FileSystem::isAbsolute($mask)) { if ($this->in) { throw new Nette\InvalidStateException("You cannot combine the absolute path in the mask '$mask' and the directory to search '{$this->in[0]}'."); } $splits[] = self::splitRecursivePart($mask); } else { foreach ($this->in ?: ['.'] as $in) { $in = strtr($in, ['[' => '[[]', ']' => '[]]']); // in path, do not treat [ and ] as a pattern by glob() $splits[] = self::splitRecursivePart($in . '/' . $mask); } } foreach ($splits as [$base, $rest, $recursive]) { $base = $base === '' ? '.' : $base; $dirs = $dirCache[$base] ??= strpbrk($base, '*?[') ? glob($base, GLOB_NOSORT | GLOB_ONLYDIR | GLOB_NOESCAPE) : [strtr($base, ['[[]' => '[', '[]]' => ']'])]; // unescape [ and ] if (!$dirs) { throw new Nette\InvalidStateException(sprintf("Directory '%s' does not exist.", rtrim($base, '/\\'))); } $search = (object) ['pattern' => $this->buildPattern($rest), 'mode' => $mode, 'recursive' => $recursive]; foreach ($dirs as $dir) { $plan[$dir][] = $search; } } } return $plan; }
@return array<string, array<object{pattern: string, mode: string, recursive: bool}>>
buildPlan
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
private static function splitRecursivePart(string $path): array { $a = strrpos($path, '/'); $parts = preg_split('~(?<=^|/)\*\*($|/)~', substr($path, 0, $a + 1), 2); return isset($parts[1]) ? [$parts[0], $parts[1] . substr($path, $a + 1), true] : [$parts[0], substr($path, $a + 1), false]; }
Since glob() does not know ** wildcard, we divide the path into a part for glob and a part for manual traversal.
splitRecursivePart
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public static function compare(float $a, float $b): int { if (is_nan($a) || is_nan($b)) { throw new \LogicException('Trying to compare NAN'); } elseif (!is_finite($a) && !is_finite($b) && $a === $b) { return 0; } $diff = abs($a - $b); if (($diff < self::Epsilon || ($diff / max(abs($a), abs($b)) < self::Epsilon))) { return 0; } return $a < $b ? -1 : 1; }
Compare two floats. If $a < $b it returns -1, if they are equal it returns 0 and if $a > $b it returns 1 @throws \LogicException if one of parameters is NAN
compare
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function areEqual(float $a, float $b): bool { return self::compare($a, $b) === 0; }
Returns true if $a = $b @throws \LogicException if one of parameters is NAN
areEqual
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function isLessThan(float $a, float $b): bool { return self::compare($a, $b) < 0; }
Returns true if $a < $b @throws \LogicException if one of parameters is NAN
isLessThan
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function isLessThanOrEqualTo(float $a, float $b): bool { return self::compare($a, $b) <= 0; }
Returns true if $a <= $b @throws \LogicException if one of parameters is NAN
isLessThanOrEqualTo
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function isGreaterThan(float $a, float $b): bool { return self::compare($a, $b) > 0; }
Returns true if $a > $b @throws \LogicException if one of parameters is NAN
isGreaterThan
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function isGreaterThanOrEqualTo(float $a, float $b): bool { return self::compare($a, $b) >= 0; }
Returns true if $a >= $b @throws \LogicException if one of parameters is NAN
isGreaterThanOrEqualTo
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function capture(callable $func): string { ob_start(function () {}); try { $func(); return ob_get_clean(); } catch (\Throwable $e) { ob_end_clean(); throw $e; } }
Executes a callback and returns the captured output as a string.
capture
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
BSD-3-Clause
public static function getLastError(): string { $message = error_get_last()['message'] ?? ''; $message = ini_get('html_errors') ? Html::htmlToText($message) : $message; $message = preg_replace('#^\w+\(.*?\): #', '', $message); return $message; }
Returns the last occurred PHP error or an empty string if no error occurred. Unlike error_get_last(), it is nit affected by the PHP directive html_errors and always returns text, not HTML.
getLastError
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
BSD-3-Clause
public static function falseToNull(mixed $value): mixed { return $value === false ? null : $value; }
Converts false to null, does not change other values.
falseToNull
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
BSD-3-Clause
public static function clamp(int|float $value, int|float $min, int|float $max): int|float { if ($min > $max) { throw new Nette\InvalidArgumentException("Minimum ($min) is not less than maximum ($max)."); } return min(max($value, $min), $max); }
Returns value clamped to the inclusive range of min and max.
clamp
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
BSD-3-Clause
public static function getSuggestion(array $possibilities, string $value): ?string { $best = null; $min = (strlen($value) / 4 + 1) * 10 + .1; foreach (array_unique($possibilities) as $item) { if ($item !== $value && ($len = levenshtein($item, $value, 10, 11, 10)) < $min) { $min = $len; $best = $item; } } return $best; }
Looks for a string from possibilities that is most similar to value, but not the same (for 8-bit encoding). @param string[] $possibilities
getSuggestion
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
BSD-3-Clause
public static function compare(mixed $left, string $operator, mixed $right): bool { return match ($operator) { '>' => $left > $right, '>=' => $left >= $right, '<' => $left < $right, '<=' => $left <= $right, '=', '==' => $left == $right, '===' => $left === $right, '!=', '<>' => $left != $right, '!==' => $left !== $right, default => throw new Nette\InvalidArgumentException("Unknown operator '$operator'"), }; }
Compares two values in the same way that PHP does. Recognizes operators: >, >=, <, <=, =, ==, ===, !=, !==, <>
compare
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
BSD-3-Clause
public static function el(?string $name = null, array|string|null $attrs = null): static { $el = new static; $parts = explode(' ', (string) $name, 2); $el->setName($parts[0]); if (is_array($attrs)) { $el->attrs = $attrs; } elseif ($attrs !== null) { $el->setText($attrs); } if (isset($parts[1])) { foreach (Strings::matchAll($parts[1] . ' ', '#([a-z0-9:-]+)(?:=(["\'])?(.*?)(?(2)\2|\s))?#i') as $m) { $el->attrs[$m[1]] = $m[3] ?? true; } } return $el; }
Constructs new HTML element. @param array|string $attrs element's attributes or plain text content
el
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
public static function fromHtml(string $html): static { return (new static)->setHtml($html); }
Returns an object representing HTML text.
fromHtml
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
public static function fromText(string $text): static { return (new static)->setText($text); }
Returns an object representing plain text.
fromText
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
public static function htmlToText(string $html): string { return html_entity_decode(strip_tags($html), ENT_QUOTES | ENT_HTML5, 'UTF-8'); }
Converts given HTML code to plain text.
htmlToText
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
public function data(string $name, mixed $value = null): static { if (func_num_args() === 1) { $this->attrs['data'] = $name; } else { $this->attrs["data-$name"] = is_bool($value) ? json_encode($value) : $value; } return $this; }
Setter for data-* attributes. Booleans are converted to 'true' resp. 'false'.
data
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
public function addText(mixed $text): static { if (!$text instanceof HtmlStringable) { $text = htmlspecialchars((string) $text, ENT_NOQUOTES, 'UTF-8'); } return $this->insert(null, $text); }
Appends plain-text string to element content.
addText
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
final public function create(string $name, array|string|null $attrs = null): static { $this->insert(null, $child = static::el($name, $attrs)); return $child; }
Creates and adds a new Html child.
create
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
final public function offsetSet($index, $child): void { $this->insert($index, $child, replace: true); }
Inserts (replaces) child node (\ArrayAccess implementation). @param int|null $index position or null for appending @param Html|string $child Html node or raw HTML string
offsetSet
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
final public function offsetGet($index): HtmlStringable|string { return $this->children[$index]; }
Returns child node (\ArrayAccess implementation). @param int $index
offsetGet
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
final public function offsetExists($index): bool { return isset($this->children[$index]); }
Exists child node? (\ArrayAccess implementation). @param int $index
offsetExists
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
public function offsetUnset($index): void { if (isset($this->children[$index])) { array_splice($this->children, $index, 1); } }
Removes child node (\ArrayAccess implementation). @param int $index
offsetUnset
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
final public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->children); }
Iterates over elements. @return \ArrayIterator<int, HtmlStringable|string>
getIterator
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
final public function render(?int $indent = null): string { $s = $this->startTag(); if (!$this->isEmpty) { // add content if ($indent !== null) { $indent++; } foreach ($this->children as $child) { if ($child instanceof self) { $s .= $child->render($indent); } else { $s .= $child; } } // add end tag $s .= $this->endTag(); } if ($indent !== null) { return "\n" . str_repeat("\t", $indent - 1) . $s . "\n" . str_repeat("\t", max(0, $indent - 2)); } return $s; }
Renders element's start tag, content and end tag.
render
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
BSD-3-Clause
public static function rgb(int $red, int $green, int $blue, int $transparency = 0): array { return [ 'red' => max(0, min(255, $red)), 'green' => max(0, min(255, $green)), 'blue' => max(0, min(255, $blue)), 'alpha' => max(0, min(127, $transparency)), ]; }
Returns RGB color (0..255) and transparency (0..127). @deprecated use ImageColor::rgb()
rgb
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function fromFile(string $file, ?int &$type = null): static { self::ensureExtension(); $type = self::detectTypeFromFile($file); if (!$type) { throw new UnknownImageFileException(is_file($file) ? "Unknown type of file '$file'." : "File '$file' not found."); } return self::invokeSafe('imagecreatefrom' . self::Formats[$type], $file, "Unable to open file '$file'.", __METHOD__); }
Reads an image from a file and returns its type in $type. @throws Nette\NotSupportedException if gd extension is not loaded @throws UnknownImageFileException if file not found or file type is not known
fromFile
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function fromString(string $s, ?int &$type = null): static { self::ensureExtension(); $type = self::detectTypeFromString($s); if (!$type) { throw new UnknownImageFileException('Unknown type of image.'); } return self::invokeSafe('imagecreatefromstring', $s, 'Unable to open image from string.', __METHOD__); }
Reads an image from a string and returns its type in $type. @throws Nette\NotSupportedException if gd extension is not loaded @throws ImageException
fromString
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function fromBlank(int $width, int $height, ImageColor|array|null $color = null): static { self::ensureExtension(); if ($width < 1 || $height < 1) { throw new Nette\InvalidArgumentException('Image width and height must be greater than zero.'); } $image = new static(imagecreatetruecolor($width, $height)); if ($color) { $image->alphablending(false); $image->filledrectangle(0, 0, $width - 1, $height - 1, $color); $image->alphablending(true); } return $image; }
Creates a new true color image of the given dimensions. The default color is black. @param positive-int $width @param positive-int $height @throws Nette\NotSupportedException if gd extension is not loaded
fromBlank
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function detectTypeFromFile(string $file, &$width = null, &$height = null): ?int { [$width, $height, $type] = @getimagesize($file); // @ - files smaller than 12 bytes causes read error return isset(self::Formats[$type]) ? $type : null; }
Returns the type of image from file. @return ImageType::*|null
detectTypeFromFile
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function detectTypeFromString(string $s, &$width = null, &$height = null): ?int { [$width, $height, $type] = @getimagesizefromstring($s); // @ - strings smaller than 12 bytes causes read error return isset(self::Formats[$type]) ? $type : null; }
Returns the type of image from string. @return ImageType::*|null
detectTypeFromString
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function typeToExtension(int $type): string { if (!isset(self::Formats[$type])) { throw new Nette\InvalidArgumentException("Unsupported image type '$type'."); } return self::Formats[$type]; }
Returns the file extension for the given image type. @param ImageType::* $type @return value-of<self::Formats>
typeToExtension
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function extensionToType(string $extension): int { $extensions = array_flip(self::Formats) + ['jpg' => ImageType::JPEG]; $extension = strtolower($extension); if (!isset($extensions[$extension])) { throw new Nette\InvalidArgumentException("Unsupported file extension '$extension'."); } return $extensions[$extension]; }
Returns the image type for given file extension. @return ImageType::*
extensionToType
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function typeToMimeType(int $type): string { return 'image/' . self::typeToExtension($type); }
Returns the mime type for the given image type. @param ImageType::* $type
typeToMimeType
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public function getWidth(): int { return imagesx($this->image); }
Returns image width. @return positive-int
getWidth
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public function getHeight(): int { return imagesy($this->image); }
Returns image height. @return positive-int
getHeight
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public function resize(int|string|null $width, int|string|null $height, int $mode = self::OrSmaller): static { if ($mode & self::Cover) { return $this->resize($width, $height, self::OrBigger)->crop('50%', '50%', $width, $height); } [$newWidth, $newHeight] = static::calculateSize($this->getWidth(), $this->getHeight(), $width, $height, $mode); if ($newWidth !== $this->getWidth() || $newHeight !== $this->getHeight()) { // resize $newImage = static::fromBlank($newWidth, $newHeight, ImageColor::rgb(0, 0, 0, 0))->getImageResource(); imagecopyresampled( $newImage, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $this->getWidth(), $this->getHeight(), ); $this->image = $newImage; } if ($width < 0 || $height < 0) { imageflip($this->image, $width < 0 ? ($height < 0 ? IMG_FLIP_BOTH : IMG_FLIP_HORIZONTAL) : IMG_FLIP_VERTICAL); } return $this; }
Scales an image. Width and height accept pixels or percent. @param int-mask-of<self::OrSmaller|self::OrBigger|self::Stretch|self::Cover|self::ShrinkOnly> $mode
resize
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function calculateSize( int $srcWidth, int $srcHeight, $newWidth, $newHeight, int $mode = self::OrSmaller, ): array { if ($newWidth === null) { } elseif (self::isPercent($newWidth)) { $newWidth = (int) round($srcWidth / 100 * abs($newWidth)); $percents = true; } else { $newWidth = abs($newWidth); } if ($newHeight === null) { } elseif (self::isPercent($newHeight)) { $newHeight = (int) round($srcHeight / 100 * abs($newHeight)); $mode |= empty($percents) ? 0 : self::Stretch; } else { $newHeight = abs($newHeight); } if ($mode & self::Stretch) { // non-proportional if (!$newWidth || !$newHeight) { throw new Nette\InvalidArgumentException('For stretching must be both width and height specified.'); } if ($mode & self::ShrinkOnly) { $newWidth = min($srcWidth, $newWidth); $newHeight = min($srcHeight, $newHeight); } } else { // proportional if (!$newWidth && !$newHeight) { throw new Nette\InvalidArgumentException('At least width or height must be specified.'); } $scale = []; if ($newWidth > 0) { // fit width $scale[] = $newWidth / $srcWidth; } if ($newHeight > 0) { // fit height $scale[] = $newHeight / $srcHeight; } if ($mode & self::OrBigger) { $scale = [max($scale)]; } if ($mode & self::ShrinkOnly) { $scale[] = 1; } $scale = min($scale); $newWidth = (int) round($srcWidth * $scale); $newHeight = (int) round($srcHeight * $scale); } return [max($newWidth, 1), max($newHeight, 1)]; }
Calculates dimensions of resized image. Width and height accept pixels or percent. @param int-mask-of<self::OrSmaller|self::OrBigger|self::Stretch|self::Cover|self::ShrinkOnly> $mode
calculateSize
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public function crop(int|string $left, int|string $top, int|string $width, int|string $height): static { [$r['x'], $r['y'], $r['width'], $r['height']] = static::calculateCutout($this->getWidth(), $this->getHeight(), $left, $top, $width, $height); if (gd_info()['GD Version'] === 'bundled (2.1.0 compatible)') { $this->image = imagecrop($this->image, $r); imagesavealpha($this->image, true); } else { $newImage = static::fromBlank($r['width'], $r['height'], ImageColor::rgb(0, 0, 0, 0))->getImageResource(); imagecopy($newImage, $this->image, 0, 0, $r['x'], $r['y'], $r['width'], $r['height']); $this->image = $newImage; } return $this; }
Crops image. Arguments accepts pixels or percent.
crop
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function calculateCutout( int $srcWidth, int $srcHeight, int|string $left, int|string $top, int|string $newWidth, int|string $newHeight, ): array { if (self::isPercent($newWidth)) { $newWidth = (int) round($srcWidth / 100 * $newWidth); } if (self::isPercent($newHeight)) { $newHeight = (int) round($srcHeight / 100 * $newHeight); } if (self::isPercent($left)) { $left = (int) round(($srcWidth - $newWidth) / 100 * $left); } if (self::isPercent($top)) { $top = (int) round(($srcHeight - $newHeight) / 100 * $top); } if ($left < 0) { $newWidth += $left; $left = 0; } if ($top < 0) { $newHeight += $top; $top = 0; } $newWidth = min($newWidth, $srcWidth - $left); $newHeight = min($newHeight, $srcHeight - $top); return [$left, $top, $newWidth, $newHeight]; }
Calculates dimensions of cutout in image. Arguments accepts pixels or percent.
calculateCutout
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public function place(self $image, int|string $left = 0, int|string $top = 0, int $opacity = 100): static { $opacity = max(0, min(100, $opacity)); if ($opacity === 0) { return $this; } $width = $image->getWidth(); $height = $image->getHeight(); if (self::isPercent($left)) { $left = (int) round(($this->getWidth() - $width) / 100 * $left); } if (self::isPercent($top)) { $top = (int) round(($this->getHeight() - $height) / 100 * $top); } $output = $input = $image->image; if ($opacity < 100) { $tbl = []; for ($i = 0; $i < 128; $i++) { $tbl[$i] = round(127 - (127 - $i) * $opacity / 100); } $output = imagecreatetruecolor($width, $height); imagealphablending($output, false); if (!$image->isTrueColor()) { $input = $output; imagefilledrectangle($output, 0, 0, $width, $height, imagecolorallocatealpha($output, 0, 0, 0, 127)); imagecopy($output, $image->image, 0, 0, 0, 0, $width, $height); } for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $c = \imagecolorat($input, $x, $y); $c = ($c & 0xFFFFFF) + ($tbl[$c >> 24] << 24); \imagesetpixel($output, $x, $y, $c); } } imagealphablending($output, true); } imagecopy( $this->image, $output, $left, $top, 0, 0, $width, $height, ); return $this; }
Puts another image into this image. Left and top accepts pixels or percent. @param int<0, 100> $opacity 0..100
place
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function calculateTextBox( string $text, string $fontFile, float $size, float $angle = 0, array $options = [], ): array { self::ensureExtension(); $box = imagettfbbox($size, $angle, $fontFile, $text, $options); return [ 'left' => $minX = min([$box[0], $box[2], $box[4], $box[6]]), 'top' => $minY = min([$box[1], $box[3], $box[5], $box[7]]), 'width' => max([$box[0], $box[2], $box[4], $box[6]]) - $minX + 1, 'height' => max([$box[1], $box[3], $box[5], $box[7]]) - $minY + 1, ]; }
Calculates the bounding box for a TrueType text. Returns keys left, top, width and height.
calculateTextBox
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public function save(string $file, ?int $quality = null, ?int $type = null): void { $type ??= self::extensionToType(pathinfo($file, PATHINFO_EXTENSION)); $this->output($type, $quality, $file); }
Saves image to the file. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9). @param ImageType::*|null $type @throws ImageException
save
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public function toString(int $type = ImageType::JPEG, ?int $quality = null): string { return Helpers::capture(function () use ($type, $quality): void { $this->output($type, $quality); }); }
Outputs image to string. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9). @param ImageType::* $type
toString
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public function send(int $type = ImageType::JPEG, ?int $quality = null): void { header('Content-Type: ' . self::typeToMimeType($type)); $this->output($type, $quality); }
Outputs image to browser. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9). @param ImageType::* $type @throws ImageException
send
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
private function output(int $type, ?int $quality, ?string $file = null): void { switch ($type) { case ImageType::JPEG: $quality = $quality === null ? 85 : max(0, min(100, $quality)); $success = @imagejpeg($this->image, $file, $quality); // @ is escalated to exception break; case ImageType::PNG: $quality = $quality === null ? 9 : max(0, min(9, $quality)); $success = @imagepng($this->image, $file, $quality); // @ is escalated to exception break; case ImageType::GIF: $success = @imagegif($this->image, $file); // @ is escalated to exception break; case ImageType::WEBP: $quality = $quality === null ? 80 : max(0, min(100, $quality)); $success = @imagewebp($this->image, $file, $quality); // @ is escalated to exception break; case ImageType::AVIF: $quality = $quality === null ? 30 : max(0, min(100, $quality)); $success = @imageavif($this->image, $file, $quality); // @ is escalated to exception break; case ImageType::BMP: $success = @imagebmp($this->image, $file); // @ is escalated to exception break; default: throw new Nette\InvalidArgumentException("Unsupported image type '$type'."); } if (!$success) { throw new ImageException(Helpers::getLastError() ?: 'Unknown error'); } }
Outputs image to browser or file. @param ImageType::* $type @throws ImageException
output
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public function __call(string $name, array $args): mixed { $function = 'image' . $name; if (!function_exists($function)) { ObjectHelpers::strictCall(static::class, $name); } foreach ($args as $key => $value) { if ($value instanceof self) { $args[$key] = $value->getImageResource(); } elseif ($value instanceof ImageColor || (is_array($value) && isset($value['red']))) { $args[$key] = $this->resolveColor($value); } } $res = $function($this->image, ...$args); return $res instanceof \GdImage ? $this->setImageResource($res) : $res; }
Call to undefined method. @throws Nette\MemberAccessException
__call
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
BSD-3-Clause
public static function hex(string $hex): self { $hex = ltrim($hex, '#'); $len = strlen($hex); if ($len === 3 || $len === 4) { return new self( (int) hexdec($hex[0]) * 17, (int) hexdec($hex[1]) * 17, (int) hexdec($hex[2]) * 17, (int) hexdec($hex[3] ?? 'F') * 17 / 255, ); } elseif ($len === 6 || $len === 8) { return new self( (int) hexdec($hex[0] . $hex[1]), (int) hexdec($hex[2] . $hex[3]), (int) hexdec($hex[4] . $hex[5]), (int) hexdec(($hex[6] ?? 'F') . ($hex[7] ?? 'F')) / 255, ); } else { throw new Nette\InvalidArgumentException('Invalid hex color format.'); } }
Accepts formats #RRGGBB, #RRGGBBAA, #RGB, #RGBA
hex
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/ImageColor.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ImageColor.php
BSD-3-Clause
public static function contains(iterable $iterable, mixed $value): bool { foreach ($iterable as $v) { if ($v === $value) { return true; } } return false; }
Tests for the presence of value.
contains
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
BSD-3-Clause
public static function containsKey(iterable $iterable, mixed $key): bool { foreach ($iterable as $k => $v) { if ($k === $key) { return true; } } return false; }
Tests for the presence of key.
containsKey
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
BSD-3-Clause
public static function first(iterable $iterable, ?callable $predicate = null, ?callable $else = null): mixed { foreach ($iterable as $k => $v) { if (!$predicate || $predicate($v, $k, $iterable)) { return $v; } } return $else ? $else() : null; }
Returns the first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null. @template K @template V @param iterable<K, V> $iterable @param ?callable(V, K, iterable<K, V>): bool $predicate @return ?V
first
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
BSD-3-Clause
public static function firstKey(iterable $iterable, ?callable $predicate = null, ?callable $else = null): mixed { foreach ($iterable as $k => $v) { if (!$predicate || $predicate($v, $k, $iterable)) { return $k; } } return $else ? $else() : null; }
Returns the key of first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null. @template K @template V @param iterable<K, V> $iterable @param ?callable(V, K, iterable<K, V>): bool $predicate @return ?K
firstKey
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
BSD-3-Clause
public static function some(iterable $iterable, callable $predicate): bool { foreach ($iterable as $k => $v) { if ($predicate($v, $k, $iterable)) { return true; } } return false; }
Tests whether at least one element in the iterator passes the test implemented by the provided function. @template K @template V @param iterable<K, V> $iterable @param callable(V, K, iterable<K, V>): bool $predicate
some
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
BSD-3-Clause
public static function every(iterable $iterable, callable $predicate): bool { foreach ($iterable as $k => $v) { if (!$predicate($v, $k, $iterable)) { return false; } } return true; }
Tests whether all elements in the iterator pass the test implemented by the provided function. @template K @template V @param iterable<K, V> $iterable @param callable(V, K, iterable<K, V>): bool $predicate
every
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
BSD-3-Clause
public static function filter(iterable $iterable, callable $predicate): \Generator { foreach ($iterable as $k => $v) { if ($predicate($v, $k, $iterable)) { yield $k => $v; } } }
Iterator that filters elements according to a given $predicate. Maintains original keys. @template K @template V @param iterable<K, V> $iterable @param callable(V, K, iterable<K, V>): bool $predicate @return \Generator<K, V>
filter
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
BSD-3-Clause
public static function map(iterable $iterable, callable $transformer): \Generator { foreach ($iterable as $k => $v) { yield $k => $transformer($v, $k, $iterable); } }
Iterator that transforms values by calling $transformer. Maintains original keys. @template K @template V @template R @param iterable<K, V> $iterable @param callable(V, K, iterable<K, V>): R $transformer @return \Generator<K, R>
map
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
BSD-3-Clause
public static function mapWithKeys(iterable $iterable, callable $transformer): \Generator { foreach ($iterable as $k => $v) { $pair = $transformer($v, $k, $iterable); if ($pair) { yield $pair[0] => $pair[1]; } } }
Iterator that transforms keys and values by calling $transformer. If it returns null, the element is skipped. @template K @template V @template ResV @template ResK @param iterable<K, V> $iterable @param callable(V, K, iterable<K, V>): ?array{ResV, ResK} $transformer @return \Generator<ResV, ResK>
mapWithKeys
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
BSD-3-Clause
public static function memoize(iterable $iterable): iterable { return new class (self::toIterator($iterable)) implements \IteratorAggregate { public function __construct( private \Iterator $iterator, private array $cache = [], ) { } public function getIterator(): \Generator { if (!$this->cache) { $this->iterator->rewind(); } $i = 0; while (true) { if (isset($this->cache[$i])) { [$k, $v] = $this->cache[$i]; } elseif ($this->iterator->valid()) { $k = $this->iterator->key(); $v = $this->iterator->current(); $this->iterator->next(); $this->cache[$i] = [$k, $v]; } else { break; } yield $k => $v; $i++; } } }; }
Wraps around iterator and caches its keys and values during iteration. This allows the data to be re-iterated multiple times. @template K @template V @param iterable<K, V> $iterable @return \IteratorAggregate<K, V>
memoize
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
BSD-3-Clause
public static function toIterator(iterable $iterable): \Iterator { return match (true) { $iterable instanceof \Iterator => $iterable, $iterable instanceof \IteratorAggregate => self::toIterator($iterable->getIterator()), is_array($iterable) => new \ArrayIterator($iterable), }; }
Creates an iterator from anything that is iterable. @template K @template V @param iterable<K, V> $iterable @return \Iterator<K, V>
toIterator
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
BSD-3-Clause
public static function encode( mixed $value, bool|int $pretty = false, bool $asciiSafe = false, bool $htmlSafe = false, bool $forceObjects = false, ): string { if (is_int($pretty)) { // back compatibility $flags = ($pretty & self::ESCAPE_UNICODE ? 0 : JSON_UNESCAPED_UNICODE) | ($pretty & ~self::ESCAPE_UNICODE); } else { $flags = ($asciiSafe ? 0 : JSON_UNESCAPED_UNICODE) | ($pretty ? JSON_PRETTY_PRINT : 0) | ($forceObjects ? JSON_FORCE_OBJECT : 0) | ($htmlSafe ? JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG : 0); } $flags |= JSON_UNESCAPED_SLASHES | (defined('JSON_PRESERVE_ZERO_FRACTION') ? JSON_PRESERVE_ZERO_FRACTION : 0); // since PHP 5.6.6 & PECL JSON-C 1.3.7 $json = json_encode($value, $flags); if ($error = json_last_error()) { throw new JsonException(json_last_error_msg(), $error); } return $json; }
Converts value to JSON format. Use $pretty for easier reading and clarity, $asciiSafe for ASCII output and $htmlSafe for HTML escaping, $forceObjects enforces the encoding of non-associateve arrays as objects. @throws JsonException
encode
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Json.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Json.php
BSD-3-Clause
public static function decode(string $json, bool|int $forceArrays = false): mixed { $flags = is_int($forceArrays) // back compatibility ? $forceArrays : ($forceArrays ? JSON_OBJECT_AS_ARRAY : 0); $flags |= JSON_BIGINT_AS_STRING; $value = json_decode($json, flags: $flags); if ($error = json_last_error()) { throw new JsonException(json_last_error_msg(), $error); } return $value; }
Parses JSON to PHP value. The $forceArrays enforces the decoding of objects as arrays. @throws JsonException
decode
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Json.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Json.php
BSD-3-Clause
public static function getMagicProperties(string $class): array { static $cache; $props = &$cache[$class]; if ($props !== null) { return $props; } $rc = new \ReflectionClass($class); preg_match_all( '~^ [ \t*]* @property(|-read|-write|-deprecated) [ \t]+ [^\s$]+ [ \t]+ \$ (\w+) ()~mx', (string) $rc->getDocComment(), $matches, PREG_SET_ORDER, ); $props = []; foreach ($matches as [, $type, $name]) { $uname = ucfirst($name); $write = $type !== '-read' && $rc->hasMethod($nm = 'set' . $uname) && ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic(); $read = $type !== '-write' && ($rc->hasMethod($nm = 'get' . $uname) || $rc->hasMethod($nm = 'is' . $uname)) && ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic(); if ($read || $write) { $props[$name] = $read << 0 | ($nm[0] === 'g') << 1 | $rm->returnsReference() << 2 | $write << 3 | ($type === '-deprecated') << 4; } } foreach ($rc->getTraits() as $trait) { $props += self::getMagicProperties($trait->name); } if ($parent = get_parent_class($class)) { $props += self::getMagicProperties($parent); } return $props; }
Returns array of magic properties defined by annotation @property. @return array of [name => bit mask] @internal
getMagicProperties
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
BSD-3-Clause
public static function getSuggestion(array $possibilities, string $value): ?string { $norm = preg_replace($re = '#^(get|set|has|is|add)(?=[A-Z])#', '+', $value); $best = null; $min = (strlen($value) / 4 + 1) * 10 + .1; foreach (array_unique($possibilities, SORT_REGULAR) as $item) { $item = $item instanceof \Reflector ? $item->name : $item; if ($item !== $value && ( ($len = levenshtein($item, $value, 10, 11, 10)) < $min || ($len = levenshtein(preg_replace($re, '*', $item), $norm, 10, 11, 10)) < $min )) { $min = $len; $best = $item; } } return $best; }
Finds the best suggestion (for 8-bit encoding). @param (\ReflectionFunctionAbstract|\ReflectionParameter|\ReflectionClass|\ReflectionProperty|string)[] $possibilities @internal
getSuggestion
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
BSD-3-Clause
public static function hasProperty(string $class, string $name): bool|string { static $cache; $prop = &$cache[$class][$name]; if ($prop === null) { $prop = false; try { $rp = new \ReflectionProperty($class, $name); if ($rp->isPublic() && !$rp->isStatic()) { $prop = $name >= 'onA' && $name < 'on_' ? 'event' : true; } } catch (\ReflectionException $e) { } } return $prop; }
Checks if the public non-static property exists. Returns 'event' if the property exists and has event like name @internal
hasProperty
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
BSD-3-Clause
public function getFirstItemOnPage(): int { return $this->itemCount !== 0 ? $this->offset + 1 : 0; }
Returns the sequence number of the first element on the page @return int<0, max>
getFirstItemOnPage
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
public function getLastItemOnPage(): int { return $this->offset + $this->length; }
Returns the sequence number of the last element on the page @return int<0, max>
getLastItemOnPage
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
protected function getPageIndex(): int { $index = max(0, $this->page - $this->base); return $this->itemCount === null ? $index : min($index, max(0, $this->getPageCount() - 1)); }
Returns zero-based page number. @return int<0, max>
getPageIndex
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
public function isFirst(): bool { return $this->getPageIndex() === 0; }
Is the current page the first one?
isFirst
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
public function isLast(): bool { return $this->itemCount === null ? false : $this->getPageIndex() >= $this->getPageCount() - 1; }
Is the current page the last one?
isLast
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
public function getPageCount(): ?int { return $this->itemCount === null ? null : (int) ceil($this->itemCount / $this->itemsPerPage); }
Returns the total number of pages. @return int<0, max>|null
getPageCount
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
public function setItemsPerPage(int $itemsPerPage): static { $this->itemsPerPage = max(1, $itemsPerPage); return $this; }
Sets the number of items to display on a single page.
setItemsPerPage
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
public function getItemsPerPage(): int { return $this->itemsPerPage; }
Returns the number of items to display on a single page. @return positive-int
getItemsPerPage
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
public function setItemCount(?int $itemCount = null): static { $this->itemCount = $itemCount === null ? null : max(0, $itemCount); return $this; }
Sets the total number of items.
setItemCount
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause