예제 #1
0
 public function registerPackage($pkg)
 {
     if (is_string($pkg)) {
         $pkg = \Package::getClass($pkg);
     }
     $pkgHandle = $pkg->getPackageHandle();
     $loader = new ModifiedPSR4ClassLoader();
     $loader->addPrefix(NAMESPACE_SEGMENT_VENDOR . '\\Package\\' . camelcase($pkgHandle) . '\\Attribute', DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_ATTRIBUTES);
     $loader->addPrefix(NAMESPACE_SEGMENT_VENDOR . '\\Package\\' . camelcase($pkgHandle) . '\\MenuItem', DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_MENU_ITEMS);
     $loader->addPrefix(NAMESPACE_SEGMENT_VENDOR . '\\Package\\' . camelcase($pkgHandle) . '\\Authentication', DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_AUTHENTICATION);
     $loader->addPrefix(NAMESPACE_SEGMENT_VENDOR . '\\Package\\' . camelcase($pkgHandle) . '\\Block', DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_BLOCKS);
     $loader->addPrefix(NAMESPACE_SEGMENT_VENDOR . '\\Package\\' . camelcase($pkgHandle) . '\\Theme', DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_THEMES);
     $loader->addPrefix(NAMESPACE_SEGMENT_VENDOR . '\\Package\\' . camelcase($pkgHandle) . '\\Controller\\PageType', DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_TYPES);
     $loader->addPrefix(NAMESPACE_SEGMENT_VENDOR . '\\Package\\' . camelcase($pkgHandle) . '\\Controller', DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CONTROLLERS);
     $loader->addPrefix(NAMESPACE_SEGMENT_VENDOR . '\\Package\\' . camelcase($pkgHandle) . '\\Job', DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JOBS);
     $this->loaders[] = $loader;
     $loader->register();
     $loader = new Psr4ClassLoader();
     $loaders = $pkg->getPackageAutoloaderRegistries();
     if (count($loaders) > 0) {
         foreach ($loaders as $path => $prefix) {
             $loader->addPrefix($prefix, DIR_PACKAGES . '/' . $pkgHandle . '/' . $path);
         }
     }
     /** @type Package $pkg */
     if (!$pkg->shouldEnableLegacyNamespace()) {
         // We map all src files in the package to the src/Concrete directory
         $loader->addPrefix(NAMESPACE_SEGMENT_VENDOR . '\\Package\\' . camelcase($pkgHandle), DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CLASSES . '/Concrete');
         $loader->addPrefix(NAMESPACE_SEGMENT_VENDOR . '\\Package\\' . camelcase($pkgHandle) . '\\Entity', DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CLASSES . '/Entity');
     } else {
         // legacy Src support
         $loader->addPrefix(NAMESPACE_SEGMENT_VENDOR . '\\Package\\' . camelcase($pkgHandle) . '\\Src', DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CLASSES);
     }
     $this->loaders[] = $loader;
     $loader->register();
     $this->registerPackageController($pkgHandle);
 }
예제 #2
0
 public function registerPackageCustomAutoloaders($pkg)
 {
     if (is_string($pkg)) {
         $pkg = \Package::getClass($pkg);
     }
     $pkgHandle = $pkg->getPackageHandle();
     $loader = new Psr4ClassLoader();
     $loaders = $pkg->getPackageAutoloaderRegistries();
     if (count($loaders) > 0) {
         foreach ($loaders as $path => $prefix) {
             $loader->addPrefix($prefix, DIR_PACKAGES . '/' . $pkgHandle . '/' . $path);
         }
     }
     $this->loaders[] = $loader;
     $loader->register();
 }