ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
League\Flysystem\Util Class Reference
+ Collaboration diagram for League\Flysystem\Util:

Static Public Member Functions

static pathinfo ($path)
 Get normalized pathinfo. More...
 
static normalizeDirname ($dirname)
 Normalize a dirname return value. More...
 
static dirname ($path)
 Get a normalized dirname from a path. More...
 
static map (array $object, array $map)
 Map result arrays. More...
 
static normalizePath ($path)
 Normalize path. More...
 
static normalizeRelativePath ($path)
 Normalize relative directories in a path. More...
 
static normalizePrefix ($prefix, $separator)
 Normalize prefix. More...
 
static contentSize ($contents)
 Get content size. More...
 
static guessMimeType ($path, $content)
 Guess MIME Type based on the path of the file and it's content. More...
 
static emulateDirectories (array $listing)
 Emulate directories. More...
 
static ensureConfig ($config)
 Ensure a Config instance. More...
 
static rewindStream ($resource)
 Rewind a stream. More...
 
static isSeekableStream ($resource)
 
static getStreamSize ($resource)
 Get the size of a stream. More...
 

Static Protected Member Functions

static removeFunkyWhiteSpace ($path)
 Removes unprintable characters and invalid unicode characters. More...
 
static emulateObjectDirectories (array $object, array $directories, array $listedDirectories)
 Emulate the directories of a single object. More...
 

Detailed Description

Definition at line 8 of file Util.php.

Member Function Documentation

◆ contentSize()

static League\Flysystem\Util::contentSize (   $contents)
static

Get content size.

Parameters
string$contents
Returns
int content size

Definition at line 164 of file Util.php.

165 {
166 return defined('MB_OVERLOAD_STRING') ? mb_strlen($contents, '8bit') : strlen($contents);
167 }

◆ dirname()

static League\Flysystem\Util::dirname (   $path)
static

Get a normalized dirname from a path.

Parameters
string$path
Returns
string dirname

Definition at line 45 of file Util.php.

46 {
47 return static::normalizeDirname(dirname($path));
48 }
$path
Definition: aliased.php:25
static dirname($path)
Get a normalized dirname from a path.
Definition: Util.php:45

References $path, and League\Flysystem\Util\dirname().

Referenced by League\Flysystem\Util\dirname(), League\Flysystem\Util\ContentListingFormatter\isDirectChild(), League\Flysystem\Adapter\Local\rename(), and League\Flysystem\Adapter\Ftp\writeStream().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emulateDirectories()

static League\Flysystem\Util::emulateDirectories ( array  $listing)
static

Emulate directories.

Parameters
array$listing
Returns
array listing with emulated directories

Definition at line 195 of file Util.php.

196 {
197 $directories = [];
198 $listedDirectories = [];
199
200 foreach ($listing as $object) {
201 list($directories, $listedDirectories) = static::emulateObjectDirectories(
202 $object,
203 $directories,
204 $listedDirectories
205 );
206 }
207
208 $directories = array_diff(array_unique($directories), array_unique($listedDirectories));
209
210 foreach ($directories as $directory) {
211 $listing[] = static::pathinfo($directory) + ['type' => 'dir'];
212 }
213
214 return $listing;
215 }

◆ emulateObjectDirectories()

static League\Flysystem\Util::emulateObjectDirectories ( array  $object,
array  $directories,
array  $listedDirectories 
)
staticprotected

Emulate the directories of a single object.

Parameters
array$object
array$directories
array$listedDirectories
Returns
array

Definition at line 285 of file Util.php.

286 {
287 if ($object['type'] === 'dir') {
288 $listedDirectories[] = $object['path'];
289 }
290
291 if (empty($object['dirname'])) {
292 return [$directories, $listedDirectories];
293 }
294
295 $parent = $object['dirname'];
296
297 while ( ! empty($parent) && ! in_array($parent, $directories)) {
298 $directories[] = $parent;
299 $parent = static::dirname($parent);
300 }
301
302 if (isset($object['type']) && $object['type'] === 'dir') {
303 $listedDirectories[] = $object['path'];
304
305 return [$directories, $listedDirectories];
306 }
307
308 return [$directories, $listedDirectories];
309 }

◆ ensureConfig()

static League\Flysystem\Util::ensureConfig (   $config)
static

Ensure a Config instance.

Parameters
null | array | Config$config
Returns
Config config instance
Exceptions
LogicException

Definition at line 226 of file Util.php.

227 {
228 if ($config === null) {
229 return new Config();
230 }
231
232 if ($config instanceof Config) {
233 return $config;
234 }
235
236 if (is_array($config)) {
237 return new Config($config);
238 }
239
240 throw new LogicException('A config should either be an array or a Flysystem\Config object.');
241 }
$config
Definition: bootstrap.php:15

References $config.

Referenced by League\Flysystem\setConfig().

+ Here is the caller graph for this function:

◆ getStreamSize()

static League\Flysystem\Util::getStreamSize (   $resource)
static

Get the size of a stream.

Parameters
resource$resource
Returns
int stream size

Definition at line 269 of file Util.php.

270 {
271 $stat = fstat($resource);
272
273 return $stat['size'];
274 }

◆ guessMimeType()

