Psr4Generator->addNamespace($prefix, $resourceOrLocation, $prepend = false); */ class PackageAutoloadGenerator implements LoaderInterface { use Nette\SmartObject; protected $packageDirectories = []; protected $ClassmapGenerator = null; protected $Psr4Generator = null; protected $RemoteAutoloader = null; protected $allowRedundancy = false; protected $_toRegister = []; public function __construct( $allowRedundancy = false, ClassmapGeneratorInterface $ClassmapGenerator = null, Psr4GeneratorInterface $Psr4Generator = null, LoaderInterface $RemoteAutoloader = null, ) { $this->ClassmapGenerator = (null !== $ClassmapGenerator) ? $ClassmapGenerator : new CodebaseLoader; $this->Psr4Generator = (null !== $Psr4Generator) ? $Psr4Generator : new LocalPsr4Autoloader; $this->RemoteAutoloader = (null !== $RemoteAutoloader) ? $RemoteAutoloader : null; // @Lacks Interface! new \Webfan\Autoload\RemoteFallbackLoader; $this->allowRedundancy=$allowRedundancy; } public function withRedundancy(bool $allowRedundancy = false) { $this->allowRedundancy=$allowRedundancy; return $this; } public function addDirectory(string $dir) { return $this->_load($dir); } public function load(string $dir) { return $this->_load($dir); } public function withDirectory($dir) { return $this->_load($dir); } protected function _withDirectoryClassmap($dir) { $this->ClassmapGenerator->addDirectory($dir); return $this; } public function loadClassmaps($classMaps) { if (!is_array($classMaps)) { $classMaps =[$classMaps]; } foreach($classMaps as $path){ if(file_exists($path) && is_file($path)){ $path = dirname($path); } $this->_withDirectoryClassmap($path); } return $this; } protected function _getComposerFile($dir) { if(!isset($this->packageDirectories[$dir])){ $this->packageDirectories[$dir]=[]; } try{ $this->packageDirectories[$dir]['json'] = json_decode(file_get_contents($dir."/composer.json"), 1); }catch(\Exception $e){ trigger_error(sprintf('% %', $e->getMessage() , __METHOD__), \E_USER_WARNING); return []; } return $this->packageDirectories[$dir]['json']; } protected function _load($dir) { $this->dir = $dir; $composer = $this->_getComposerFile($dir); if(isset($composer["autoload"]["classmap"])){ $this->loadClassmaps($composer["autoload"]["classmap"]); } if(isset($composer["autoload"]["psr-4"])){ $this->loadPSR4($composer['autoload']['psr-4']); } if(isset($composer["autoload"]["psr-0"])){ $this->loadPSR0($composer['autoload']['psr-0']); } if(isset($composer["autoload"]["files"])){ $this->loadFiles($composer["autoload"]["files"]); } } public function loadFiles($files) { foreach($files as $file){ $fullpath = //$this->dir."/". $file; if(file_exists($fullpath)){ include $fullpath; } } } public function loadPSR4($namespaces) { $this->loadPSR($namespaces, true); } public function loadPSR0($namespaces) { $this->loadPSR($namespaces, false); } public function loadPSR($namespaces, $psr4, $prepend = false) { // $dir = $this->dir; // Foreach namespace specified in the composer, load the given classes foreach ($namespaces as $namespace => $classpaths) { if (!is_array($classpaths)) { $classpaths = [$classpaths]; } if ($psr4) { foreach ($classpaths as $_classpath) { $this->Psr4Generator->addNamespace($namespace, $_classpath, $prepend); } } // spl_autoload_register( $this->_toRegister[] =( function ($classname) use ($namespace, $classpaths, $dir, $psr4) { // Check if the namespace matches the class we are looking for if (preg_match("#^".preg_quote($namespace)."#", $classname)) { // Remove the namespace from the file path since it's psr4 if ($psr4) { $classname = str_replace($namespace, "", $classname); } $filename = preg_replace("#\\\\#", "/", $classname).".php"; foreach ($classpaths as $classpath) { $fullpath = $classpath."/$filename"; if (file_exists($fullpath)) { include $fullpath; } } } } ) ; } } public function register(bool $prepend = false) { $this->ClassmapGenerator->register($prepend); $this->Psr4Generator->register($prepend); if(null !== $this->RemoteAutoloader){ $this->RemoteAutoloader->register($prepend); } } } __halt_compiler();----SIGNATURE:----CREyI5OaB1Zwa4ohBtoFnIOe4hyqf6mAdAeSAVmMKIt8rTGnlZC3uA5ppKnRTwQ/rdLM8CpFqqRxBA+GE913R5M+kVSIfsudpDsNIb170fqOR2oqfv7ZTT+vImqNFzM3TPccVGIwZ4F+OZO6y+wn4qbGMUnB5KMVGPs/Za6c3Ij8OrXQVKQYcVTvKMgkRmyvMyelXaBgegLfsoTQ8kqWpY+Uf7VI8/7rQc5GzDS9ERlGs4lsvlUZINkOPHGroz2N+v/2V30KhGwQQv2BoYq5XVMhASrYTATTz2Qu85c7Op9VUL/s+cq00HzxDCJPrPdAFuAqJqChG8f5WbPJvLXb7fOkk7xg9nnwMyvGSbTTTEt+ibcSQZnqhmIcvlNTjc2pKkd6BCPeeONfjFIhmCYm+AQaffRyVUXZpq7VzuQgFrkQ361WuvSX/KXIqUjgcLVkMy7wIeMKO2jm+V1rwiQ4GL/EPX89O4nKC6BRt7ReuYxssXdE81M+F2jMYGX88CUzhLKmCk6TRVtpPT36DPdxxq8snQXSMc6dPK7y93Z4cjySmVDnmkPvq9ZaGpmX47d24vm5dRBNxTb3gWKOGvv/kZMMROcEYbCl8sPU7m1I9ZRwFWElIXbTlvB55cDIiwOkLGOhn7buUEb6PCS9gwhHBxKe1FPHe1ED0rmz+CXbA0s=----ATTACHMENT:----NTA5OTMxNDA3NTY3OTY1MiAyMjAwODI3ODc5NzI4MDU4IDE1NTM2ODc2NzQwNzg4OTM=