· 10 years ago · Sep 17, 2016, 04:04 PM
1<?php
2
3class DomainController {
4
5 const DOMAIN_DIR = '/var/www/prshops/data/www';
6
7 public static function compileDomainDir($domainName)
8 {
9 return self::DOMAIN_DIR . '/' . $domainName;
10 }
11
12 public static function deleteDirectoryTree($dir)
13 {
14
15 $files = array_diff(scandir($dir), array('.','..'));
16
17 foreach ($files as $file) {
18 (is_dir("$dir/$file")) ? self::deleteDirectoryTree("$dir/$file") : unlink("$dir/$file");
19 }
20
21 return rmdir($dir);
22 }
23
24 public static function actionCreate($domainName = null)
25 {
26 if (!$domainName) {
27 throw new Exception("$domainName in actionCreate is invalid", 1);
28 }
29
30 // TODO check if domain is not already in hh_domains table
31
32 // compile domainDir, full path
33 $domainDir = self::compileDomainDir($domainName);
34
35 // create domainDir with checking
36 if ( ! file_exists($domainDir)) {
37 mkdir($domainDir, 0755, true);
38 }
39
40 // TODO copy needed files
41
42 }
43
44 public static function actionDelete($domainName = null)
45 {
46 if (!$domainName) {
47 throw new Exception("$domainName in actionDelete is invalid", 1);
48 }
49
50 // compile domainDir, full path
51 $domainDir = self::compileDomainDir($domainName);
52
53 // check if domain directory exists
54 if ( ! file_exists($domainDir)) {
55 throw new Exception("$domainDir in actionDelete is not exists!", 1);
56 }
57
58 // delete domain directory with exception handling
59 try {
60 self::deleteDirectoryTree($domainDir);
61 } catch (Exception $e) {
62 throw $e;
63 }
64
65 // TODO remove domain from hh_domains
66
67 }
68
69}