Load `autoload_psr4.php` classes, used by PSR-4 packages

@return int|bool Return total packages loaded, if `autoload_psr4.php`
is not accessible return `false`
8685
public function psr4()
    {
        $i = $this->load($this->composerPath . $this->psrFourName);

        if ($i !== false) {
            $this->log[] = 'Imported ' . $i . ' classes from psr4';
            return $i;
        }

        $this->log[] = 'Warn: psr4 not found';
        return false;
    }
492893
public function autoload($class)
    {
        if (isset($this->classes[$class])) {
            require $this->classes[$class];

            return true;
        }
        // fallback for classes defined with leading backslash
        if (strpos($class, '\\') === 0) {
            $class = substr($class, 1);

            return $this->autoload($class);
        }

        return false;
    }
116618
public function autoload($class)
    {
        if ($this->_collectClasses) {
            $this->_arrLoadedClasses[self::$_scope][] = $class;
        }

	    $classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class)));

	    if ($this->_isIncludePathDefined) {
            $classFile =  COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . $class;
        }

        $classFile.= '.php';

        if (stream_resolve_include_path($classFile)) {
            return include $classFile;
        }

        $classFile = ltrim($this->classToFile($class) . '.php', '\\/');
	    if (stream_resolve_include_path($classFile)) {
		    return include $classFile;
	    }

        return false;
    }
180255
private function plugins_loaded() {
		if ( $this->_plugins_loaded ) {
			return;
		}
		$this->_plugins_loaded = true;

		spl_autoload_register( function ( $class ) {
			return $this->get_main()->load_class( $class );
		} );

		$this->load_functions();
	}
714677
public function onBeforeAutoloadDump() {

    // FIXME Composer call this AFTER the plugin remove, so we need this check to prevent a fatal error
    clearstatcache();
    if( file_exists( __DIR__ . '/Plugin.php' ) ) {

      //
      $filesystem = new Filesystem();
      $tmp        = $this->composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
      array_unshift( $tmp, $this->composer->getPackage() );

      $list = [];
      foreach( $tmp as $package ) {
        if( $package->getType() == static::PACKAGE_TYPE ) {

          // choose root directory based on the path (absolute path has no root) or package (main or vendor)
          if( $package === $this->composer->getPackage() ) $directory = $this->root;
          else $directory = $this->getDirectory( $package );

          // process autoloader
          $autoload = $package->getAutoload();
          if( isset( $autoload[ 'psr-4' ] ) ) {
            foreach( $autoload[ 'psr-4' ] as $namespace => $path ) {

              // don't handle multi directory namespace
              if( is_array( $path ) ) $this->io->writeError( 'Spoom\Composer: Ignoring multiple psr-4 namespaces of ' . $package->getPrettyName() );
              else {

                // normalize and ensure the trailing slash in the path
                $list[ $namespace ] = $filesystem->normalizePath( ( $filesystem->isAbsolutePath( $path ) ? '' : $directory ) . $path ) . '/';
              }
            }
          }
        }
      }

      $this->io->write( 'Spoom\Composer: Generating autoload file for ' . count( $list ) . ' extension(s)' );

      // create autoload file from the package list
      $this->writeAutoload( $list );
    }
  }
543679
public function getPackages()
    {
        if ($this->packages === null) {
            $this->packages = $this->composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
            $this->packages[] = $this->composer->getPackage();
        }

        return $this->packages;
    }
785841
public function createLoader(array $autoloads)
    {
        $loader = new ClassLoader();

        if (isset($autoloads['psr-0'])) {
            foreach ($autoloads['psr-0'] as $namespace => $path) {
                $loader->add($namespace, $path);
            }
        }

        if (isset($autoloads['psr-4'])) {
            foreach ($autoloads['psr-4'] as $namespace => $path) {
                $loader->addPsr4($namespace, $path);
            }
        }

        return $loader;
    }
1365272
public static function autoload()
    {
        // Vendor path
        $dir_base = realpath(__DIR__ . '/../../../../');

        $finder = new Finder();
        $finder->files()
            ->ignoreVCS(true)
            ->ignoreDotFiles(false)
            ->name('service.yml')
            ->exclude('Tests')
            ->exclude('tests')
            ->in($dir_base);

        foreach ($finder as $file) {
            self::autoloadFile($file);
        }
    }
1011144
public function load()
    {
        $this->extensions = [];
        foreach ($this->getPackages() as $package) {
            [$v, $p] = explode('/', $package['name']);
            $extension = Extension::findBy([
                'vendor' => $v,
                'package' => $p
            ]);
            if (!$extension) {
                $extension = (new Extension())
                    ->vendor($v)
                    ->package($p);
            }
            $extension
                ->version($package['version'] ?? '')
                ->description($package['description'] ?? '')
                ->save();
            $this->extensions[] = $extension;
        }
        return $this;
    }
