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

ICanBoogie / bind-activerecord / 6129970765

09 Sep 2023 08:47AM UTC coverage: 32.759%. First build
6129970765

push

github

olvlvl
Match changes to ModelDefinition

3 of 3 new or added lines in 1 file covered. (100.0%)

38 of 116 relevant lines covered (32.76%)

0.41 hits per line

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

0.0
/lib/ContainerExtension.php
1
<?php
2

3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
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
namespace ICanBoogie\Binding\ActiveRecord;
13

14
use ICanBoogie\ActiveRecord\Config;
15
use ICanBoogie\ActiveRecord\Connection;
16
use ICanBoogie\ActiveRecord\ConnectionProvider;
17
use ICanBoogie\ActiveRecord\ModelProvider;
18
use ICanBoogie\Application;
19
use ICanBoogie\Binding\SymfonyDependencyInjection\ExtensionWithFactory;
20
use Symfony\Component\DependencyInjection\Alias;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\DependencyInjection\Definition;
23
use Symfony\Component\DependencyInjection\Extension\Extension;
24
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
25
use Symfony\Component\DependencyInjection\Reference;
26

27
final class ContainerExtension extends Extension implements ExtensionWithFactory
28
{
29
    public static function from(Application $app): ExtensionInterface
30
    {
31
        return new self(
×
32
            $app->configs->config_for_class(Config::class)
×
33
        );
×
34
    }
35

36
    private function __construct(
37
        private readonly Config $config
38
    ) {
39
    }
×
40

41
    /**
42
     * @param array<string, mixed> $configs
43
     */
44
    public function load(array $configs, ContainerBuilder $container): void
45
    {
46
        $this->register_connections($container);
×
47
        $this->register_models($container);
×
48
    }
49

50
    /**
51
     * Creates a `active_record.connection.$id` definition for each of the connection configured.
52
     */
53
    private function register_connections(ContainerBuilder $container): void
54
    {
55
        foreach ($this->config->connections as $id => $connection) {
×
56
            $definition = (new Definition(Connection::class))
×
57
                ->setFactory([ new Reference(ConnectionProvider::class), 'connection_for_id' ])
×
58
                ->setArguments([ $id ])
×
59
                ->setPublic(true);
×
60

61
            $container->setDefinition("active_record.connection.$id", $definition);
×
62
        }
63
    }
64

65
    /**
66
     * Creates a `active_record.model.$id` definition for each of the models configured.
67
     */
68
    private function register_models(ContainerBuilder $container): void
69
    {
70
        foreach ($this->config->models as $id => $model) {
×
71
            $class = $model->model_class;
×
72
            $definition = (new Definition($class))
×
73
                ->setFactory([ new Reference(ModelProvider::class), 'model_for_id' ])
×
74
                ->setArguments([ $id ])
×
75
                ->setPublic(true);
×
76

77
            $alias = "active_record.model.$id";
×
78

79
            $container->setDefinition($class, $definition);
×
80
            $container->setAlias($alias, new Alias($class, public: true));
×
81
        }
82
    }
83
}
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

© 2025 Coveralls, Inc