Component loading

Loading process and principle

Here to introduce the collection and loading principle of components, you can do some understanding.

  • Swoft gets all psr4 load registration information via composer's ClassLoader object
  • Find the directory for each psr4 namespace and see if there is a need for AutoLoader.php swewt.
    • Allows you to skip scanning certain defined namespaces to speed up when starting the application. By default skip scanning 'Psr\', 'PHPUnit\', 'Symfony\' several public namespaces
  • Load the AutoLoader.php file for each component. The purpose of the scanning path specified by its configuration, to avoid scanning as many as 1.0 invalid directory
  • AutoLoader must implement LoaderInterface and optionally implement several other useful interfaces.
    • Implement LoaderInterface to define the directory to be scanned
    • Implementing DefinitionInterface can define an array to configure the beans within some components.
    • Achieve ComponentInterface addition to support the above configuration, you can also customize whether to enable the current component and adding some components description
  • Start parsing each component's AutoLoader , collecting annotation information, bean configuration, etc.
    • Components that are not enabled will skip parsing its AutoLoader::class scan configuration
    • Also allows startup application, setting disables the specified AutoLoader::class in order to achieve the purpose of this component is prohibited scan
/docs/2.x/en/component/how-to-load.html
progress-bar