-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_repo
More file actions
86 lines (57 loc) · 1.5 KB
/
Copy pathcreate_repo
File metadata and controls
86 lines (57 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
//parent directories
define('DS',DIRECTORY_SEPARATOR);
define('ROOT_PATH',dirname(__FILE__).DS);
define('APP',ROOT_PATH.'app'.DS);
define('PUBLIC_PATH',ROOT_PATH.'public'.DS);
require_once 'app/config/config_constants.php';
require_once 'vendor/autoload.php';
if(php_sapi_name() =='cli')
{
if(isset($argv[1]))
{
$repo = $argv[1];
clearstatcache();
if(!file_exists(REPOSITORY.$repo.'.php') && !file_exists(REPOSITORY.$repo.'Interface'.'.php'))
{
file_put_contents(REPOSITORY.$repo.'Interface.php',getInterfaceString($repo.'Interface'));
file_put_contents(REPOSITORY.$repo.'Repository.php',getRepoString($repo.'Repository',$repo.'Interface'));
die('Repository created '.$repo.' successfully');
}
else
{
die("Repository $repo already craeted before");
}
}
else
{
die('no data input found');
}
}
else
{
die('');
}
function getInterfaceString($interface)
{
$string ='<?php
namespace App\Repositories;
interface '.$interface.'{
// write interface functions here
}';
return $string;
}
function getRepoString($repo,$interface)
{
$string ='<?php
namespace App\Repositories;
//use App\Models\Model;
use App\Repositories\\'.$interface.';
class '.$repo.' implements '.$interface.'{
public $model;
public function __construct()
{
$this->model = new model;
}';
return $string;
}