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

Breadcrumb

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

class CachedDoubler

Cached class doubler. Prevents mirroring/creation of the same structure twice.

@author Konstantin Kudryashov <ever.zet@gmail.com>

Hierarchy

  • class \Prophecy\Doubler\Doubler
    • class \Prophecy\Doubler\CachedDoubler extends \Prophecy\Doubler\Doubler

Expanded class hierarchy of CachedDoubler

1 file declares its use of CachedDoubler
Prophet.php in vendor/phpspec/prophecy/src/Prophecy/Prophet.php

File

vendor/phpspec/prophecy/src/Prophecy/Doubler/CachedDoubler.php, line 22

Namespace

Prophecy\Doubler
View source
class CachedDoubler extends Doubler {
    
    /**
     * @var array<string, class-string>
     */
    private static $classes = array();
    protected function createDoubleClass(?ReflectionClass $class, array $interfaces) {
        $classId = $this->generateClassId($class, $interfaces);
        if (isset(self::$classes[$classId])) {
            return self::$classes[$classId];
        }
        return self::$classes[$classId] = parent::createDoubleClass($class, $interfaces);
    }
    
    /**
     * @param ReflectionClass<object>|null $class
     * @param ReflectionClass<object>[]    $interfaces
     *
     * @return string
     */
    private function generateClassId(?ReflectionClass $class, array $interfaces) {
        $parts = array();
        if (null !== $class) {
            $parts[] = $class->getName();
        }
        foreach ($interfaces as $interface) {
            $parts[] = $interface->getName();
        }
        foreach ($this->getClassPatches() as $patch) {
            $parts[] = get_class($patch);
        }
        sort($parts);
        return md5(implode('', $parts));
    }
    
    /**
     * @return void
     */
    public function resetCache() {
        self::$classes = array();
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
CachedDoubler::$classes private static property
CachedDoubler::createDoubleClass protected function Creates double class and returns its FQN. Overrides Doubler::createDoubleClass
CachedDoubler::generateClassId private function
CachedDoubler::resetCache public function
Doubler::$creator private property
Doubler::$instantiator private property
Doubler::$mirror private property
Doubler::$namer private property
Doubler::$patches private property
Doubler::double public function Creates double from specific class or/and list of interfaces.
Doubler::getClassPatches public function Returns list of registered class patches.
Doubler::registerClassPatch public function Registers new class patch.
Doubler::__construct public function
RSS feed
Powered by Drupal