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

aimeos / aimeos-base / d75eff4d-70b2-4a0c-9fb5-c3e263dbf45f

12 Dec 2024 01:03PM UTC coverage: 88.603%. Remained the same
d75eff4d-70b2-4a0c-9fb5-c3e263dbf45f

push

circleci

aimeos
Fixed test

1687 of 1904 relevant lines covered (88.6%)

5.98 hits per line

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

90.0
/src/Filesystem/Manager/Standard.php
1
<?php
2

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

10

11
namespace Aimeos\Base\Filesystem\Manager;
12

13

14
/**
15
 * Standard file system manager
16
 *
17
 * @package Base
18
 * @subpackage Filesystem
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;
4✔
34
        }
35

36

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

47

48
        /**
49
         * Clean up the objects inside
50
         *
51
         * @return array List of properties to serialize
52
         */
53
        public function __sleep() : array
54
        {
55
                $this->__destruct();
1✔
56
                $this->objects = [];
1✔
57

58
                return array_keys( get_object_vars( $this ) );
1✔
59
        }
60

61

62
        /**
63
         * Returns the file system for the given name
64
         *
65
         * @param string $name Key for the file system
66
         * @return \Aimeos\Base\Filesystem\Iface File system object
67
         * @throws \Aimeos\Base\Filesystem\Exception If an no configuration for that name is found
68
         */
69
        public function get( string $name ) : \Aimeos\Base\Filesystem\Iface
70
        {
71
                if( !isset( $this->objects[$name] ) ) {
3✔
72
                        $this->objects[$name] = $this->create( $this->config( $name ) );
3✔
73
                }
74

75
                return $this->objects[$name];
2✔
76
        }
77

78

79
        /**
80
         * Returns the configuration for the given name
81
         *
82
         * @param string $name Name of the resource, e.g. "fs" or "fs-media"
83
         * @return array|string Configuration values or alias name
84
         * @throws \Aimeos\Base\Filesystem\Exception If an no configuration for that name is found
85
         */
86
        protected function config( string $name )
87
        {
88
                foreach( [$name, 'fs'] as $fsname )
3✔
89
                {
90
                        if( isset( $this->config[$fsname] ) ) {
3✔
91
                                return $this->config[$fsname];
2✔
92
                        }
93
                }
94

95
                $msg = sprintf( 'No resource configuration for "%1$s" available', $name );
1✔
96
                throw new \Aimeos\Base\Filesystem\Exception( $msg );
1✔
97
        }
98

99

100
        /**
101
         * Creates and returns a new file system object
102
         *
103
         * @param array $config Resource configuration
104
         * @return \Aimeos\Base\Filesystem\Iface File system object
105
         * @throws \Aimeos\Base\Filesystem\Exception if file system class isn't found
106
         */
107
        protected function create( array $config ) : \Aimeos\Base\Filesystem\Iface
108
        {
109
                if( !isset( $config['adapter'] ) ) {
2✔
110
                        throw new \Aimeos\Base\Filesystem\Exception( 'File system not configured' );
×
111
                }
112

113
                $classname = '\Aimeos\Base\Filesystem\\' . ucfirst( (string) $config['adapter'] );
2✔
114

115
                if( !class_exists( $classname ) ) {
2✔
116
                        throw new \Aimeos\Base\Filesystem\Exception( sprintf( 'File system "%1$s" not found', $config['adapter'] ) );
×
117
                }
118

119
                return new $classname( $config );
2✔
120
        }
121
}
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