예제 #1
0
 /**
  * Retrieve instance type with interception processing
  *
  * @param string $instanceName
  * @return string
  */
 public function getInstanceType($instanceName)
 {
     $type = parent::getInstanceType($instanceName);
     if ($this->interceptionConfig && $this->interceptionConfig->hasPlugins($instanceName) && $this->interceptableValidator->validate($instanceName)) {
         return $type . '\\Interceptor';
     }
     return $type;
 }
 /**
  * @dataProvider getInterceptionConfigurationDataProvider
  */
 public function testGetInterceptionConfiguration($plugins)
 {
     $definedClasses = ['Class1'];
     $this->interceptionConfig->expects($this->once())->method('hasPlugins')->with('Class1')->willReturn(true);
     $this->typeReader->expects($this->any())->method('isConcrete')->willReturnMap([['Class1', true], ['instance', true]]);
     $this->interceptableValidator->expects($this->any())->method('validate')->with('Class1')->willReturn(true);
     $this->cacheManager->expects($this->once())->method('setEnabled')->with([CompiledConfig::TYPE_IDENTIFIER], true);
     $this->pluginList->expects($this->once())->method('setInterceptedClasses')->with($definedClasses);
     $this->pluginList->expects($this->once())->method('setScopePriorityScheme')->with(['global', 'areaCode']);
     $this->pluginList->expects($this->once())->method('getPluginsConfig')->willReturn(['instance' => $plugins]);
     $this->model->addAreaCode('areaCode');
     $this->model->getInterceptionConfiguration($definedClasses);
 }
 /**
  * Get intercepted class names
  *
  * @param array $classes
  * @param array $interceptedEntities
  * @return array
  */
 public function collectEntities(array $classes, array $interceptedEntities = [])
 {
     $output = [];
     foreach ($classes as $class) {
         foreach ($interceptedEntities as $interceptorClass) {
             $interceptedEntity = substr($interceptorClass, 0, -12);
             if (is_subclass_of($class, $interceptedEntity) && $this->interceptableValidator->validate($class)) {
                 $reflectionClass = new \ReflectionClass($class);
                 if (!$reflectionClass->isAbstract() && !$reflectionClass->isFinal()) {
                     $output[] = $class . '\\Interceptor';
                 }
             }
         }
     }
     $output = array_merge($this->filterOutAbstractClasses($interceptedEntities), $output);
     $output = array_unique($output);
     return $output;
 }
 /**
  * Get intercepted instances from defined class list
  *
  * @param array $definedClasses
  * @return array
  */
 private function getInterceptedClasses($definedClasses)
 {
     $intercepted = [];
     foreach ($definedClasses as $definedClass) {
         if ($this->interceptionConfig->hasPlugins($definedClass) && $this->typeReader->isConcrete($definedClass) && $this->interceptableValidator->validate($definedClass)) {
             $intercepted[] = $definedClass;
         }
     }
     return $intercepted;
 }