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

aimeos / aimeos-base / e91f53ce-0333-43ec-90cd-b09033cbf4cc

12 Dec 2024 01:03PM UTC coverage: 88.609%. Remained the same
e91f53ce-0333-43ec-90cd-b09033cbf4cc

push

circleci

aimeos
Fixed test

1688 of 1905 relevant lines covered (88.61%)

5.97 hits per line

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

77.27
/src/MQueue/Manager/Standard.php
1
<?php
2

3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2024
6
 * @package Base
7
 * @subpackage MQueue
8
 */
9

10

11
namespace Aimeos\Base\MQueue\Manager;
12

13

14
/**
15
 * Standard message queue manager
16
 *
17
 * @package Base
18
 * @subpackage MQueue
19
 */
20
class Standard implements Iface
21
{
22
        private array $config;
23
        private array $objects = [];
24

25

26
        /**
27
         * Initializes the object
28
         *
29
         * @param array $config Associative multi-dimensional configuration
30
         */
31
        public function __construct( array $config )
32
        {
33
                $this->config = $config;
5✔
34
        }
35

36

37
        /**
38
         * Cleans up the object
39
         */
40
        public function __destruct()
41
        {
42
                foreach( $this->objects as $key => $object ) {
5✔
43
                        unset( $this->objects[$key] );
4✔
44
                }
45
        }
46

47

48
        /**
49
         * Clones the objects inside.
50
         */
51
        public function __clone()
52
        {
53
                $this->objects[] = [];
1✔
54
        }
55

56

57
        /**
58
         * Clean up the objects inside
59
         *
60
         * @return array List of properties to serialize
61
         */
62
        public function __sleep() : array
63
        {
64
                $this->__destruct();
×
65
                $this->objects = [];
×
66

67
                return array_keys( get_object_vars( $this ) );
×
68
        }
69

70

71
        /**
72
         * Returns the message queue for the given name
73
         *
74
         * @param string $name Resource name of the message queue
75
         * @return \Aimeos\Base\MQueue\Iface Message queue object
76
         * @throws \Aimeos\Base\MQueue\Exception If an no configuration for that name is found
77
         */
78
        public function get( string $name ) : \Aimeos\Base\MQueue\Iface
79
        {
80
                if( !isset( $this->objects[$name] ) ) {
4✔
81
                        $this->objects[$name] = $this->create( $this->config( $name ) );
4✔
82
                }
83

84
                return $this->objects[$name];
3✔
85
        }
86

87

88
        /**
89
         * Returns the configuration for the given name
90
         *
91
         * @param string $name Name of the resource, e.g. "mq" or "mq-email"
92
         * @return array Configuration values
93
         * @throws \Aimeos\Base\MQueue\Exception If an no configuration for that name is found
94
         */
95
        protected function config( string $name ) : array
96
        {
97
                foreach( [$name, 'mq'] as $mqname )
4✔
98
                {
99
                        if( isset( $this->config[$mqname] ) ) {
4✔
100
                                return $this->config[$mqname];
3✔
101
                        }
102
                }
103

104
                $msg = sprintf( 'No resource configuration for "%1$s" available', $name );
1✔
105
                throw new \Aimeos\Base\MQueue\Exception( $msg );
1✔
106
        }
107

108

109
        /**
110
         * Creates and returns a new message queue object
111
         *
112
         * @param array $config Resource configuration
113
         * @return \Aimeos\Base\MQueue\Iface Message queue object
114
         * @throws \Aimeos\Base\MQueue\Exception if message queue class isn't found
115
         */
116
        protected function create( array $config )
117
        {
118
                if( !isset( $config['adapter'] ) ) {
3✔
119
                        throw new \Aimeos\Base\MQueue\Exception( 'Message queue not configured' );
×
120
                }
121

122
                $classname = '\Aimeos\Base\MQueue\\' . ucfirst( (string) $config['adapter'] );
3✔
123

124
                if( !class_exists( $classname ) ) {
3✔
125
                        throw new \Aimeos\Base\MQueue\Exception( sprintf( 'Message queue "%1$s" not found', $config['adapter'] ) );
×
126
                }
127

128
                $config['db'] = $this->config[$config['db'] ?? 'db'] ?? [];
3✔
129

130
                return new $classname( $config );
3✔
131
        }
132
}
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