13
13
class UtilityHandler
14
14
{
15
15
/**
16
- \brief Extracts the files included in a compile request.
17
-
18
- \param string $directory The directory to extract the files to.
19
- \param array $request_files The files structure, as taken from the JSON request.
20
- \return A list of files or a reply message in case of error.
21
-
22
- Takes the files structure from a compile request and creates each file in a
23
- specified directory. If requested, it may create additional directories and
24
- have the files placed inside them accordingly.
25
-
26
- Also creates a new structure where each key is the file extension and the
27
- associated value is an array containing the absolute paths of the file, minus
28
- the extension.
29
-
30
- In case of error, the return value is an array that has a key <b>success</b>
31
- and contains the response to be sent back to the user.
16
+ * \brief Extracts the files included in a compile request.
17
+ *
18
+ * \param string $directory The directory to extract the files to.
19
+ * \param array $request_files The files structure, as taken from the JSON request.
20
+ * \return A list of files or a reply message in case of error.
21
+ *
22
+ * Takes the files structure from a compile request and creates each file in a
23
+ * specified directory. If requested, it may create additional directories and
24
+ * have the files placed inside them accordingly.
25
+ *
26
+ * Also creates a new structure where each key is the file extension and the
27
+ * associated value is an array containing the absolute paths of the file, minus
28
+ * the extension.
29
+ *
30
+ * In case of error, the return value is an array that has a key <b>success</b>
31
+ * and contains the response to be sent back to the user.
32
32
*/
33
33
function extract_files ($ directory , $ request_files , $ lib_extraction )
34
34
{
@@ -48,14 +48,14 @@ function extract_files($directory, $request_files, $lib_extraction)
48
48
// Examples: foo.c bar.cpp
49
49
$ REGEX = "/(.*)\.( $ EXTENSIONS )$/ " ;
50
50
51
- if (!file_exists ($ directory ))
52
- mkdir ($ directory , 0777 , true );
51
+ if (!file_exists ($ directory ))
52
+ mkdir ($ directory , 0777 , true );
53
53
54
54
foreach ($ request_files as $ file )
55
55
{
56
56
$ filename = $ file ["filename " ];
57
57
$ content = $ file ["content " ];
58
- $ ignore = false ;
58
+ $ ignore = false ;
59
59
60
60
$ failure_response = array (
61
61
"success " => false ,
@@ -72,22 +72,22 @@ function extract_files($directory, $request_files, $lib_extraction)
72
72
{
73
73
$ new_directory = pathinfo ($ filename , PATHINFO_DIRNAME );
74
74
75
- if (($ lib_extraction === true ) && ($ new_directory !== "utility " ))
76
- $ ignore = true ;
77
- if (!file_exists ("$ directory/ $ new_directory " ))
78
- mkdir ("$ directory/ $ new_directory " , 0777 , true );
79
- // There is no reason to check whether mkdir()
80
- // succeeded, given that the call to
81
- // file_put_contents() that follows would fail
82
- // as well.
75
+ if (($ lib_extraction === true ) && ($ new_directory !== "utility " ))
76
+ $ ignore = true ;
77
+ if (!file_exists ("$ directory/ $ new_directory " ))
78
+ mkdir ("$ directory/ $ new_directory " , 0777 , true );
79
+ // There is no reason to check whether mkdir()
80
+ // succeeded, given that the call to
81
+ // file_put_contents() that follows would fail
82
+ // as well.
83
83
84
84
}
85
85
86
86
if (file_put_contents ("$ directory/ $ filename " , $ content ) === false )
87
87
return $ failure_response ;
88
88
89
- if ($ ignore )
90
- continue ;
89
+ if ($ ignore )
90
+ continue ;
91
91
92
92
if (preg_match ($ REGEX , $ filename , $ matches ))
93
93
$ files [$ matches [2 ]][] = "$ directory/ $ matches [1 ]" ;
@@ -100,11 +100,11 @@ function extract_files($directory, $request_files, $lib_extraction)
100
100
}
101
101
102
102
/**
103
- \brief Searches for files with specific extensions in a directory.
104
-
105
- \param string $directory The directory to search for files.
106
- \param mixed $extensions An array of strings, the extensions to look for.
107
- \return A list of files that have the appropriate extension.
103
+ * \brief Searches for files with specific extensions in a directory.
104
+ *
105
+ * \param string $directory The directory to search for files.
106
+ * \param mixed $extensions An array of strings, the extensions to look for.
107
+ * \return A list of files that have the appropriate extension.
108
108
*/
109
109
function get_files_by_extension ($ directory , $ extensions )
110
110
{
@@ -120,20 +120,20 @@ function get_files_by_extension($directory, $extensions)
120
120
}
121
121
122
122
/**
123
- \brief Executes a command and displays the command itself and its output.
124
-
125
- \param string $command The command to be executed.
126
-
127
- Simplifies the creation and debugging of pages that rely on multiple external
128
- programs by "emulating" the execution of the requested command in a terminal
129
- emulator. Can be useful during early stages of development. Replace with
130
- <b>exec()</b> afterwards.
131
-
132
- To perform the command execution, <b>passthru()</b> is used. The string
133
- <b>2\>&1</b> is appended to the command to ensure messages sent to standard
134
- error are not lost.
135
-
136
- \warning It is not possible to redirect the standard error output to a file.
123
+ * \brief Executes a command and displays the command itself and its output.
124
+ *
125
+ * \param string $command The command to be executed.
126
+ *
127
+ * Simplifies the creation and debugging of pages that rely on multiple external
128
+ * programs by "emulating" the execution of the requested command in a terminal
129
+ * emulator. Can be useful during early stages of development. Replace with
130
+ * <b>exec()</b> afterwards.
131
+ *
132
+ * To perform the command execution, <b>passthru()</b> is used. The string
133
+ * <b>2\>&1</b> is appended to the command to ensure messages sent to standard
134
+ * error are not lost.
135
+ *
136
+ * \warning It is not possible to redirect the standard error output to a file.
137
137
*/
138
138
function debug_exec ($ command , /** @noinspection PhpUnusedParameterInspection */
139
139
&$ output , /** @noinspection PhpUnusedParameterInspection */
0 commit comments