@@ -35,21 +35,7 @@ class Admin
35
35
*/
36
36
public static function init ($ path , $ bare = true , array $ options = array ())
37
37
{
38
- $ command = isset ($ options ['command ' ]) ? $ options ['command ' ] : 'git ' ;
39
-
40
- // command-line
41
- $ builder = ProcessBuilder::create (array ($ command , 'init ' , '-q ' ));
42
- if ($ bare ) {
43
- $ builder ->add ('--bare ' );
44
- }
45
- $ builder ->add ($ path );
46
-
47
- // environment
48
- $ builder ->inheritEnvironmentVariables (false );
49
- $ process = $ builder ->getProcess ();
50
- if (isset ($ options ['environment_variables ' ])) {
51
- $ process ->setEnv ($ options ['environment_variables ' ]);
52
- }
38
+ $ process = static ::getProcess ('init ' , array_merge (array ('-q ' ), $ bare ? array ('--bare ' ) : array (), array ($ path )), $ options );
53
39
54
40
$ process ->run ();
55
41
@@ -74,11 +60,8 @@ public static function init($path, $bare = true, array $options = array())
74
60
*/
75
61
public static function isValidRepository ($ url , array $ options = array ())
76
62
{
77
- $ command = isset ($ options ['command ' ]) ? $ options ['command ' ] : 'git ' ;
78
- $ builder = ProcessBuilder::create (array ($ command , 'ls-remote ' ));
79
- $ builder ->add ($ url );
63
+ $ process = static ::getProcess ('ls-remote ' , array ($ url ), $ options );
80
64
81
- $ process = $ builder ->getProcess ();
82
65
$ process ->run ();
83
66
84
67
return $ process ->isSuccessFul ();
@@ -127,19 +110,7 @@ public static function mirrorTo($path, $url, array $options = array())
127
110
*/
128
111
private static function cloneRepository ($ path , $ url , array $ args = array (), array $ options = array ())
129
112
{
130
- $ command = isset ($ options ['command ' ]) ? $ options ['command ' ] : 'git ' ;
131
- $ builder = ProcessBuilder::create (array ($ command , 'clone ' , '-q ' ));
132
- foreach ($ args as $ value ) {
133
- $ builder ->add ($ value );
134
- }
135
- $ builder ->add ($ url );
136
- $ builder ->add ($ path );
137
-
138
- $ builder ->inheritEnvironmentVariables (false );
139
- $ process = $ builder ->getProcess ();
140
- if (isset ($ options ['environment_variables ' ])) {
141
- $ process ->setEnv ($ options ['environment_variables ' ]);
142
- }
113
+ $ process = static ::getProcess ('clone ' , array_merge (array ('-q ' ), $ args , array ($ url , $ path )), $ options );
143
114
144
115
$ process ->run ();
145
116
@@ -149,4 +120,27 @@ private static function cloneRepository($path, $url, array $args = array(), arra
149
120
150
121
return new Repository ($ path , $ options );
151
122
}
123
+
124
+ /**
125
+ * This internal method is used to create a process object.
126
+ */
127
+ private static function getProcess ($ command , array $ args = array (), array $ options = array ())
128
+ {
129
+ $ options = array_merge (array (
130
+ 'environment_variables ' => array (),
131
+ 'command ' => 'git ' ,
132
+ 'process_timeout ' => 3600
133
+ ), $ options );
134
+
135
+ $ builder = ProcessBuilder::create (array_merge (array ($ options ['command ' ], $ command ), $ args ));
136
+ $ builder ->inheritEnvironmentVariables (false );
137
+
138
+ $ process = $ builder ->getProcess ();
139
+ $ process ->setEnv ($ options ['environment_variables ' ]);
140
+ $ process ->setTimeout ($ options ['process_timeout ' ]);
141
+ $ process ->setIdleTimeout ($ options ['process_timeout ' ]);
142
+
143
+ return $ process ;
144
+ }
145
+
152
146
}
0 commit comments