Skip to content

Commit 8328c3d

Browse files
committed
Updated user id & project id fetching
Removed pass by reference of the project files. Made the method look for the request fields `userId` & `projectId` instead of the txt files that were user until now.
1 parent 3443923 commit 8328c3d

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

Symfony/src/Codebender/BuilderBundle/Controller/DefaultController.php

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ protected function compile($contents)
8181
{
8282
$apiHandler = $this->get('codebender_builder.handler');
8383

84-
$files = $contents["files"];
84+
$contents = $this->checkForUserIdProjectId($contents);
8585

86-
$this->checkForUserIdProjectId($files);
86+
$files = $contents["files"];
8787

8888
$userLibraries = array();
8989

@@ -199,28 +199,20 @@ protected function returnProvidedAndFetchedLibraries($projectFiles, $userLibrari
199199
* Checks if project id and user id txt files exist in the request files.
200200
* If not, creates these files with null id
201201
*
202-
* @param array $projectFiles
202+
* @param array $requestContents
203+
* @return array
203204
*/
204-
protected function checkForUserIdProjectId(&$projectFiles)
205+
protected function checkForUserIdProjectId($requestContents)
205206
{
206-
$foundProject = false;
207-
$foundUser = false;
208-
209-
foreach ($projectFiles as $file) {
210-
if (preg_match('/(?<=user_)[\d]+/', $file['filename'])) {
211-
$foundUser = true;
212-
}
213-
if (preg_match('/(?<=project_)[\d]+/', $file['filename'])) {
214-
$foundProject = true;
215-
}
207+
if (!array_key_exists('userId', $requestContents)) {
208+
$requestContents['userId'] = 'null';
216209
}
217210

218-
if (!$foundUser) {
219-
$projectFiles[] = array('filename' => 'user_null.txt', 'content' => '');
220-
}
221-
if (!$foundProject) {
222-
$projectFiles[] = array('filename' => 'project_null.txt', 'content' => '');
211+
if (!array_key_exists('projectId', $requestContents)) {
212+
$requestContents['projectId'] = 'null';
223213
}
214+
215+
return $requestContents;
224216
}
225217
}
226218

0 commit comments

Comments
 (0)