Skip to content

Commit

Permalink
Unified middleware under global controllers
Browse files Browse the repository at this point in the history
Moved all common middleware to global controllers def. Cleaner code and
easier to maintain.
  • Loading branch information
DiegoPino committed Jan 13, 2016
1 parent 0654a2b commit 2428860
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions services/ResourceService/src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,18 @@
// If $id is empty then assume we are dealing with fedora base rest endpoint
return $app['config']['islandora']['fedoraProtocol'].'://'.$app['config']['islandora']['fedoraHost'].$app['config']['islandora']['fedoraPath'];
}

};

/**
* Apply middleware to all controllers
*/
$app['controllers']
->convert('id', $idToUri)
->assert('id',$app['config']['islandora']['resourceIdRegex'])
->before($htmlHeaderToTurtle)
->before($hostHeaderNormalize)
;

/**
* Convert returned Guzzle responses to Symfony responses.
*/
Expand All @@ -126,12 +135,8 @@
}
return $response;
})
->value('child',"")
->value('id',"")
->convert('id', $idToUri)
->assert('id',$app['config']['islandora']['resourceIdRegex'])
->before($htmlHeaderToTurtle)
->before($hostHeaderNormalize);
->value('child',"");

/**
* Resource POST route. takes $id (valid UUID or empty) for the parent resource as first value to match
Expand All @@ -149,10 +154,7 @@
}
return $response;
})
->value('id',"")
->assert('id',$app['config']['islandora']['resourceIdRegex'])
->before($htmlHeaderToTurtle)
->before($hostHeaderNormalize);
->value('id',"");

/**
* Resource PUT route. takes $id (valid UUID or empty) for the resource to be update/created as first value to match,
Expand All @@ -171,10 +173,8 @@
}
return $response;
})
->value('child',"")
->assert('id',$app['config']['islandora']['resourceIdRegex'])
->before($htmlHeaderToTurtle)
->before($hostHeaderNormalize);
->value('id',"")
->value('child',"");

/**
* Resource PATCH route. takes $id (valid UUID or empty) for the resource to be modified via SPARQL as first value to match,
Expand All @@ -192,10 +192,8 @@
}
return $response;
})
->value('child',"")
->assert('id',$app['config']['islandora']['resourceIdRegex'])
->before($htmlHeaderToTurtle)
->before($hostHeaderNormalize);
->value('id',"")
->value('child',"");

/**
* Resource DELETE route. takes $id (valid UUID or empty) for the resource to be modified via SPARQL as first value to match,
Expand All @@ -218,10 +216,8 @@
}
return $response;
})
->value('child',"")
->assert('id',$app['config']['islandora']['resourceIdRegex'])
->before($htmlHeaderToTurtle)
->before($hostHeaderNormalize);
->value('id',"")
->value('child',"");

$app->after(function (Request $request, Response $response, Application $app) {
// Todo a closing controller, not sure what now but i had an idea.
Expand Down

0 comments on commit 2428860

Please sign in to comment.