Completed
Branch 0.2.1 (e70612)
by Anton
09:15
created

Create   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4
Metric Value
wmc 7
lcom 0
cbo 4
dl 0
loc 48
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B __invoke() 0 34 6
1
<?php
2
3
namespace Modules\Filemanager\Controller {
4
5
	use Modules\Filemanager, Modules\Informer;
6
7
	class Create {
8
9
		protected $parent = null;
10
11
		# Constructor
12
13
		public function __construct(Filemanager\Utils\Container $parent) {
14
15
			$this->parent = $parent;
16
		}
17
18
		# Invoker
19
20
		public function __invoke(array $post) {
21
22
			# Declare variables
23
24
			$type = ''; $name = '';
25
26
			# Extract post array
27
28
			extract($post);
29
30
			# Check for demo mode
31
32
			if (Informer::isDemoMode()) return 'DEMO_MODE_RESTRICTION';
33
34
			# Validate name
35
36
			if (false === ($name = Filemanager\Validate::name($name))) return 'FILEMANAGER_ERROR_NAME_INVALID';
37
38
			# Check if item exists
39
40
			if (@file_exists($this->parent->pathFull() . $name)) return 'FILEMANAGER_ERROR_EXISTS';
41
42
			# Create item
43
44
			$entity = Filemanager::get($type, $this->parent);
45
46
			if (!$entity->create($name)) return (($entity->type() === FILEMANAGER_TYPE_DIR) ?
47
48
				'FILEMANAGER_ERROR_DIR_CREATE' : 'FILEMANAGER_ERROR_FILE_CREATE');
49
50
			# ------------------------
51
52
			return true;
53
		}
54
	}
55
}
56