/** * Builds or fetches the cloneables map * * @return CallbackLazyMap */ private function getCloneablesMap() { $cachedInstantiators = $this->getInstantiatorsMap(); return self::$cachedCloneables = self::$cachedCloneables ?: new CallbackLazyMap(function ($className) use($cachedInstantiators) { /* @var $factory Closure */ $factory = $cachedInstantiators->{$className}; $instance = $factory(); $reflection = new ReflectionClass($instance); // not cloneable if it implements `__clone`, as we want to avoid calling it if ($reflection->hasMethod('__clone')) { return null; } return $instance; }); }
/** * Builds or fetches the cloneables map * * @return CallbackLazyMap */ private function getCloneablesMap() { $cachedInstantiators = $this->getInstantiatorsMap(); $that = $this; return self::$cachedCloneables = self::$cachedCloneables ?: new CallbackLazyMap(function ($className) use($cachedInstantiators, $that) { /* @var $factory Closure */ $factory = $cachedInstantiators->{$className}; $instance = $factory(); if (!$that->isSafeToClone(new ReflectionClass($className))) { return null; } return $instance; }); }