Oihana PHP System

initDefinitions.php

Table of Contents

Functions

initDefinitions()  : array<string|int, mixed>
Initialize all DI container definitions by loading and merging PHP definition files.

Functions

initDefinitions()

Initialize all DI container definitions by loading and merging PHP definition files.

initDefinitions(string $basePath) : array<string|int, mixed>

This function scans $basePath recursively for .php files, requires each file, and merges the resulting arrays into a single definitions array. It is intended to assemble service definitions for a DI container.

Behavior:

  • Only files with the "php" extension are considered.
  • Files are discovered recursively in subdirectories.
  • Each file must return an array; non-array returns may cause merge issues or exceptions in requireAndMergeArrays.
Parameters
$basePath : string

Absolute or relative path to the root directory containing definition files.

Tags
throws
Exception

If a required file cannot be read/included or merging fails.

see
recursiveFilePaths()
see
requireAndMergeArrays()
see
initContainer()
example
use DI\ContainerBuilder;
use function oihana\init\initDefinitions;

// Load all container definitions from the 'definitions' directory
$definitions = initDefinitions(__DIR__ . '/../../definitions');

// Example: pass the definitions to your container builder
$containerBuilder = new ContainerBuilder() ;

$containerBuilder->addDefinitions( $definitions ) ;

$containerBuilder->build() ;
Return values
array<string|int, mixed>

Merged definitions array.


        
On this page

Search results