The PackageRegistry class provides access to all available packages in LibreDTE Core. It implements the PackageRegistryInterface and uses the PackageRegistryTrait for common registry functionality.
Overview
LibreDTE’s mission is to provide free, accessible, and well-documented electronic invoicing for Chile. As such, this library focuses exclusively on providing functionality related to Chilean electronic invoicing.
Class Definition
namespace libredte\lib\Core;
class PackageRegistry implements PackageRegistryInterface
Available Packages
LibreDTE Lib Core contains the following packages:
- billing - Electronic billing and invoicing package for Chile
Public Methods
getBillingPackage()
Get the billing package for electronic invoicing functionality.
public function getBillingPackage(): BillingPackageInterface
The billing package instance providing access to all electronic invoicing features for Chile.
Example
use libredte\lib\Core\Application;
// Get the application instance
$app = Application::getInstance();
// Access the package registry
$registry = $app->getPackageRegistry();
// Get the billing package
$billing = $registry->getBillingPackage();
// Now you can use billing package features
// Example: $billing->createInvoice(...)
getPackage()
Get a package by its name. This method is inherited from PackageRegistryTrait.
public function getPackage(string $name): PackageInterface
The package name. Currently supported: 'billing'
The requested package instance.
Example
$registry = $app->getPackageRegistry();
// Generic way to access packages
$billing = $registry->getPackage('billing');
// Type-safe way (recommended)
$billing = $registry->getBillingPackage();
Usage Pattern
The typical pattern for accessing packages is:
- Get the Application instance
- Get the PackageRegistry from the Application
- Get the specific package you need
- Use the package’s functionality
use libredte\lib\Core\Application;
// 1. Get application
$app = Application::getInstance();
// 2. Get registry
$registry = $app->getPackageRegistry();
// 3. Get billing package
$billing = $registry->getBillingPackage();
// 4. Use the package
// Work with electronic invoicing features...
Dependency Injection
When using a dependency injection container, you can inject the PackageRegistryInterface directly:
use Derafu\Backbone\Contract\PackageRegistryInterface;
class MyInvoiceService
{
public function __construct(
private PackageRegistryInterface $packageRegistry
) {}
public function createInvoice(): void
{
$billing = $this->packageRegistry->getBillingPackage();
// Use billing package...
}
}