@@ -86,49 +86,82 @@ public function compileAction($auth_key, $version)
86
86
87
87
/**
88
88
*
89
- * @param type $files
90
- * @param array $personalLibs
89
+ * @param array $files
90
+ * @param array $userLibs
91
91
*
92
- * @return type
92
+ * @return array
93
93
*/
94
- protected function checkHeaders ($ files , array $ personalLibs )
94
+ protected function checkHeaders ($ files , array $ userlibs )
95
95
{
96
96
$ apiHandler = $ this ->get ('codebender_api.handler ' );
97
97
98
98
$ headers = $ apiHandler ->read_libraries ($ files );
99
99
100
100
// declare arrays
101
- $ libraries = $ notFoundHeaders = $ foundFiles = array ();
101
+ $ libraries = $ notFoundHeaders = $ foundHeaders = $ fetchedLibs = $ providedLibs = array ();
102
+
103
+ $ providedLibs = array_keys ($ userlibs );
102
104
103
105
// get library manager url
104
106
$ libmanager_url = $ this ->container ->getParameter ('library ' );
105
107
106
- $ libraries = $ personalLibs ;
108
+ $ libraries = $ userlibs ;
107
109
108
110
foreach ($ headers as $ header ) {
109
- $ foundPersonal = false ;
110
- foreach ($ personalLibs as $ plibrary ){
111
- foreach ($ plibrary as $ libcontent ){
112
- if ($ libcontent ["filename " ] == $ header .".h " )
113
- $ foundPersonal = true ;
111
+
112
+ $ exists_in_request = false ;
113
+ foreach ($ userlibs as $ lib ){
114
+ foreach ($ lib as $ libcontent ){
115
+ if ($ libcontent ["filename " ] == $ header .".h " ) {
116
+ $ exists_in_request = true ;
117
+ $ foundHeaders [] = $ header . ".h " ;
118
+ }
114
119
}
115
120
}
116
- if ($ foundPersonal === false ) {
121
+ if ($ exists_in_request === false ) {
117
122
118
123
$ data = $ apiHandler ->get ($ libmanager_url . "/fetch?library= " . urlencode ($ header ));
119
124
$ data = json_decode ($ data , true );
120
125
121
126
if ($ data ["success " ]) {
127
+ $ fetchedLibs [] = $ header ;
128
+
122
129
$ libraries [$ header ] = $ data ["files " ];
123
- foreach ($ data ['files ' ] as $ file ) {
124
- $ foundFiles [] = $ file ['filename ' ];
125
- }
130
+ $ foundHeaders [] = $ header . ".h " ;
131
+
126
132
} elseif (!$ data ['success ' ]){
127
133
$ notFoundHeaders [] = $ header . ".h " ;
128
134
}
129
135
}
130
136
}
131
- return array ('libraries ' => $ libraries , 'foundFiles ' => $ foundFiles , 'notFoundHeaders ' => $ notFoundHeaders );
137
+
138
+ return array (
139
+ 'libraries ' => $ libraries ,
140
+ 'providedLibraries ' => $ providedLibs ,
141
+ 'fetchedLibraries ' => $ fetchedLibs ,
142
+ 'detectedHeaders ' => $ headers ,
143
+ 'foundHeaders ' => $ foundHeaders ,
144
+ 'notFoundHeaders ' => $ notFoundHeaders );
145
+ }
146
+
147
+ /**
148
+ *
149
+ * @param array $files
150
+ * Checks if project id and user id txt files exist in the request files.
151
+ * If not, creates these files with null id
152
+ *
153
+ */
154
+ protected function checkForUserProject (&$ files )
155
+ {
156
+ $ foundProj = $ foundUsr = false ;
157
+
158
+ foreach ($ files as $ file ) {
159
+ if (preg_match ('/(?<=user_)[\d]+/ ' , $ file ['filename ' ])) $ foundUsr = true ;
160
+ if (preg_match ('/(?<=project_)[\d]+/ ' , $ file ['filename ' ])) $ foundProj = true ;
161
+ }
162
+
163
+ if (!$ foundUsr ) $ files [] = array ('filename ' => 'user_null.txt ' , 'content ' => '' );
164
+ if (!$ foundProj ) $ files [] = array ('filename ' => 'project_null.txt ' , 'content ' => '' );
132
165
}
133
166
}
134
167
0 commit comments