static League\Flysystem\Util::guessMimeType (   $path,
  $content 
)
static

Guess MIME Type based on the path of the file and it's content.

Parameters
string$path
string | resource$content
Returns
string|null MIME Type or NULL if no extension detected

Definition at line 177 of file Util.php.

178 {
179 $mimeType = MimeType::detectByContent($content);
180
181 if ( ! (empty($mimeType) || in_array($mimeType, ['application/x-empty', 'text/plain', 'text/x-asm']))) {
182 return $mimeType;
183 }
184
186 }
static detectByFilename($filename)
Definition: MimeType.php:61
static detectByContent($content)
Detects MIME Type based on given content.
Definition: MimeType.php:20

References $path, League\Flysystem\Util\MimeType\detectByContent(), and League\Flysystem\Util\MimeType\detectByFilename().

Referenced by League\Flysystem\Adapter\Local\update(), and League\Flysystem\Adapter\Ftp\write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSeekableStream()

static League\Flysystem\Util::isSeekableStream (   $resource)
static

Definition at line 255 of file Util.php.

256 {
257 $metadata = stream_get_meta_data($resource);
258
259 return $metadata['seekable'];
260 }
$metadata['__DYNAMIC:1__']

References $metadata.

◆ map()

static League\Flysystem\Util::map ( array  $object,
array  $map 
)
static

Map result arrays.

Parameters
array$object
array$map
Returns
array mapped result

Definition at line 58 of file Util.php.

59 {
60 $result = [];
61
62 foreach ($map as $from => $to) {
63 if ( ! isset($object[$from])) {
64 continue;
65 }
66
67 $result[$to] = $object[$from];
68 }
69
70 return $result;
71 }
$result
$from

References $from, $map, and $result.

◆ normalizeDirname()

static League\Flysystem\Util::normalizeDirname (   $dirname)
static

Normalize a dirname return value.

Parameters
string$dirname
Returns
string normalized dirname

Definition at line 33 of file Util.php.

34 {
35 return $dirname === '.' ? '' : $dirname;
36 }

◆ normalizePath()

◆ normalizePrefix()

static League\Flysystem\Util::normalizePrefix (   $prefix,
  $separator 
)
static

Normalize prefix.

Parameters
string$prefix
string$separator
Returns
string normalized path

Definition at line 152 of file Util.php.

153 {
154 return rtrim($prefix, $separator) . $separator;
155 }

◆ normalizeRelativePath()

static League\Flysystem\Util::normalizeRelativePath (   $path)
static

Normalize relative directories in a path.

Parameters
string$path
Exceptions
LogicException
Returns
string

Definition at line 96 of file Util.php.

97 {
98 $path = str_replace('\\', '/', $path);
99 $path = static::removeFunkyWhiteSpace($path);
100
101 $parts = [];
102
103 foreach (explode('/', $path) as $part) {
104 switch ($part) {
105 case '':
106 case '.':
107 break;
108
109 case '..':
110 if (empty($parts)) {
111 throw new LogicException(
112 'Path is outside of the defined root, path: [' . $path . ']'
113 );
114 }
115 array_pop($parts);
116 break;
117
118 default:
119 $parts[] = $part;
120 break;
121 }
122 }
123
124 return implode('/', $parts);
125 }

References $path.

Referenced by ILIAS\FileUpload\Processor\FilenameSanitizerPreProcessor\process().

+ Here is the caller graph for this function:

◆ pathinfo()

static League\Flysystem\Util::pathinfo (   $path)
static

Get normalized pathinfo.

Parameters
string$path
Returns
array pathinfo

Definition at line 17 of file Util.php.

18 {
19 $pathinfo = pathinfo($path) + compact('path');
20 $pathinfo['dirname'] = array_key_exists('dirname', $pathinfo)
21 ? static::normalizeDirname($pathinfo['dirname']) : '';
22
23 return $pathinfo;
24 }
static pathinfo($path)
Get normalized pathinfo.
Definition: Util.php:17

References $path, and League\Flysystem\Util\pathinfo().

Referenced by League\Flysystem\Util\ContentListingFormatter\addPathInfo(), League\Flysystem\Util\MimeType\detectByFilename(), and League\Flysystem\Util\pathinfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeFunkyWhiteSpace()

static League\Flysystem\Util::removeFunkyWhiteSpace (   $path)
staticprotected

Removes unprintable characters and invalid unicode characters.

Parameters
string$path
Returns
string $path

Definition at line 134 of file Util.php.

134 {
135 // We do this check in a loop, since removing invalid unicode characters
136 // can lead to new characters being created.
137 while (preg_match('#\p{C}+|^\./#u', $path)) {
138 $path = preg_replace('#\p{C}+|^\./#u', '', $path);
139 }
140
141 return $path;
142 }

References $path.

◆ rewindStream()

static League\Flysystem\Util::rewindStream (   $resource)
static

Rewind a stream.

Parameters
resource$resource

Definition at line 248 of file Util.php.

249 {
250 if (ftell($resource) !== 0 && static::isSeekableStream($resource)) {
251 rewind($resource);
252 }
253 }

Referenced by League\Flysystem\Filesystem\putStream(), League\Flysystem\Filesystem\updateStream(), and League\Flysystem\Filesystem\writeStream().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: