Laravel   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
eloc 18
c 2
b 0
f 0
dl 0
loc 69
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __destruct() 0 4 2
A __construct() 0 6 1
A __sleep() 0 6 1
A get() 0 14 3
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2025
6
 * @package Base
7
 * @subpackage Filesystem
8
 */
9
10
11
namespace Aimeos\Base\Filesystem\Manager;
12
13
14
/**
15
 * Laravel file system manager
16
 *
17
 * @package Base
18
 * @subpackage Filesystem
19
 */
20
class Laravel extends Standard implements Iface
21
{
22
	private \Illuminate\Filesystem\FilesystemManager $fsm;
23
	private array $objects = [];
24
	private string $tempdir;
25
26
27
	/**
28
	 * Initializes the object
29
	 *
30
	 * @param \Illuminate\Filesystem\FilesystemManager $fsm Laravel file system manager object
31
	 * @param array $config Filesystem resource configuration
32
	 * @param string $tempdir Directory for storing temporary files
33
	 */
34
	public function __construct( \Illuminate\Filesystem\FilesystemManager $fsm, array $config, string $tempdir )
35
	{
36
		parent::__construct( $config );
37
38
		$this->fsm = $fsm;
39
		$this->tempdir = $tempdir;
40
	}
41
42
43
	/**
44
	 * Cleans up the object
45
	 */
46
	public function __destruct()
47
	{
48
		foreach( $this->objects as $key => $object ) {
49
			unset( $this->objects[$key] );
50
		}
51
	}
52
53
54
	/**
55
	 * Clean up the objects inside
56
	 *
57
	 * @return array List of property names
58
	 */
59
	public function __sleep() : array
60
	{
61
		$this->__destruct();
62
		$this->objects = [];
63
64
		return array_keys( get_object_vars( $this ) );
65
	}
66
67
68
	/**
69
	 * Returns the file system for the given name
70
	 *
71
	 * @param string $name Key for the file system
72
	 * @return \Aimeos\Base\Filesystem\Iface File system object
73
	 * @throws \Aimeos\Base\Filesystem\Exception If an no configuration for that name is found
74
	 */
75
	public function get( string $name ) : \Aimeos\Base\Filesystem\Iface
76
	{
77
		$key = $this->config( $name );
78
79
		if( is_string( $key ) )
80
		{
81
			if( !isset( $this->objects[$key] ) ) {
82
				$this->objects[$key] = new \Aimeos\Base\Filesystem\Laravel( $this->fsm->disk( $key ), $this->tempdir );
83
			}
84
85
			return $this->objects[$key];
86
		}
87
88
		return parent::get( $name );
89
	}
90
}
91