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

Breadcrumb

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

function DeepCopy::copyObjectProperty

1 call to DeepCopy::copyObjectProperty()
DeepCopy::copyObject in vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php
Copies an object.

File

vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php, line 223

Class

DeepCopy
@final

Namespace

DeepCopy

Code

private function copyObjectProperty($object, ReflectionProperty $property) {
    // Ignore static properties
    if ($property->isStatic()) {
        return;
    }
    // Ignore readonly properties
    if (method_exists($property, 'isReadOnly') && $property->isReadOnly()) {
        return;
    }
    // Apply the filters
    foreach ($this->filters as $item) {
        
        /** @var Matcher $matcher */
        $matcher = $item['matcher'];
        
        /** @var Filter $filter */
        $filter = $item['filter'];
        if ($matcher->matches($object, $property->getName())) {
            $filter->apply($object, $property->getName(), function ($object) {
                return $this->recursiveCopy($object);
            });
            if ($filter instanceof ChainableFilter) {
                continue;
            }
            // If a filter matches, we stop processing this property
            return;
        }
    }
    $property->setAccessible(true);
    // Ignore uninitialized properties (for PHP >7.4)
    if (method_exists($property, 'isInitialized') && !$property->isInitialized($object)) {
        return;
    }
    $propertyValue = $property->getValue($object);
    // Copy the property
    $property->setValue($object, $this->recursiveCopy($propertyValue));
}
RSS feed
Powered by Drupal