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

Breadcrumb

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

function Exporter::getArrayObjectProperties

Parameters

\ArrayIterator|\ArrayObject $value:

\ArrayIterator|\ArrayObject $proto:

1 call to Exporter::getArrayObjectProperties()
Exporter::prepare in vendor/symfony/var-exporter/Internal/Exporter.php
Prepares an array of values for VarExporter.

File

vendor/symfony/var-exporter/Internal/Exporter.php, line 384

Class

Exporter
@author Nicolas Grekas <p@tchwork.com>

Namespace

Symfony\Component\VarExporter\Internal

Code

private static function getArrayObjectProperties($value, $proto) : array {
    $reflector = $value instanceof \ArrayIterator ? 'ArrayIterator' : 'ArrayObject';
    $reflector = Registry::$reflectors[$reflector] ??= Registry::getClassReflector($reflector);
    $properties = [
        $arrayValue = (array) $value,
        $reflector->getMethod('getFlags')
            ->invoke($value),
        $value instanceof \ArrayObject ? $reflector->getMethod('getIteratorClass')
            ->invoke($value) : 'ArrayIterator',
    ];
    $reflector = $reflector->getMethod('setFlags');
    $reflector->invoke($proto, \ArrayObject::STD_PROP_LIST);
    if ($properties[1] & \ArrayObject::STD_PROP_LIST) {
        $reflector->invoke($value, 0);
        $properties[0] = (array) $value;
    }
    else {
        $reflector->invoke($value, \ArrayObject::STD_PROP_LIST);
        $arrayValue = (array) $value;
    }
    $reflector->invoke($value, $properties[1]);
    if ([
        [],
        0,
        'ArrayIterator',
    ] === $properties) {
        $properties = [];
    }
    else {
        if ('ArrayIterator' === $properties[2]) {
            unset($properties[2]);
        }
        $properties = [
            $reflector->class => [
                "\x00" => $properties,
            ],
        ];
    }
    return [
        $arrayValue,
        $properties,
    ];
}
RSS feed
Powered by Drupal