HEX
Server: LiteSpeed
System: Linux server.zepintelhosting.com 4.18.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64
User: enamadmin (1026)
PHP: 8.2.30
Disabled: exec,system,passthru,shell_exec,proc_open,popen,apache_child_terminate
Upload Files
File: /home/enamadmin/www/elearning_plateforme1/lib/spatie/php-cloneable/src/Cloneable.php
<?php

namespace Spatie\Cloneable;

use ReflectionClass;

trait Cloneable
{
    public function with(...$values): static
    {
        $refClass = new ReflectionClass(static::class);
        $clone = $refClass->newInstanceWithoutConstructor();

        foreach ($refClass->getProperties() as $property) {
            if ($property->isStatic()) {
                continue;
            }

            $objectField = $property->getName();

            if (array_key_exists($objectField, $values)) {
                $objectValue = $values[$objectField];
            } elseif ($property->isInitialized($this)) {
                $objectValue = $property->getValue($this);
            } else {
                continue;
            }

            $declarationScope = $property->getDeclaringClass()->getName();
            if ($declarationScope === self::class) {
                $clone->$objectField = $objectValue;
            } else {
                (fn () => $this->$objectField = $objectValue)
                    ->bindTo($clone, $declarationScope)();
            }
        }

        return $clone;
    }
}