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 function getClassMap()
{
return $this->classMap;
}
|
@return array<string, string> Array of classname => path
|
getClassMap
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
|
@param array<string, string> $classMap Class to filename map
@return void
|
addClassMap
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function add($prefix, $paths, $prepend = false)
{
$paths = (array) $paths;
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
$paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
$paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
$paths
);
}
}
|
Registers a set of PSR-0 directories for a given prefix, either
appending or prepending to the ones previously set for this prefix.
@param string $prefix The prefix
@param list<string>|string $paths The PSR-0 root directories
@param bool $prepend Whether to prepend the directories
@return void
|
add
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function addPsr4($prefix, $paths, $prepend = false)
{
$paths = (array) $paths;
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
$paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
$paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
$paths
);
}
}
|
Registers a set of PSR-4 directories for a given namespace, either
appending or prepending to the ones previously set for this namespace.
@param string $prefix The prefix/namespace, with trailing '\\'
@param list<string>|string $paths The PSR-4 base directories
@param bool $prepend Whether to prepend the directories
@throws \InvalidArgumentException
@return void
|
addPsr4
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
|
Registers a set of PSR-0 directories for a given prefix,
replacing any others previously set for this prefix.
@param string $prefix The prefix
@param list<string>|string $paths The PSR-0 base directories
@return void
|
set
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
|
Registers a set of PSR-4 directories for a given namespace,
replacing any others previously set for this namespace.
@param string $prefix The prefix/namespace, with trailing '\\'
@param list<string>|string $paths The PSR-4 base directories
@throws \InvalidArgumentException
@return void
|
setPsr4
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
|
Turns on searching the include path for class files.
@param bool $useIncludePath
@return void
|
setUseIncludePath
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function getUseIncludePath()
{
return $this->useIncludePath;
}
|
Can be used to check if the autoloader uses the include path to check
for classes.
@return bool
|
getUseIncludePath
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
|
Turns off searching the prefix and fallback directories for classes
that have not been registered with the class map.
@param bool $classMapAuthoritative
@return void
|
setClassMapAuthoritative
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
|
Should class lookup fail if not found in the current class map?
@return bool
|
isClassMapAuthoritative
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
|
APCu prefix to use to cache found/not-found classes, if the extension is enabled.
@param string|null $apcuPrefix
@return void
|
setApcuPrefix
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
|
The APCu prefix in use, or null if APCu caching is not enabled.
@return string|null
|
getApcuPrefix
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
if (null === $this->vendorDir) {
return;
}
if ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}
|
Registers this instance as an autoloader.
@param bool $prepend Whether to prepend the autoloader or not
@return void
|
register
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}
|
Unregisters this instance as an autoloader.
@return void
|
unregister
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
$includeFile = self::$includeFile;
$includeFile($file);
return true;
}
return null;
}
|
Loads the given class or interface.
@param string $class The name of the class
@return true|null True if loaded, null otherwise
|
loadClass
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
|
Finds the path to the file where the class is defined.
@param string $class The name of the class
@return string|false The path if found, false otherwise
|
findFile
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}
|
Returns the currently registered loaders keyed by their corresponding vendor directories.
@return array<string, self>
|
getRegisteredLoaders
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
|
@param string $class
@param string $ext
@return string|false
|
findFileWithExtension
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public static function getInstalledPackages()
{
$packages = array();
foreach (self::getInstalled() as $installed) {
$packages[] = array_keys($installed['versions']);
}
if (1 === \count($packages)) {
return $packages[0];
}
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
}
|
Returns a list of all package names which are present, either by being installed, replaced or provided
@return string[]
@psalm-return list<string>
|
getInstalledPackages
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getInstalledPackagesByType($type)
{
$packagesByType = array();
foreach (self::getInstalled() as $installed) {
foreach ($installed['versions'] as $name => $package) {
if (isset($package['type']) && $package['type'] === $type) {
$packagesByType[] = $name;
}
}
}
return $packagesByType;
}
|
Returns a list of all package names with a specific type e.g. 'library'
@param string $type
@return string[]
@psalm-return list<string>
|
getInstalledPackagesByType
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function isInstalled($packageName, $includeDevRequirements = true)
{
foreach (self::getInstalled() as $installed) {
if (isset($installed['versions'][$packageName])) {
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
}
}
return false;
}
|
Checks whether the given package is installed
This also returns true if the package name is provided or replaced by another package
@param string $packageName
@param bool $includeDevRequirements
@return bool
|
isInstalled
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function satisfies(VersionParser $parser, $packageName, $constraint)
{
$constraint = $parser->parseConstraints((string) $constraint);
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
return $provided->matches($constraint);
}
|
Checks whether the given package satisfies a version constraint
e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
@param VersionParser $parser Install composer/semver to have access to this class and functionality
@param string $packageName
@param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
@return bool
|
satisfies
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getVersionRanges($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
$ranges = array();
if (isset($installed['versions'][$packageName]['pretty_version'])) {
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
}
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
}
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
}
if (array_key_exists('provided', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
}
return implode(' || ', $ranges);
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
|
Returns a version constraint representing all the range(s) which are installed for a given package
It is easier to use this via isInstalled() with the $constraint argument if you need to check
whether a given version of a package is installed, and not just whether it exists
@param string $packageName
@return string Version constraint usable with composer/semver
|
getVersionRanges
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['version'])) {
return null;
}
return $installed['versions'][$packageName]['version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
|
@param string $packageName
@return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
getVersion
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getPrettyVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
return null;
}
return $installed['versions'][$packageName]['pretty_version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
|
@param string $packageName
@return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
getPrettyVersion
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getReference($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['reference'])) {
return null;
}
return $installed['versions'][$packageName]['reference'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
|
@param string $packageName
@return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
|
getReference
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getInstallPath($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
|
@param string $packageName
@return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
|
getInstallPath
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getRootPackage()
{
$installed = self::getInstalled();
return $installed[0]['root'];
}
|
@return array
@psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
|
getRootPackage
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getRawData()
{
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
self::$installed = include __DIR__ . '/installed.php';
} else {
self::$installed = array();
}
}
return self::$installed;
}
|
Returns the raw installed.php data for custom implementations
@deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
@return array[]
@psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
|
getRawData
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getAllRawData()
{
return self::getInstalled();
}
|
Returns the raw data of all installed.php which are currently loaded for custom implementations
@return array[]
@psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
getAllRawData
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function reload($data)
{
self::$installed = $data;
self::$installedByVendor = array();
// when using reload, we disable the duplicate protection to ensure that self::$installed data is
// always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
// so we have to assume it does not, and that may result in duplicate data being returned when listing
// all installed packages for example
self::$installedIsLocalDir = false;
}
|
Lets you reload the static array from another file
This is only useful for complex integrations in which a project needs to use
this class but then also needs to execute another project's autoloader in process,
and wants to ensure both projects have access to their version of installed.php.
A typical case would be PHPUnit, where it would need to make sure it reads all
the data it needs from this class, then call reload() with
`require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
the project in which it runs can then also use this class safely, without
interference between PHPUnit's dependencies and the project's dependencies.
@param array[] $data A vendor/composer/installed.php data set
@return void
@psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
|
reload
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
private static function getInstalled()
{
if (null === self::$canGetVendors) {
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
}
$installed = array();
$copiedLocalDir = false;
if (self::$canGetVendors) {
$selfDir = strtr(__DIR__, '\\', '/');
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
$vendorDir = strtr($vendorDir, '\\', '/');
if (isset(self::$installedByVendor[$vendorDir])) {
$installed[] = self::$installedByVendor[$vendorDir];
} elseif (is_file($vendorDir.'/composer/installed.php')) {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require $vendorDir.'/composer/installed.php';
self::$installedByVendor[$vendorDir] = $required;
$installed[] = $required;
if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
self::$installed = $required;
self::$installedIsLocalDir = true;
}
}
if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
$copiedLocalDir = true;
}
}
}
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require __DIR__ . '/installed.php';
self::$installed = $required;
} else {
self::$installed = array();
}
}
if (self::$installed !== array() && !$copiedLocalDir) {
$installed[] = self::$installed;
}
return $installed;
}
|
@return array[]
@psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
getInstalled
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public function isNullableTypeDeclaration($typeDeclaration): bool
{
if ($typeDeclaration instanceof Node\NullableType) {
return true;
}
if ($typeDeclaration instanceof Node\UnionType) {
foreach ($typeDeclaration->types as $type) {
if (
$type instanceof Node\Identifier
&& 'null' === $type->toLowerString()
) {
return true;
}
if (
$type instanceof Node\Name\FullyQualified
&& $type->hasAttribute('originalName')
) {
$originalName = $type->getAttribute('originalName');
if (
$originalName instanceof Node\Name
&& 'null' === $originalName->toLowerString()
) {
return true;
}
}
}
}
return false;
}
|
@param null|Node\ComplexType|Node\Identifier|Node\Name $typeDeclaration
|
isNullableTypeDeclaration
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/ergebnis/phpstan-rules/src/Analyzer.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/ergebnis/phpstan-rules/src/Analyzer.php
|
BSD-3-Clause
|
public function __construct(
Reflection\ReflectionProvider $reflectionProvider,
array $interfacesImplementedByContainers,
array $methodsAllowedToUseContainerTypeDeclarations
) {
$this->reflectionProvider = $reflectionProvider;
$this->interfacesImplementedByContainers = \array_values(\array_filter(
\array_map(static function (string $interfaceImplementedByContainers): string {
return $interfaceImplementedByContainers;
}, $interfacesImplementedByContainers),
static function (string $interfaceImplementedByContainer): bool {
return \interface_exists($interfaceImplementedByContainer);
},
));
$this->methodsAllowedToUseContainerTypeDeclarations = $methodsAllowedToUseContainerTypeDeclarations;
}
|
@param list<string> $interfacesImplementedByContainers
@param list<string> $methodsAllowedToUseContainerTypeDeclarations
|
__construct
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/ergebnis/phpstan-rules/src/Methods/NoParameterWithContainerTypeDeclarationRule.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/ergebnis/phpstan-rules/src/Methods/NoParameterWithContainerTypeDeclarationRule.php
|
BSD-3-Clause
|
public function &__get(string $name)
{
$class = static::class;
if ($prop = ObjectHelpers::getMagicProperties($class)[$name] ?? null) { // property getter
if (!($prop & 0b0001)) {
throw new MemberAccessException("Cannot read a write-only property $class::\$$name.");
}
$m = ($prop & 0b0010 ? 'get' : 'is') . ucfirst($name);
if ($prop & 0b10000) {
$trace = debug_backtrace(0, 1)[0]; // suppose this method is called from __call()
$loc = isset($trace['file'], $trace['line'])
? " in $trace[file] on line $trace[line]"
: '';
trigger_error("Property $class::\$$name is deprecated, use $class::$m() method$loc.", E_USER_DEPRECATED);
}
if ($prop & 0b0100) { // return by reference
return $this->$m();
} else {
$val = $this->$m();
return $val;
}
} else {
ObjectHelpers::strictGet($class, $name);
}
}
|
@return mixed
@throws MemberAccessException if the property is not defined.
|
__get
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/SmartObject.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/SmartObject.php
|
BSD-3-Clause
|
public function __set(string $name, mixed $value): void
{
$class = static::class;
if (ObjectHelpers::hasProperty($class, $name)) { // unsetted property
$this->$name = $value;
} elseif ($prop = ObjectHelpers::getMagicProperties($class)[$name] ?? null) { // property setter
if (!($prop & 0b1000)) {
throw new MemberAccessException("Cannot write to a read-only property $class::\$$name.");
}
$m = 'set' . ucfirst($name);
if ($prop & 0b10000) {
$trace = debug_backtrace(0, 1)[0]; // suppose this method is called from __call()
$loc = isset($trace['file'], $trace['line'])
? " in $trace[file] on line $trace[line]"
: '';
trigger_error("Property $class::\$$name is deprecated, use $class::$m() method$loc.", E_USER_DEPRECATED);
}
$this->$m($value);
} else {
ObjectHelpers::strictSet($class, $name);
}
}
|
@throws MemberAccessException if the property is not defined or is read-only
|
__set
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/SmartObject.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/SmartObject.php
|
BSD-3-Clause
|
public static function __callStatic(string $name, array $args): mixed
{
Utils\ObjectHelpers::strictStaticCall(static::class, $name);
}
|
Call to undefined static method.
@throws MemberAccessException
|
__callStatic
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/StaticClass.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/StaticClass.php
|
BSD-3-Clause
|
public function isFirst(?int $gridWidth = null): bool
{
return $this->counter === 1 || ($gridWidth && $this->counter !== 0 && (($this->counter - 1) % $gridWidth) === 0);
}
|
Is the current element the first one?
|
isFirst
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Iterators/CachingIterator.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Iterators/CachingIterator.php
|
BSD-3-Clause
|
public function isLast(?int $gridWidth = null): bool
{
return !$this->hasNext() || ($gridWidth && ($this->counter % $gridWidth) === 0);
}
|
Is the current element the last one?
|
isLast
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Iterators/CachingIterator.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Iterators/CachingIterator.php
|
BSD-3-Clause
|
public static function from(array $array, bool $recursive = true): static
{
$obj = new static;
foreach ($array as $key => $value) {
$obj->$key = $recursive && is_array($value)
? static::from($value)
: $value;
}
return $obj;
}
|
Transforms array to ArrayHash.
@param array<T> $array
|
from
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
BSD-3-Clause
|
public function &getIterator(): \Iterator
{
foreach ((array) $this as $key => $foo) {
yield $key => $this->$key;
}
}
|
Returns an iterator over all items.
@return \Iterator<array-key, T>
|
getIterator
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
BSD-3-Clause
|
public function offsetSet($key, $value): void
{
if (!is_scalar($key)) { // prevents null
throw new Nette\InvalidArgumentException(sprintf('Key must be either a string or an integer, %s given.', get_debug_type($key)));
}
$this->$key = $value;
}
|
Replaces or appends a item.
@param array-key $key
@param T $value
|
offsetSet
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
BSD-3-Clause
|
#[\ReturnTypeWillChange]
public function offsetGet($key)
{
return $this->$key;
}
|
Returns a item.
@param array-key $key
@return T
|
offsetGet
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
BSD-3-Clause
|
public function offsetExists($key): bool
{
return isset($this->$key);
}
|
Determines whether a item exists.
@param array-key $key
|
offsetExists
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
BSD-3-Clause
|
public function offsetUnset($key): void
{
unset($this->$key);
}
|
Removes the element from this list.
@param array-key $key
|
offsetUnset
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
|
BSD-3-Clause
|
public static function from(array $array): static
{
if (!Arrays::isList($array)) {
throw new Nette\InvalidArgumentException('Array is not valid list.');
}
$obj = new static;
$obj->list = $array;
return $obj;
}
|
Transforms array to ArrayList.
@param list<T> $array
|
from
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
BSD-3-Clause
|
public function &getIterator(): \Iterator
{
foreach ($this->list as &$item) {
yield $item;
}
}
|
Returns an iterator over all items.
@return \Iterator<int, T>
|
getIterator
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
BSD-3-Clause
|
public function offsetSet($index, $value): void
{
if ($index === null) {
$this->list[] = $value;
} elseif (!is_int($index) || $index < 0 || $index >= count($this->list)) {
throw new Nette\OutOfRangeException('Offset invalid or out of range');
} else {
$this->list[$index] = $value;
}
}
|
Replaces or appends a item.
@param int|null $index
@param T $value
@throws Nette\OutOfRangeException
|
offsetSet
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
BSD-3-Clause
|
public function offsetGet($index): mixed
{
if (!is_int($index) || $index < 0 || $index >= count($this->list)) {
throw new Nette\OutOfRangeException('Offset invalid or out of range');
}
return $this->list[$index];
}
|
Returns a item.
@param int $index
@return T
@throws Nette\OutOfRangeException
|
offsetGet
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
BSD-3-Clause
|
public function offsetExists($index): bool
{
return is_int($index) && $index >= 0 && $index < count($this->list);
}
|
Determines whether a item exists.
@param int $index
|
offsetExists
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
BSD-3-Clause
|
public function offsetUnset($index): void
{
if (!is_int($index) || $index < 0 || $index >= count($this->list)) {
throw new Nette\OutOfRangeException('Offset invalid or out of range');
}
array_splice($this->list, $index, 1);
}
|
Removes the element at the specified position in this list.
@param int $index
@throws Nette\OutOfRangeException
|
offsetUnset
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
|
BSD-3-Clause
|
public static function get(array $array, string|int|array $key, mixed $default = null): mixed
{
foreach (is_array($key) ? $key : [$key] as $k) {
if (is_array($array) && array_key_exists($k, $array)) {
$array = $array[$k];
} else {
if (func_num_args() < 3) {
throw new Nette\InvalidArgumentException("Missing item '$k'.");
}
return $default;
}
}
return $array;
}
|
Returns item from array. If it does not exist, it throws an exception, unless a default value is set.
@template T
@param array<T> $array
@param array-key|array-key[] $key
@param ?T $default
@return ?T
@throws Nette\InvalidArgumentException if item does not exist and default value is not provided
|
get
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function &getRef(array &$array, string|int|array $key): mixed
{
foreach (is_array($key) ? $key : [$key] as $k) {
if (is_array($array) || $array === null) {
$array = &$array[$k];
} else {
throw new Nette\InvalidArgumentException('Traversed item is not an array.');
}
}
return $array;
}
|
Returns reference to array item. If the index does not exist, new one is created with value null.
@template T
@param array<T> $array
@param array-key|array-key[] $key
@return ?T
@throws Nette\InvalidArgumentException if traversed item is not an array
|
getRef
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function mergeTree(array $array1, array $array2): array
{
$res = $array1 + $array2;
foreach (array_intersect_key($array1, $array2) as $k => $v) {
if (is_array($v) && is_array($array2[$k])) {
$res[$k] = self::mergeTree($v, $array2[$k]);
}
}
return $res;
}
|
Recursively merges two fields. It is useful, for example, for merging tree structures. It behaves as
the + operator for array, ie. it adds a key/value pair from the second array to the first one and retains
the value from the first array in the case of a key collision.
@template T1
@template T2
@param array<T1> $array1
@param array<T2> $array2
@return array<T1|T2>
|
mergeTree
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function getKeyOffset(array $array, string|int $key): ?int
{
return Helpers::falseToNull(array_search(self::toKey($key), array_keys($array), strict: true));
}
|
Returns zero-indexed position of given array key. Returns null if key is not found.
|
getKeyOffset
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function contains(array $array, mixed $value): bool
{
return in_array($value, $array, true);
}
|
Tests an array for the presence of value.
|
contains
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function first(array $array, ?callable $predicate = null, ?callable $else = null): mixed
{
$key = self::firstKey($array, $predicate);
return $key === null
? ($else ? $else() : null)
: $array[$key];
}
|
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 of int|string
@template V
@param array<K, V> $array
@param ?callable(V, K, array<K, V>): bool $predicate
@return ?V
|
first
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function last(array $array, ?callable $predicate = null, ?callable $else = null): mixed
{
$key = self::lastKey($array, $predicate);
return $key === null
? ($else ? $else() : null)
: $array[$key];
}
|
Returns the last item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
@template K of int|string
@template V
@param array<K, V> $array
@param ?callable(V, K, array<K, V>): bool $predicate
@return ?V
|
last
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function firstKey(array $array, ?callable $predicate = null): int|string|null
{
if (!$predicate) {
return array_key_first($array);
}
foreach ($array as $k => $v) {
if ($predicate($v, $k, $array)) {
return $k;
}
}
return null;
}
|
Returns the key of first item (matching the specified predicate if given) or null if there is no such item.
@template K of int|string
@template V
@param array<K, V> $array
@param ?callable(V, K, array<K, V>): bool $predicate
@return ?K
|
firstKey
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function lastKey(array $array, ?callable $predicate = null): int|string|null
{
return $predicate
? self::firstKey(array_reverse($array, preserve_keys: true), $predicate)
: array_key_last($array);
}
|
Returns the key of last item (matching the specified predicate if given) or null if there is no such item.
@template K of int|string
@template V
@param array<K, V> $array
@param ?callable(V, K, array<K, V>): bool $predicate
@return ?K
|
lastKey
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function insertBefore(array &$array, string|int|null $key, array $inserted): void
{
$offset = $key === null ? 0 : (int) self::getKeyOffset($array, $key);
$array = array_slice($array, 0, $offset, preserve_keys: true)
+ $inserted
+ array_slice($array, $offset, count($array), preserve_keys: true);
}
|
Inserts the contents of the $inserted array into the $array immediately after the $key.
If $key is null (or does not exist), it is inserted at the beginning.
|
insertBefore
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function insertAfter(array &$array, string|int|null $key, array $inserted): void
{
if ($key === null || ($offset = self::getKeyOffset($array, $key)) === null) {
$offset = count($array) - 1;
}
$array = array_slice($array, 0, $offset + 1, preserve_keys: true)
+ $inserted
+ array_slice($array, $offset + 1, count($array), preserve_keys: true);
}
|
Inserts the contents of the $inserted array into the $array before the $key.
If $key is null (or does not exist), it is inserted at the end.
|
insertAfter
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function grep(
array $array,
#[Language('RegExp')]
string $pattern,
bool|int $invert = false,
): array
{
$flags = $invert ? PREG_GREP_INVERT : 0;
return Strings::pcre('preg_grep', [$pattern, $array, $flags]);
}
|
Returns only those array items, which matches a regular expression $pattern.
@param string[] $array
@return string[]
|
grep
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function flatten(array $array, bool $preserveKeys = false): array
{
$res = [];
$cb = $preserveKeys
? function ($v, $k) use (&$res): void { $res[$k] = $v; }
: function ($v) use (&$res): void { $res[] = $v; };
array_walk_recursive($array, $cb);
return $res;
}
|
Transforms multidimensional array to flat array.
|
flatten
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function isList(mixed $value): bool
{
return is_array($value) && (PHP_VERSION_ID < 80100
? !$value || array_keys($value) === range(0, count($value) - 1)
: array_is_list($value)
);
}
|
Checks if the array is indexed in ascending order of numeric keys from zero, a.k.a list.
@return ($value is list ? true : false)
|
isList
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function associate(array $array, $path): array|\stdClass
{
$parts = is_array($path)
? $path
: preg_split('#(\[\]|->|=|\|)#', $path, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if (!$parts || $parts === ['->'] || $parts[0] === '=' || $parts[0] === '|') {
throw new Nette\InvalidArgumentException("Invalid path '$path'.");
}
$res = $parts[0] === '->' ? new \stdClass : [];
foreach ($array as $rowOrig) {
$row = (array) $rowOrig;
$x = &$res;
for ($i = 0; $i < count($parts); $i++) {
$part = $parts[$i];
if ($part === '[]') {
$x = &$x[];
} elseif ($part === '=') {
if (isset($parts[++$i])) {
$x = $row[$parts[$i]];
$row = null;
}
} elseif ($part === '->') {
if (isset($parts[++$i])) {
if ($x === null) {
$x = new \stdClass;
}
$x = &$x->{$row[$parts[$i]]};
} else {
$row = is_object($rowOrig) ? $rowOrig : (object) $row;
}
} elseif ($part !== '|') {
$x = &$x[(string) $row[$part]];
}
}
if ($x === null) {
$x = $row;
}
}
return $res;
}
|
Reformats table to associative tree. Path looks like 'field|field[]field->field=field'.
@param string|string[] $path
|
associate
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function normalize(array $array, mixed $filling = null): array
{
$res = [];
foreach ($array as $k => $v) {
$res[is_int($k) ? $v : $k] = is_int($k) ? $filling : $v;
}
return $res;
}
|
Normalizes array to associative array. Replace numeric keys with their values, the new value will be $filling.
|
normalize
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function pick(array &$array, string|int $key, mixed $default = null): mixed
{
if (array_key_exists($key, $array)) {
$value = $array[$key];
unset($array[$key]);
return $value;
} elseif (func_num_args() < 3) {
throw new Nette\InvalidArgumentException("Missing item '$key'.");
} else {
return $default;
}
}
|
Returns and removes the value of an item from an array. If it does not exist, it throws an exception,
or returns $default, if provided.
@template T
@param array<T> $array
@param ?T $default
@return ?T
@throws Nette\InvalidArgumentException if item does not exist and default value is not provided
|
pick
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function some(iterable $array, callable $predicate): bool
{
foreach ($array as $k => $v) {
if ($predicate($v, $k, $array)) {
return true;
}
}
return false;
}
|
Tests whether at least one element in the array passes the test implemented by the provided function.
@template K of int|string
@template V
@param array<K, V> $array
@param callable(V, K, array<K, V>): bool $predicate
|
some
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function every(iterable $array, callable $predicate): bool
{
foreach ($array as $k => $v) {
if (!$predicate($v, $k, $array)) {
return false;
}
}
return true;
}
|
Tests whether all elements in the array pass the test implemented by the provided function.
@template K of int|string
@template V
@param array<K, V> $array
@param callable(V, K, array<K, V>): bool $predicate
|
every
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function filter(array $array, callable $predicate): array
{
$res = [];
foreach ($array as $k => $v) {
if ($predicate($v, $k, $array)) {
$res[$k] = $v;
}
}
return $res;
}
|
Returns a new array containing all key-value pairs matching the given $predicate.
@template K of int|string
@template V
@param array<K, V> $array
@param callable(V, K, array<K, V>): bool $predicate
@return array<K, V>
|
filter
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function map(iterable $array, callable $transformer): array
{
$res = [];
foreach ($array as $k => $v) {
$res[$k] = $transformer($v, $k, $array);
}
return $res;
}
|
Returns an array containing the original keys and results of applying the given transform function to each element.
@template K of int|string
@template V
@template R
@param array<K, V> $array
@param callable(V, K, array<K, V>): R $transformer
@return array<K, R>
|
map
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function mapWithKeys(array $array, callable $transformer): array
{
$res = [];
foreach ($array as $k => $v) {
$pair = $transformer($v, $k, $array);
if ($pair) {
$res[$pair[0]] = $pair[1];
}
}
return $res;
}
|
Returns an array containing new keys and values generated by applying the given transform function to each element.
If the function returns null, the element is skipped.
@template K of int|string
@template V
@template ResK of int|string
@template ResV
@param array<K, V> $array
@param callable(V, K, array<K, V>): ?array{ResK, ResV} $transformer
@return array<ResK, ResV>
|
mapWithKeys
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function invoke(iterable $callbacks, ...$args): array
{
$res = [];
foreach ($callbacks as $k => $cb) {
$res[$k] = $cb(...$args);
}
return $res;
}
|
Invokes all callbacks and returns array of results.
@param callable[] $callbacks
|
invoke
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function invokeMethod(iterable $objects, string $method, ...$args): array
{
$res = [];
foreach ($objects as $k => $obj) {
$res[$k] = $obj->$method(...$args);
}
return $res;
}
|
Invokes method on every object in an array and returns array of results.
@param object[] $objects
|
invokeMethod
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function toObject(iterable $array, object $object): object
{
foreach ($array as $k => $v) {
$object->$k = $v;
}
return $object;
}
|
Copies the elements of the $array array to the $object object and then returns it.
@template T of object
@param T $object
@return T
|
toObject
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function wrap(array $array, string $prefix = '', string $suffix = ''): array
{
$res = [];
foreach ($array as $k => $v) {
$res[$k] = $prefix . $v . $suffix;
}
return $res;
}
|
Returns copy of the $array where every item is converted to string
and prefixed by $prefix and suffixed by $suffix.
@param string[] $array
@return string[]
|
wrap
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
|
BSD-3-Clause
|
public static function invokeSafe(string $function, array $args, callable $onError): mixed
{
$prev = set_error_handler(function ($severity, $message, $file) use ($onError, &$prev, $function): ?bool {
if ($file === __FILE__) {
$msg = ini_get('html_errors')
? Html::htmlToText($message)
: $message;
$msg = preg_replace("#^$function\\(.*?\\): #", '', $msg);
if ($onError($msg, $severity) !== false) {
return null;
}
}
return $prev ? $prev(...func_get_args()) : false;
});
try {
return $function(...$args);
} finally {
restore_error_handler();
}
}
|
Invokes internal PHP function with own error handler.
|
invokeSafe
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
BSD-3-Clause
|
public static function check(mixed $callable, bool $syntax = false)
{
if (!is_callable($callable, $syntax)) {
throw new Nette\InvalidArgumentException(
$syntax
? 'Given value is not a callable type.'
: sprintf("Callback '%s' is not callable.", self::toString($callable)),
);
}
return $callable;
}
|
Checks that $callable is valid PHP callback. Otherwise throws exception. If the $syntax is set to true, only verifies
that $callable has a valid structure to be used as a callback, but does not verify if the class or method actually exists.
@return callable
@throws Nette\InvalidArgumentException
|
check
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
BSD-3-Clause
|
public static function toString(mixed $callable): string
{
if ($callable instanceof \Closure) {
$inner = self::unwrap($callable);
return '{closure' . ($inner instanceof \Closure ? '}' : ' ' . self::toString($inner) . '}');
} else {
is_callable(is_object($callable) ? [$callable, '__invoke'] : $callable, true, $textual);
return $textual;
}
}
|
Converts PHP callback to textual form. Class or method may not exists.
|
toString
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
BSD-3-Clause
|
public static function toReflection($callable): \ReflectionMethod|\ReflectionFunction
{
if ($callable instanceof \Closure) {
$callable = self::unwrap($callable);
}
if (is_string($callable) && str_contains($callable, '::')) {
return new ReflectionMethod(...explode('::', $callable, 2));
} elseif (is_array($callable)) {
return new ReflectionMethod($callable[0], $callable[1]);
} elseif (is_object($callable) && !$callable instanceof \Closure) {
return new ReflectionMethod($callable, '__invoke');
} else {
return new \ReflectionFunction($callable);
}
}
|
Returns reflection for method or function used in PHP callback.
@param callable $callable type check is escalated to ReflectionException
@throws \ReflectionException if callback is not valid
|
toReflection
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
BSD-3-Clause
|
public static function isStatic(callable $callable): bool
{
return is_string(is_array($callable) ? $callable[0] : $callable);
}
|
Checks whether PHP callback is function or static method.
|
isStatic
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
BSD-3-Clause
|
public static function unwrap(\Closure $closure): callable|array
{
$r = new \ReflectionFunction($closure);
$class = $r->getClosureScopeClass()?->name;
if (str_ends_with($r->name, '}')) {
return $closure;
} elseif (($obj = $r->getClosureThis()) && $obj::class === $class) {
return [$obj, $r->name];
} elseif ($class) {
return [$class, $r->name];
} else {
return $r->name;
}
}
|
Unwraps closure created by Closure::fromCallable().
|
unwrap
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
|
BSD-3-Clause
|
public static function from(string|int|\DateTimeInterface|null $time): static
{
if ($time instanceof \DateTimeInterface) {
return new static($time->format('Y-m-d H:i:s.u'), $time->getTimezone());
} elseif (is_numeric($time)) {
if ($time <= self::YEAR) {
$time += time();
}
return (new static)->setTimestamp((int) $time);
} else { // textual or null
return new static((string) $time);
}
}
|
Creates a DateTime object from a string, UNIX timestamp, or other DateTimeInterface object.
@throws \Exception if the date and time are not valid.
|
from
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
BSD-3-Clause
|
public static function fromParts(
int $year,
int $month,
int $day,
int $hour = 0,
int $minute = 0,
float $second = 0.0,
): static
{
$s = sprintf('%04d-%02d-%02d %02d:%02d:%02.5F', $year, $month, $day, $hour, $minute, $second);
if (
!checkdate($month, $day, $year)
|| $hour < 0
|| $hour > 23
|| $minute < 0
|| $minute > 59
|| $second < 0
|| $second >= 60
) {
throw new Nette\InvalidArgumentException("Invalid date '$s'");
}
return new static($s);
}
|
Creates DateTime object.
@throws Nette\InvalidArgumentException if the date and time are not valid.
|
fromParts
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
BSD-3-Clause
|
public static function createFromFormat(
string $format,
string $time,
string|\DateTimeZone|null $timezone = null,
): static|false
{
if ($timezone === null) {
$timezone = new \DateTimeZone(date_default_timezone_get());
} elseif (is_string($timezone)) {
$timezone = new \DateTimeZone($timezone);
}
$date = parent::createFromFormat($format, $time, $timezone);
return $date ? static::from($date) : false;
}
|
Returns new DateTime object formatted according to the specified format.
|
createFromFormat
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
BSD-3-Clause
|
public function jsonSerialize(): string
{
return $this->format('c');
}
|
Returns JSON representation in ISO 8601 (used by JavaScript).
|
jsonSerialize
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
BSD-3-Clause
|
public function __toString(): string
{
return $this->format('Y-m-d H:i:s');
}
|
Returns the date and time in the format 'Y-m-d H:i:s'.
|
__toString
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
BSD-3-Clause
|
public function modifyClone(string $modify = ''): static
{
$dolly = clone $this;
return $modify ? $dolly->modify($modify) : $dolly;
}
|
You'd better use: (clone $dt)->modify(...)
|
modifyClone
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
|
BSD-3-Clause
|
public function getRelativePathname(): string
{
return ($this->relativePath === '' ? '' : $this->relativePath . DIRECTORY_SEPARATOR)
. $this->getBasename();
}
|
Returns the relative path including file name.
|
getRelativePathname
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
|
BSD-3-Clause
|
public function read(): string
{
return FileSystem::read($this->getPathname());
}
|
Returns the contents of the file.
@throws Nette\IOException
|
read
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
|
BSD-3-Clause
|
public function write(string $content): void
{
FileSystem::write($this->getPathname(), $content);
}
|
Writes the contents to the file.
@throws Nette\IOException
|
write
|
php
|
sebastianbergmann/php-text-template
|
tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
|
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
|
BSD-3-Clause
|
public static function createDir(string $dir, int $mode = 0777): void
{
if (!is_dir($dir) && !@mkdir($dir, $mode, recursive: true) && !is_dir($dir)) { // @ - dir may already exist
throw new Nette\IOException(sprintf(
"Unable to create directory '%s' with mode %s. %s",
self::normalizePath($dir),
decoct($mode),
Helpers::getLastError(),
));
}
}
|
Creates a directory if it does not exist, including parent directories.
@throws Nette\IOException on error occurred
|
createDir
|
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 copy(string $origin, string $target, bool $overwrite = true): void
{
if (stream_is_local($origin) && !file_exists($origin)) {
throw new Nette\IOException(sprintf("File or directory '%s' not found.", self::normalizePath($origin)));
} elseif (!$overwrite && file_exists($target)) {
throw new Nette\InvalidStateException(sprintf("File or directory '%s' already exists.", self::normalizePath($target)));
} elseif (is_dir($origin)) {
static::createDir($target);
foreach (new \FilesystemIterator($target) as $item) {
static::delete($item->getPathname());
}
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($origin, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
if ($item->isDir()) {
static::createDir($target . '/' . $iterator->getSubPathName());
} else {
static::copy($item->getPathname(), $target . '/' . $iterator->getSubPathName());
}
}
} else {
static::createDir(dirname($target));
if (@stream_copy_to_stream(static::open($origin, 'rb'), static::open($target, 'wb')) === false) { // @ is escalated to exception
throw new Nette\IOException(sprintf(
"Unable to copy file '%s' to '%s'. %s",
self::normalizePath($origin),
self::normalizePath($target),
Helpers::getLastError(),
));
}
}
}
|
Copies a file or an entire directory. Overwrites existing files and directories by default.
@throws Nette\IOException on error occurred
@throws Nette\InvalidStateException if $overwrite is set to false and destination already exists
|
copy
|
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 open(string $path, string $mode)
{
$f = @fopen($path, $mode); // @ is escalated to exception
if (!$f) {
throw new Nette\IOException(sprintf(
"Unable to open file '%s'. %s",
self::normalizePath($path),
Helpers::getLastError(),
));
}
return $f;
}
|
Opens file and returns resource.
@return resource
@throws Nette\IOException on error occurred
|
open
|
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 delete(string $path): void
{
if (is_file($path) || is_link($path)) {
$func = DIRECTORY_SEPARATOR === '\\' && is_dir($path) ? 'rmdir' : 'unlink';
if (!@$func($path)) { // @ is escalated to exception
throw new Nette\IOException(sprintf(
"Unable to delete '%s'. %s",
self::normalizePath($path),
Helpers::getLastError(),
));
}
} elseif (is_dir($path)) {
foreach (new \FilesystemIterator($path) as $item) {
static::delete($item->getPathname());
}
if (!@rmdir($path)) { // @ is escalated to exception
throw new Nette\IOException(sprintf(
"Unable to delete directory '%s'. %s",
self::normalizePath($path),
Helpers::getLastError(),
));
}
}
}
|
Deletes a file or an entire directory if exists. If the directory is not empty, it deletes its contents first.
@throws Nette\IOException on error occurred
|
delete
|
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 rename(string $origin, string $target, bool $overwrite = true): void
{
if (!$overwrite && file_exists($target)) {
throw new Nette\InvalidStateException(sprintf("File or directory '%s' already exists.", self::normalizePath($target)));
} elseif (!file_exists($origin)) {
throw new Nette\IOException(sprintf("File or directory '%s' not found.", self::normalizePath($origin)));
} else {
static::createDir(dirname($target));
if (realpath($origin) !== realpath($target)) {
static::delete($target);
}
if (!@rename($origin, $target)) { // @ is escalated to exception
throw new Nette\IOException(sprintf(
"Unable to rename file or directory '%s' to '%s'. %s",
self::normalizePath($origin),
self::normalizePath($target),
Helpers::getLastError(),
));
}
}
}
|
Renames or moves a file or a directory. Overwrites existing files and directories by default.
@throws Nette\IOException on error occurred
@throws Nette\InvalidStateException if $overwrite is set to false and destination already exists
|
rename
|
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 read(string $file): string
{
$content = @file_get_contents($file); // @ is escalated to exception
if ($content === false) {
throw new Nette\IOException(sprintf(
"Unable to read file '%s'. %s",
self::normalizePath($file),
Helpers::getLastError(),
));
}
return $content;
}
|
Reads the content of a file.
@throws Nette\IOException on error occurred
|
read
|
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 readLines(string $file, bool $stripNewLines = true): \Generator
{
return (function ($f) use ($file, $stripNewLines) {
$counter = 0;
do {
$line = Callback::invokeSafe('fgets', [$f], fn($error) => throw new Nette\IOException(sprintf(
"Unable to read file '%s'. %s",
self::normalizePath($file),
$error,
)));
if ($line === false) {
fclose($f);
break;
}
if ($stripNewLines) {
$line = rtrim($line, "\r\n");
}
yield $counter++ => $line;
} while (true);
})(static::open($file, 'r'));
}
|
Reads the file content line by line. Because it reads continuously as we iterate over the lines,
it is possible to read files larger than the available memory.
@return \Generator<int, string>
@throws Nette\IOException on error occurred
|
readLines
|
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 write(string $file, string $content, ?int $mode = 0666): void
{
static::createDir(dirname($file));
if (@file_put_contents($file, $content) === false) { // @ is escalated to exception
throw new Nette\IOException(sprintf(
"Unable to write file '%s'. %s",
self::normalizePath($file),
Helpers::getLastError(),
));
}
if ($mode !== null && !@chmod($file, $mode)) { // @ is escalated to exception
throw new Nette\IOException(sprintf(
"Unable to chmod file '%s' to mode %s. %s",
self::normalizePath($file),
decoct($mode),
Helpers::getLastError(),
));
}
}
|
Writes the string to a file.
@throws Nette\IOException on error occurred
|
write
|
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.