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

ICanBoogie / bind-activerecord / 6139815966

10 Sep 2023 10:27PM UTC coverage: 34.211% (+2.3%) from 31.933%
6139815966

push

github

olvlvl
ActiveRecord update

17 of 17 new or added lines in 5 files covered. (100.0%)

39 of 114 relevant lines covered (34.21%)

0.37 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\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Definition;
22
use Symfony\Component\DependencyInjection\Extension\Extension;
23
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
24
use Symfony\Component\DependencyInjection\Reference;
25

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

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

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

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

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

64
    /**
65
     * Creates a `active_record.model.$id` definition for each of the models configured.
66
     */
67
    private function register_models(ContainerBuilder $container): void
68
    {
69
        foreach ($this->config->models as $definition) {
×
70
            $activerecord_class = $definition->activerecord_class;
×
71

72
            $d = (new Definition($definition->model_class))
×
73
                ->setFactory([ new Reference(ModelProvider::class), 'model_for_record' ])
×
74
                ->setArguments([ $activerecord_class ])
×
75
                ->setPublic(true);
×
76

77
            $container->setDefinition(Record::format_service_id($activerecord_class), $d);
×
78
        }
79
    }
80
}
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