• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Cecilapp / Cecil / 21146412611

19 Jan 2026 05:26PM UTC coverage: 82.274%. First build
21146412611

Pull #2285

github

web-flow
Merge fe78c7058 into 878eab640
Pull Request #2285: Integrate PHP-DI for dependency injection

58 of 83 new or added lines in 16 files covered. (69.88%)

3328 of 4045 relevant lines covered (82.27%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/src/Container/ContainerFactory.php
1
<?php
2

3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <arnaud@ligny.fr>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace Cecil\Container;
15

16
use Cecil\Config;
17
use DI\Container;
18
use DI\ContainerBuilder;
19
use Psr\Log\LoggerInterface;
20

21
/**
22
 * Factory to create and configure the dependency injection container.
23
 *
24
 * Uses PHP-DI for automatic autowiring and simple configuration.
25
 *
26
 * @see https://php-di.org/
27
 */
28
class ContainerFactory
29
{
30
    /**
31
     * Creates and configures the DI container with Cecil dependencies.
32
     *
33
     * @param Config          $config Application configuration
34
     * @param LoggerInterface $logger Application logger
35
     *
36
     * @return Container The configured and ready-to-use container
37
     */
38
    public static function create(
39
        Config $config,
40
        LoggerInterface $logger
41
    ): Container {
42
        $builder = new ContainerBuilder();
1✔
43

44
        // Enable PHP 8 attributes for dependency injection
45
        $builder->useAttributes(true);
1✔
46

47
        // Load dependencies configuration
48
        $definitionsFile = __DIR__ . '/../../config/dependencies.php';
1✔
49
        if (file_exists($definitionsFile)) {
1✔
50
            $builder->addDefinitions($definitionsFile);
1✔
51
        }
52

53
        // Enable compilation cache in production
54
        if (!$config->get('debug')) {
1✔
NEW
55
            $cacheDir = $config->getCachePath() . '/di';
×
NEW
56
            if (!is_dir($cacheDir)) {
×
NEW
57
                mkdir($cacheDir, 0755, true);
×
58
            }
NEW
59
            $builder->enableCompilation($cacheDir);
×
60
        }
61

62
        // Build the container
63
        $container = $builder->build();
1✔
64

65
        // Inject Config and Logger instances from Builder
66
        // These objects are already instantiated and configured
67
        $container->set(Config::class, $config);
1✔
68
        $container->set(LoggerInterface::class, $logger);
1✔
69

70
        // Note: Builder cannot be injected here because it creates the container itself
71
        // Services that need Builder receive it as a constructor parameter
72

73
        return $container;
1✔
74
    }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc