/**
  * This method is used to optimize the matching process.
  *
  * @param \TYPO3\Flow\Aop\Builder\ClassNameIndex $classNameIndex
  * @return \TYPO3\Flow\Aop\Builder\ClassNameIndex
  */
 public function reduceTargetClassNames(\TYPO3\Flow\Aop\Builder\ClassNameIndex $classNameIndex)
 {
     $classNames = $this->reflectionService->getClassNamesByAnnotation(Flow\ValueObject::class);
     $annotatedIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $annotatedIndex->setClassNames($classNames);
     return $classNameIndex->intersect($annotatedIndex);
 }
 /**
  * @test
  */
 public function filterByPrefixWork()
 {
     $index1 = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $index1->setClassNames(array('\\Foo\\Bar', '\\Foo\\Baz', '\\Bar\\Baz', '\\Foo\\Blubb'));
     // We need to call sort manually!
     $index1->sort();
     $filteredIndex = $index1->filterByPrefix('\\Foo');
     $this->assertEquals(array('\\Foo\\Bar', '\\Foo\\Baz', '\\Foo\\Blubb'), $filteredIndex->getClassNames());
 }
 /**
  * @test
  */
 public function reduceTargetClassNamesFiltersAllClassesNotMatchedByAClassNameFilterWithRegularExpressions()
 {
     $availableClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $expectedClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $classNameFilter = new \TYPO3\Flow\Aop\Pointcut\PointcutClassNameFilter('TestPackage\\Subpackage\\.*');
     $result = $classNameFilter->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
 /**
  * @test
  */
 public function reduceTargetClassNamesFiltersAllClassesNotHavingTheGivenAnnotation()
 {
     $availableClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $mockReflectionService = $this->getMock(\TYPO3\Flow\Reflection\ReflectionService::class, array(), array(), '', false);
     $mockReflectionService->expects($this->any())->method('getClassNamesByAnnotation')->with('SomeAnnotationClass')->will($this->returnValue(array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'SomeMoreClass')));
     $classAnnotatedWithFilter = new \TYPO3\Flow\Aop\Pointcut\PointcutClassAnnotatedWithFilter('SomeAnnotationClass');
     $classAnnotatedWithFilter->injectReflectionService($mockReflectionService);
     $expectedClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $result = $classAnnotatedWithFilter->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
 /**
  * @test
  */
 public function reduceTargetClassNamesFiltersAllClassesNotBeeingConfiguredAsScopeSession()
 {
     $availableClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $mockCompileTimeObjectManager = $this->getMock(\TYPO3\Flow\Object\CompileTimeObjectManager::class, array(), array(), '', false);
     $mockCompileTimeObjectManager->expects($this->any())->method('getClassNamesByScope')->with(\TYPO3\Flow\Object\Configuration\Configuration::SCOPE_SESSION)->will($this->returnValue(array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'SomeMoreClass')));
     $sessionObjectMethodsPointcutFilter = new \TYPO3\Flow\Session\Aspect\SessionObjectMethodsPointcutFilter();
     $sessionObjectMethodsPointcutFilter->injectObjectManager($mockCompileTimeObjectManager);
     $expectedClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $result = $sessionObjectMethodsPointcutFilter->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
 /**
  * @test
  */
 public function reduceTargetClassNamesFiltersAllClassesExceptTheClassItselfAndAllItsSubclasses()
 {
     $testClassName = uniqid('someTestInterface');
     eval('class ' . $testClassName . ' {}');
     $availableClassNames = array($testClassName, 'TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $mockReflectionService = $this->getMock(\TYPO3\Flow\Reflection\ReflectionService::class, array(), array(), '', false);
     $mockReflectionService->expects($this->any())->method('getAllSubClassNamesForClass')->with($testClassName)->will($this->returnValue(array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'SomeMoreClass')));
     $classTypeFilter = new \TYPO3\Flow\Aop\Pointcut\PointcutClassTypeFilter($testClassName);
     $classTypeFilter->injectReflectionService($mockReflectionService);
     $expectedClassNames = array($testClassName, 'TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $result = $classTypeFilter->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
 /**
  * @test
  */
 public function reduceTargetClassNamesFiltersAllClassesNotMatchedAByClassNameFilter()
 {
     $availableClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $classNameFilter1 = new \TYPO3\Flow\Aop\Pointcut\PointcutClassNameFilter('TestPackage\\Subpackage\\SubSubPackage\\Class3');
     $classNameFilter2 = new \TYPO3\Flow\Aop\Pointcut\PointcutClassNameFilter('TestPackage\\Subpackage\\Class1');
     $methodNameFilter1 = new \TYPO3\Flow\Aop\Pointcut\PointcutMethodNameFilter('method2');
     $expectedClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $pointcutFilterComposite = new \TYPO3\Flow\Aop\Pointcut\PointcutFilterComposite();
     $pointcutFilterComposite->addFilter('&&', $classNameFilter1);
     $pointcutFilterComposite->addFilter('||', $classNameFilter2);
     $pointcutFilterComposite->addFilter('&&', $methodNameFilter1);
     $result = $pointcutFilterComposite->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
 /**
  * This method is used to optimize the matching process.
  *
  * @param \TYPO3\Flow\Aop\Builder\ClassNameIndex $classNameIndex
  * @return \TYPO3\Flow\Aop\Builder\ClassNameIndex
  */
 public function reduceTargetClassNames(\TYPO3\Flow\Aop\Builder\ClassNameIndex $classNameIndex)
 {
     $classNames = $this->reflectionService->getClassesContainingMethodsAnnotatedWith($this->annotation);
     $annotatedIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $annotatedIndex->setClassNames($classNames);
     return $classNameIndex->intersect($annotatedIndex);
 }
 /**
  * @test
  */
 public function reduceTargetClassNamesPassesTheGivenClassNameIndexToAllResourceFiltersAndReturnsTheUnionOfTheirResults()
 {
     $availableClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $mockPointcutFilter1 = $this->getMock('\\TYPO3\\Flow\\Aop\\Pointcut\\PointcutFilterInterface');
     $mockPointcutFilter1->expects($this->once())->method('reduceTargetClassNames')->with($availableClassNamesIndex)->will($this->returnValue(new \TYPO3\Flow\Aop\Builder\ClassNameIndex(array('TestPackage\\Subpackage\\Class1' => TRUE))));
     $mockPointcutFilter2 = $this->getMock('\\TYPO3\\Flow\\Aop\\Pointcut\\PointcutFilterInterface');
     $mockPointcutFilter2->expects($this->once())->method('reduceTargetClassNames')->with($availableClassNamesIndex)->will($this->returnValue(new \TYPO3\Flow\Aop\Builder\ClassNameIndex(array('TestPackage\\Subpackage\\SubSubPackage\\Class3' => TRUE))));
     $policyFilterArray = array('role' => array('resource1' => $mockPointcutFilter1, 'resource2' => $mockPointcutFilter2));
     $policyService = $this->getAccessibleMock('TYPO3\\Flow\\Security\\Policy\\PolicyService', array('dummy'));
     $policyService->_set('filters', $policyFilterArray);
     $expectedClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $result = $policyService->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
 /**
  * This method is used to optimize the matching process.
  *
  * @param \TYPO3\Flow\Aop\Builder\ClassNameIndex $classNameIndex
  * @return \TYPO3\Flow\Aop\Builder\ClassNameIndex
  */
 public function reduceTargetClassNames(\TYPO3\Flow\Aop\Builder\ClassNameIndex $classNameIndex)
 {
     if (interface_exists($this->interfaceOrClassName)) {
         $classNames = $this->reflectionService->getAllImplementationClassNamesForInterface($this->interfaceOrClassName);
     } elseif (class_exists($this->interfaceOrClassName)) {
         $classNames = $this->reflectionService->getAllSubClassNamesForClass($this->interfaceOrClassName);
         $classNames[] = $this->interfaceOrClassName;
     } else {
         $classNames = array();
     }
     $filteredIndex = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $filteredIndex->setClassNames($classNames);
     return $classNameIndex->intersect($filteredIndex);
 }
 /**
  * This method is used to optimize the matching process.
  *
  * @param \TYPO3\Flow\Aop\Builder\ClassNameIndex $classNameIndex
  * @return \TYPO3\Flow\Aop\Builder\ClassNameIndex
  */
 public function reduceTargetClassNames(\TYPO3\Flow\Aop\Builder\ClassNameIndex $classNameIndex)
 {
     $sessionClasses = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     $sessionClasses->setClassNames($this->objectManager->getClassNamesByScope(ObjectConfiguration::SCOPE_SESSION));
     return $classNameIndex->intersect($sessionClasses);
 }
 /**
  * This method is used to optimize the matching process.
  *
  * @param \TYPO3\Flow\Aop\Builder\ClassNameIndex $classNameIndex
  * @return \TYPO3\Flow\Aop\Builder\ClassNameIndex
  */
 public function reduceTargetClassNames(\TYPO3\Flow\Aop\Builder\ClassNameIndex $classNameIndex)
 {
     if ($this->filters === array()) {
         $this->buildPointcutFilters();
     }
     $result = new \TYPO3\Flow\Aop\Builder\ClassNameIndex();
     foreach ($this->filters as $resources) {
         /** @var $filterForResource \TYPO3\Flow\Aop\Pointcut\PointcutFilterInterface */
         foreach ($resources as $filterForResource) {
             $result->applyUnion($filterForResource->reduceTargetClassNames($classNameIndex));
         }
     }
     return $result;
 }