You are here

class CachedDoubler in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Doubler/CachedDoubler.php \Prophecy\Doubler\CachedDoubler

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

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

Hierarchy

Expanded class hierarchy of CachedDoubler

File

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

Namespace

Prophecy\Doubler
View source
class CachedDoubler extends Doubler {
  private $classes = array();

  /**
   * {@inheritdoc}
   */
  public function registerClassPatch(ClassPatch\ClassPatchInterface $patch) {
    $this->classes[] = array();
    parent::registerClassPatch($patch);
  }

  /**
   * {@inheritdoc}
   */
  protected function createDoubleClass(ReflectionClass $class = null, array $interfaces) {
    $classId = $this
      ->generateClassId($class, $interfaces);
    if (isset($this->classes[$classId])) {
      return $this->classes[$classId];
    }
    return $this->classes[$classId] = parent::createDoubleClass($class, $interfaces);
  }

  /**
   * @param ReflectionClass   $class
   * @param ReflectionClass[] $interfaces
   *
   * @return string
   */
  private function generateClassId(ReflectionClass $class = null, array $interfaces) {
    $parts = array();
    if (null !== $class) {
      $parts[] = $class
        ->getName();
    }
    foreach ($interfaces as $interface) {
      $parts[] = $interface
        ->getName();
    }
    sort($parts);
    return md5(implode('', $parts));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CachedDoubler::$classes private property
CachedDoubler::createDoubleClass protected function Creates double class and returns its FQN. Overrides Doubler::createDoubleClass
CachedDoubler::generateClassId private function
CachedDoubler::registerClassPatch public function Registers new class patch. Overrides Doubler::registerClassPatch
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::__construct public function Initializes doubler.