610625
public function load($class)
    {
        if ($this->psr0 and $this->loadPsr0($class)) {
            return true;
        }
        $namespace = '\\';
        $classPath = str_replace('\\', '/', $class) . '.php';
        while (true) {
            if ($this->loadFrom($classPath, $namespace)) {
                return true;
            }
            $pos = strpos($classPath, '/');
            if ($pos === false) {
                if (! $this->psr0) {
                    break;
                }
                $pos = strpos($classPath, '_');
                if ($pos === false) {
                    break;
                }
            }
            $namespace = rtrim($namespace, '\\') . '\\' . substr($classPath, 0, $pos);
            $classPath = substr($classPath, $pos + 1);
        }
        return false;
    }
1041660
public function allPsr0SourcePaths()
    {
        $autoloadPsr0Paths = array();
        foreach ($this->autoloadPsr0() as $namespace => $paths) {
            $autoloadPsr0Paths = array_merge($autoloadPsr0Paths, $paths);
        }

        return $autoloadPsr0Paths;
    }
53738
public function run()
    {
        $this->loader->register();
        $result   = true;
        $classMap = array_slice($this->classMap, 0);

        // Now try to autoload all classes.
        while ($classMap) {
            $file  = reset($classMap);
            $class = key($classMap);
            try {
                $result = $this->tryLoadClass($class, $file) && $result;
            } catch (ParentClassNotFoundException $exception) {
                $this->handleParentClassNotFound($exception, $classMap);

                continue;
            }

            unset($classMap[$class]);
            $this->logger->info(
                'Loaded {class}.',
                array('class' => $class, 'file' => $file)
            );
        }

        $this->loader->unregister();

        return $result;
    }
369178
protected function _packages()
    {
        $installed = static::cache('_composerPackages');
        if (is_array($installed)) {
            return $installed;
        }

        $jsonPath = VENDOR_INCLUDE_PATH . 'composer/installed.json';
        $installed = [];

        if (is_readable($jsonPath)) {
            $json = (array)json_decode(file_get_contents($jsonPath), true);
            foreach ($json as $pkg) {
                $installed[$pkg['name']] = [
                    'name' => $pkg['name'],
                    'version' => $pkg['version'],
                    'version_normalized' => $pkg['version_normalized'],
                ];
            }
        }

        return static::cache('_composerPackages', $installed);
    }
1300062
public function getAutoloaderConfig()
    {
        $autoloaderArray = array();

        // If this module has a defined classmap, add a classmap autoloader.
        $classmapPath = $this->getDir() . '/' . $this->relativeModuleDir . 'autoload_classmap.php';
        if (file_exists($classmapPath)) {
            $autoloaderArray['Zend\Loader\ClassMapAutoloader'] = array(
                $classmapPath
            );
        }

        // Fallback to a PSR-0 autoloader.
        $autoloaderArray['Zend\Loader\StandardAutoloader'] = array(
            'namespaces' => array(
                $this->getNamespace() =>
                    $this->getDir() . '/' . $this->relativeModuleDir . 'src/' . $this->getNamespace(),
            ),
        );

        return $autoloaderArray;
    }
1003599
protected function getInstalledPackages()
    {
        if ($this->installedPackages === null) {
            $installedPackages = [];
            $packageService = $this->application->make(PackageService::class);
            foreach ($packageService->getInstalledHandles() as $packageHandle) {
                $installedPackages[$packageHandle] = $packageService->getClass($packageHandle);
            }
            $this->installedPackages = $installedPackages;
        }

        return $this->installedPackages;
    }
38220
public function requiredBy()
    {
        if ($cache = $this->config('required_by')) {
            return collection($cache);
        }

        Plugin::dropCache();
        $out = [];
        $plugins = Plugin::get()->filter(function ($v, $k) {
            return $v->name() !== $this->name();
        });

        foreach ($plugins as $plugin) {
            if ($dependencies = $plugin->dependencies($plugin->name)) {
                $packages = array_map(function ($item) {
                    list(, $package) = packageSplit($item, true);

                    return strtolower($package);
                }, array_keys($dependencies));

                if (in_array(strtolower($this->name()), $packages)) {
                    $out[] = $plugin;
                }
            }
        }

        $this->config('required_by', $out);

        return collection($out);
    }
809559
public function allPsr4SourcePaths()
    {
        $autoloadPsr4Paths = array();
        foreach ($this->autoloadPsr4() as $namespace => $paths) {
            $autoloadPsr4Paths = array_merge($autoloadPsr4Paths, $paths);
        }

        return $autoloadPsr4Paths;
    }