Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SplCaster.php

function SplCaster::castFileInfo

File

vendor/symfony/var-dumper/Caster/SplCaster.php, line 66

Class

SplCaster
Casts SPL related classes to array representation.

Namespace

Symfony\Component\VarDumper\Caster

Code

public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, bool $isNested) : array {
    static $map = [
        'path' => 'getPath',
        'filename' => 'getFilename',
        'basename' => 'getBasename',
        'pathname' => 'getPathname',
        'extension' => 'getExtension',
        'realPath' => 'getRealPath',
        'aTime' => 'getATime',
        'mTime' => 'getMTime',
        'cTime' => 'getCTime',
        'inode' => 'getInode',
        'size' => 'getSize',
        'perms' => 'getPerms',
        'owner' => 'getOwner',
        'group' => 'getGroup',
        'type' => 'getType',
        'writable' => 'isWritable',
        'readable' => 'isReadable',
        'executable' => 'isExecutable',
        'file' => 'isFile',
        'dir' => 'isDir',
        'link' => 'isLink',
        'linkTarget' => 'getLinkTarget',
    ];
    $prefix = Caster::PREFIX_VIRTUAL;
    unset($a["\x00SplFileInfo\x00fileName"]);
    unset($a["\x00SplFileInfo\x00pathName"]);
    try {
        $c->isReadable();
    } catch (\RuntimeException $e) {
        if ('Object not initialized' !== $e->getMessage()) {
            throw $e;
        }
        $a[$prefix . '⚠'] = 'The parent constructor was not called: the object is in an invalid state';
        return $a;
    } catch (\Error $e) {
        if ('Object not initialized' !== $e->getMessage()) {
            throw $e;
        }
        $a[$prefix . '⚠'] = 'The parent constructor was not called: the object is in an invalid state';
        return $a;
    }
    foreach ($map as $key => $accessor) {
        try {
            $a[$prefix . $key] = $c->{$accessor}();
        } catch (\Exception) {
        }
    }
    if ($a[$prefix . 'realPath'] ?? false) {
        $a[$prefix . 'realPath'] = new LinkStub($a[$prefix . 'realPath']);
    }
    if (isset($a[$prefix . 'perms'])) {
        $a[$prefix . 'perms'] = new ConstStub(\sprintf('0%o', $a[$prefix . 'perms']), $a[$prefix . 'perms']);
    }
    static $mapDate = [
        'aTime',
        'mTime',
        'cTime',
    ];
    foreach ($mapDate as $key) {
        if (isset($a[$prefix . $key])) {
            $a[$prefix . $key] = new ConstStub(date('Y-m-d H:i:s', $a[$prefix . $key]), $a[$prefix . $key]);
        }
    }
    return $a;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal