From 8cec5a9064b6d5992f14bf372eb34a2c29c208f5 Mon Sep 17 00:00:00 2001 From: Dyan Galih Date: Tue, 2 Jul 2019 07:12:25 +0700 Subject: [PATCH] Add Lazy Class Feature --- src/Tools/Lazy.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/Tools/Lazy.php diff --git a/src/Tools/Lazy.php b/src/Tools/Lazy.php new file mode 100644 index 0000000..088e7a4 --- /dev/null +++ b/src/Tools/Lazy.php @@ -0,0 +1,34 @@ + + * Date: 2019-07-02 + * Time: 07:11 + * Class Lazy + * @package WebAppId\DDD\Tools + */ +class Lazy +{ + /** + * @param object $fromClass + * @param object $toClass + * @param bool $strict + * @return object + */ + public static function copy(object $fromClass, object $toClass, bool $strict = false): object + { + foreach (get_object_vars($fromClass) as $key => $value) { + if ($strict) { + if (property_exists($toClass, $key)) { + $toClass->$key = $value; + } + } else { + $toClass->$key = $value; + } + } + return $toClass; + } +} \ No newline at end of file