Skip to content
Snippets Groups Projects

Issue #3248976: Add API documentation for Package Manager

+ 108
0
<?php
/**
* @file
* Documentation related to Package Manager.
*/
/**
* Package Manager is an API-only module which provides the scaffolding and
* functionality needed for Drupal to make changes to its own running code base.
* It doesn't provide any user interface.
*
* At the center of Package Manager is the concept of a staging area. A staging
* area is a (nearly) complete copy of the active Drupal code base, which is
* created in a separate location that isn't accessible over the web, such as a
* temporary directory. Package Manager can run Composer commands in the staging
* area to require or update packages in it, and then copy those changes back
* into the live, running code base (which is referred to as the "active
* directory"). When that's done, the staging area can be safely deleted. These
* four distinct operations comprise the "stage life cycle".
*
* Only one staging area can exist at any given time, and it is "owned" by the
* user or session that originally created it. Only the owner can perform
* operations on the staging area.
*
* Package Manager's PHP API is based on \Drupal\package_manager\Stage, which
* controls the stage life cycle. This class may be extended to implement custom
* behavior, but in most situations, custom code should use the event system
* to interact with the stage.
*
* Events are dispatched before and after each operation in the stage life
* cycle. There are two types of events: pre-operation and post-operation.
* Pre-operation events can analyze the state of the staging area, or the system
* as a whole, and flag errors if they detect any problems. If errors are
* flagged, the operation is prevented. Therefore, pre-operation events are
* helpful to ensure that the staging area is in a valid state. Post-operation
* events are simple triggers allowing custom code to react when an operation
* is complete. They cannot flag errors.
*
* All stage events extend \Drupal\package_manager\Event\StageEvent, and all
* pre-operation events extend
* \Drupal\package_manager\Event\PreOperationStageEvent. All events have a
* getStage() method which allows access to the stage object itself.
*
* The stage dispatches the following events during its life cycle:
*
* - \Drupal\package_manager\Event\PreCreateEvent
* Dispatched before the staging area is created. At this point, the stage
* will have recorded which user or session owns it, so another staging area
* cannot be created until the current one is destroyed. If subscribers flag
* errors during this event, the stage will release its ownership. This is
* the earliest possible time to detect problems that might prevent the
* stage from completing its life cycle successfully. Only dispatched once
* during a stage's life cycle.
*
* - \Drupal\package_manager\Event\PostCreateEvent
* Dispatched after the staging area is created, which means that nearly all
* of the running Drupal code base (normally excluding things like public and
* private files, SQLite databases, and other site-specific assets) has been
* copied into a separate, temporary location. Only dispatched once during a
* stage's life cycle.
*
* - \Drupal\package_manager\Event\PreRequireEvent
* Dispatched before one or more Composer packages are required into the
* staging area. May be dispatched multiple times during a stage's life cycle.
*
* - \Drupal\package_manager\Event\PostRequireEvent
* Dispatched after one or more Composer packages have been added to the
* staging area. May be dispatched multiple times during a stage's life cycle.
*
* - \Drupal\package_manager\Event\PreApplyEvent
* Dispatched before changes in the staging area (for example, new or updated
* packages) are copied to the active directory (i.e., the running Drupal code
* base). This is the final opportunity for event subscribers to flag errors
* before the active directory is modified. May be dispatched multiple times
* during a stage's life cycle.
*
* - \Drupal\package_manager\Event\PostApplyEvent
* Dispatched after changes in the staging area have been copied to the active
* directory. May be dispatched multiple times during a stage's life cycle.
*
* - \Drupal\package_manager\Event\PreDestroyEvent
* Dispatched before the staging area is destroyed, during which the temporary
* directory will be completely deleted the stage will release its ownership.
* Only dispatched once during a stage's life cycle.
*
* - \Drupal\package_manager\Event\PostDestroy
* Dispatched after the staging area is destroyed and the stage has released
* its ownership. Only dispatched once during a stage's life cycle.
*
* The public API of any stage consists of at least four methods:
*
* - \Drupal\package_manager\Stage::create()
* Creates the staging area, records ownership, and dispatches pre- and
* post-create events.
*
* - \Drupal\package_manager\Stage::require()
* Adds packages to the staging area and dispatches pre- and post-require
* events.
*
* - \Drupal\package_manager\Stage::apply()
* Copies changes from the staging area into the active directory, and
* dispatches pre- and post-apply events.
*
* - \Drupal\package_manager\Stage::destroy()
* Destroys the staging area, releases ownership, and dispatches pre- and
* post-destroy events.
*/
Loading