예제 #1
0
 /**
  * @test
  */
 public function classesFromPsr4PackagesAreLoaded()
 {
     $this->mockPackage1->expects($this->any())->method('getAutoloadType')->will($this->returnValue(Package::AUTOLOADER_TYPE_PSR4));
     mkdir('vfs://Test/Packages/Application/Acme.MyApp/Classes', 0770, TRUE);
     file_put_contents('vfs://Test/Packages/Application/Acme.MyApp/Classes/Foo.php', '<?php ' . __CLASS__ . '::$testClassWasLoaded = TRUE; ?>');
     $this->classLoader->setPackages($this->mockPackages, $this->mockPackages);
     $this->classLoader->loadClass('Acme\\MyApp\\Foo');
     $this->assertTrue(self::$testClassWasLoaded);
 }
예제 #2
0
 /**
  * Initializes the package manager
  *
  * @param \TYPO3\Flow\Core\Bootstrap $bootstrap The current bootstrap
  * @return void
  */
 public function initialize(\TYPO3\Flow\Core\Bootstrap $bootstrap)
 {
     $this->systemLogger = new \TYPO3\Flow\Log\EarlyLogger();
     $this->bootstrap = $bootstrap;
     $this->packageStatesPathAndFilename = $this->packageStatesPathAndFilename ?: FLOW_PATH_CONFIGURATION . 'PackageStates.php';
     $this->packageFactory = new PackageFactory($this);
     $this->loadPackageStates();
     foreach ($this->packages as $packageKey => $package) {
         if ($package->isProtected() || isset($this->packageStatesConfiguration['packages'][$packageKey]['state']) && $this->packageStatesConfiguration['packages'][$packageKey]['state'] === 'active') {
             $this->activePackages[$packageKey] = $package;
         }
     }
     $this->classLoader->setPackages($this->activePackages);
     foreach ($this->activePackages as $package) {
         $package->boot($bootstrap);
     }
 }
 /**
  * @test
  */
 public function classesFromOverlayedPsr4PackagesAreOverwritten()
 {
     $this->classLoader = new ClassLoader();
     $mockPackage1 = $this->getMockBuilder(\TYPO3\Flow\Package\Package::class)->disableOriginalConstructor()->getMock();
     $mockPackage1->expects($this->any())->method('getNamespace')->will($this->returnValue('TestPackage\\Foo'));
     $mockPackage1->expects($this->any())->method('getFlattenedAutoloadConfiguration')->will($this->returnValue([['namespace' => 'TestPackage\\Foo', 'classPath' => 'vfs://Test/Packages/Libraries/test/subPackage/src/', 'mappingType' => ClassLoader::MAPPING_TYPE_PSR4]]));
     $mockPackage2 = $this->getMockBuilder(\TYPO3\Flow\Package\Package::class)->disableOriginalConstructor()->getMock();
     $mockPackage2->expects($this->any())->method('getNamespace')->will($this->returnValue('TestPackage'));
     $mockPackage2->expects($this->any())->method('getFlattenedAutoloadConfiguration')->will($this->returnValue([['namespace' => 'TestPackage', 'classPath' => 'vfs://Test/Packages/Libraries/test/mainPackage/src/', 'mappingType' => ClassLoader::MAPPING_TYPE_PSR4]]));
     $packages = array($mockPackage2, $mockPackage1);
     mkdir('vfs://Test/Packages/Libraries/test/subPackage/src/', 0770, true);
     mkdir('vfs://Test/Packages/Libraries/test/mainPackage/src/Foo', 0770, true);
     file_put_contents('vfs://Test/Packages/Libraries/test/subPackage/src/Bar3.php', '<?php ' . __CLASS__ . '::$testClassWasOverwritten = TRUE; ?>');
     file_put_contents('vfs://Test/Packages/Libraries/test/mainPackage/src/Foo/Bar3.php', '<?php ' . __CLASS__ . '::$testClassWasOverwritten = FALSE; ?>');
     $this->classLoader->setPackages($packages);
     $this->classLoader->loadClass('TestPackage\\Foo\\Bar3');
     $this->assertTrue(self::$testClassWasOverwritten);
 }
 /**
  * @test
  */
 public function classesFromOverlayedPsr4PackagesAreOverwritten()
 {
     $this->classLoader = new ClassLoader();
     $mockPackage1 = $this->getMockBuilder('TYPO3\\Flow\\Package\\Package')->disableOriginalConstructor()->getMock();
     $mockPackage1->expects($this->any())->method('getAutoloadType')->will($this->returnValue(Package::AUTOLOADER_TYPE_PSR4));
     $mockPackage1->expects($this->any())->method('getNamespace')->will($this->returnValue('TestPackage\\Foo'));
     $mockPackage1->expects($this->any())->method('getClassesPath')->will($this->returnValue('vfs://Test/Packages/Libraries/test/subPackage/src/'));
     $mockPackage1->expects($this->any())->method('getPackagePath')->will($this->returnValue('vfs://Test/Packages/Libraries/test/subPackage/src/'));
     $mockPackage2 = $this->getMockBuilder('TYPO3\\Flow\\Package\\Package')->disableOriginalConstructor()->getMock();
     $mockPackage2->expects($this->any())->method('getAutoloadType')->will($this->returnValue(Package::AUTOLOADER_TYPE_PSR4));
     $mockPackage2->expects($this->any())->method('getNamespace')->will($this->returnValue('TestPackage'));
     $mockPackage2->expects($this->any())->method('getClassesPath')->will($this->returnValue('vfs://Test/Packages/Libraries/test/mainPackage/src/'));
     $mockPackage2->expects($this->any())->method('getPackagePath')->will($this->returnValue('vfs://Test/Packages/Libraries/test/mainPackage/src/'));
     $packages = array($mockPackage2, $mockPackage1);
     mkdir('vfs://Test/Packages/Libraries/test/subPackage/src/', 0770, TRUE);
     mkdir('vfs://Test/Packages/Libraries/test/mainPackage/src/Foo', 0770, TRUE);
     file_put_contents('vfs://Test/Packages/Libraries/test/subPackage/src/Bar.php', '<?php ' . __CLASS__ . '::$testClassWasOverwritten = TRUE; ?>');
     file_put_contents('vfs://Test/Packages/Libraries/test/mainPackage/src/Foo/Bar.php', '<?php ' . __CLASS__ . '::$testClassWasOverwritten = FALSE; ?>');
     $this->classLoader->setPackages($packages, $packages);
     $this->classLoader->loadClass('TestPackage\\Foo\\Bar');
     $this->assertTrue(self::$testClassWasOverwritten);
 }
 /**
  * Brings the composer autoload configuration into an easy to use format for various parts of Flow.
  *
  * @return void
  */
 protected function explodeAutoloadConfiguration()
 {
     $this->namespaces = [];
     $this->autoloadTypes = [];
     $this->flattenedAutoloadConfiguration = [];
     $allAutoloadConfiguration = $this->autoloadConfiguration;
     foreach ($allAutoloadConfiguration as $autoloadType => $autoloadConfiguration) {
         $this->autoloadTypes[] = $autoloadType;
         if (ClassLoader::isAutoloadTypeWithPredictableClassPath($autoloadType)) {
             $this->namespaces = array_merge($this->namespaces, array_keys($autoloadConfiguration));
             foreach ($autoloadConfiguration as $namespace => $paths) {
                 $paths = (array) $paths;
                 foreach ($paths as $path) {
                     $this->flattenedAutoloadConfiguration[] = ['namespace' => $namespace, 'classPath' => $this->packagePath . $path, 'mappingType' => $autoloadType];
                 }
             }
         }
     }
 }