diff --git a/CHANGELOG.md b/CHANGELOG.md index 98e35e8..4607a7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [[v0.2.4](https://github.com/The-FireHub-Project/Runtime/compare/v0.2.3...v0.2.4)] – 2026-09-03 + +### Changed +* `Copy` changed behavior by @dieselxxx + +## [[v0.2.3](https://github.com/The-FireHub-Project/Runtime/compare/v0.2.2...v0.2.3)] – 2026-09-03 + +### Added +* Create `Copy` by @dieselxxx + ## [[v0.2.2](https://github.com/The-FireHub-Project/Runtime/compare/v0.2.1...v0.2.2)] – 2026-08-31 ### Added diff --git a/README.md b/README.md index 4d21b7d..e8d9159 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ /> version diff --git a/src/Copy.php b/src/Copy.php index ae0f4c5..d360080 100644 --- a/src/Copy.php +++ b/src/Copy.php @@ -24,9 +24,10 @@ * Deep copying recursively duplicates mutable arrays and objects while preserving values that are immutable, * non-copyable, or otherwise cannot safely be duplicated. * - * Objects implementing the {@see Cloneable} capability are responsible for defining their own deep-copy behavior. - * Internal PHP objects are never copied through reflection because their internal state may not be safely - * reconstructible without their constructor or native cloning semantics. + * Objects implementing the {@see Cloneable} capability expose a copy operation that delegates to this runtime + * implementation. User-defined objects are copied recursively through reflection, while internal PHP objects are + * preserved because their internal state may not be safely reconstructible without their constructor or native + * cloning semantics. * * Circular object references are preserved during the copy operation. * @since 1.0.0 @@ -127,7 +128,6 @@ private static function copyArray (array $value, array &$objects):array { * ### Copies an object according to its copy semantics * @since 1.0.0 * - * @uses self::copyCloneable() To copy objects implementing the {@see Cloneable} capability. * @uses self::copyReflective() To copy user-defined objects using reflection. * * @param object $value

@@ -145,43 +145,12 @@ private static function copyObject (object $value, array &$objects):object { if ($value instanceof Closure) return $value; - if ($value instanceof Cloneable) return self::copyCloneable($value, $objects); - if (new ReflectionObject($value)->isInternal()) return $value; return self::copyReflective($value, $objects); } - /** - * ### Creates a deep copy using the object's own copy contract - * @since 1.0.0 - * - * @uses \FireHub\Runtime\ObjectModel\Identity::id() To get the object's identifier. - * - * @param Cloneable $value

- * The object to copy. - *

- * @param array $objects

- * Previously copied objects indexed by object identifier. - *

- * - * @return object The copied object. - */ - private static function copyCloneable (Cloneable $value, array &$objects):object { - - $id = ObjectModel\Identity::id($value); - - if (isset($objects[$id])) return $objects[$id]; - - $copy = $value->copy(); - - $objects[$id] = $copy; - - return $copy; - - } - /** * ### Creates a deep copy of a user-defined object using reflection * @since 1.0.0