Skip to content

NextPDF CodeIgniter boot and discovery

CodeIgniter 4 discovers the package’s Services class, helper functions, and registrar through Composer package discovery. This page explains the sequence and the configuration that controls it.

CodeIgniter 4 resolves a service by scanning each discovered Config\Services class for a static method that matches the requested service name. When your application calls service('pdf'), the framework finds the first discovered Services class that declares a pdf method, and then calls it.

Discovery is governed by Config\Modules:

  • $enabled — primary switch for auto-discovery. Default true.
  • $discoverInComposer — extends discovery to Composer packages. Default true. This flag lets the framework find nextpdf/codeigniter.
  • $composerPackages — an optional only / exclude filter for the Composer package set.
  • $aliases — the element types that participate in discovery. The framework default includes services and registrars, and this package uses both.

The package class is NextPDF\CodeIgniter\Config\Services. Composer maps the PHP Standards Recommendation 4 (PSR-4) prefix NextPDF\CodeIgniter\ to src/CodeIgniter/. A fully qualified class name must have a top-level namespace (PSR-4 §x1.x2.p5, modal MUST). The namespace prefix maps to the base directory, so the class resolves to its file (PSR-4 §x1.x3).

  1. Composer autoload. Composer registers the PSR-4 map and the files autoload entries. It loads the helper file src/CodeIgniter/Helpers/pdf_helper.php at this point.
  2. Framework bootstrap. CodeIgniter reads Config\Modules. When discovery is enabled, it builds the discovered element list across Composer packages.
  3. Registrar discovery. The framework collects Registrar classes. The package’s Registrar::Autoload() advertises the pdf helper to CodeIgniter’s helper loader.
  4. Service resolution on first call. Service factories are lazy. The first call to service('pdf') or Services::pdf() runs the factory. Shared services are cached on the locator for the process.

CodeIgniter 4 does not provide a PSR-11 container. Instead, the static factory methods on the Services class act as the bindings. Each method accepts a bool $getShared parameter:

ServiceShared by defaultNotes
fontRegistryyesWarmed, then locked.
imageRegistryyesBounded least recently used (LRU) cache.
documentFactoryyesStateless.
pdfDocumentnoFresh per call.
pdfnoFresh per call.
tsaClientyesnull when no Time-Stamp Authority (TSA) URL is configured.
pdfSignernonull when signing is disabled.

Shared instances live in CodeIgniter’s BaseService instance cache for the process. The framework test harness clears that cache with BaseService::reset(), and the package functional tests rely on that reset between cases.

The effective configuration resolves in this order:

  1. Package defaults in NextPDF\CodeIgniter\Config\NextPdf.
  2. An application class Config\NextPdf that extends the package class, when present. CodeIgniter loads it instead of the package default.
  3. Environment overrides applied by BaseConfig, keyed by the lowercase short class name nextpdf (dotted nested keys, or the fully qualified class form).

The application config-extension file declares one class and has no side effects. That keeps it aligned with the PSR-1 expectation that a file either declares symbols or runs side-effecting logic, but not both (PSR-1 §x1.x1.p3). The helper file is the deliberate side-effecting counterpart. It declares the global pdf() and pdf_document() functions, and each one is guarded by a function_exists check so a double load is safe.

  • composer dump-autoload — rebuilds the PSR-4 map and the files autoload list after an upgrade.
  • To probe discovery quickly, use a controller that calls Services::pdfDocument(false) and asserts a Document return.
  • Inspect vendor/composer/autoload_files.php to confirm that the helper file is registered.
  • See /integrations/codeigniter/troubleshooting/ for the failure-to-cause mapping.
  • Fully qualified class name requires a top-level namespace (PSR-4 Autoloader §x1.x2.p5).
  • Namespace prefix to base directory class-path mapping (PSR-4 Autoloader §x1.x3).
  • A file declares symbols or causes side effects — the helper file design (PSR-1 Basic Coding Standard §x1.x1.p3).
  • /integrations/codeigniter/integration/ — the wiring reference and smoke test.
  • /integrations/codeigniter/install/ — install and verify discovery.
  • /integrations/codeigniter/overview/ — the full application programming interface (API) surface.
  • /integrations/codeigniter/troubleshooting/ — discovery failure modes.