Skip to content

Instantly share code, notes, and snippets.

@shadow-fox
Forked from weierophinney/Module.php
Created May 7, 2014 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shadow-fox/5aa4c674583c037245f8 to your computer and use it in GitHub Desktop.
Save shadow-fox/5aa4c674583c037245f8 to your computer and use it in GitHub Desktop.
<?php
namespace SomeApi;
use ZF\ApiProblem\ApiProblem;
use ZF\ApiProblem\ApiProblemResponse;
class Module
{
public function onBootstrap($e)
{
$app = $e->getTarget();
$events = $app->getEventManager();
$events->attach('route', array($this, 'onRoute'), -1000);
}
public function onRoute($e)
{
$request = $e->getRequest();
if (! method_exists($request, 'getHeaders')) {
// Console request? not sure what to do here, move along...
return;
}
if ($request->getHeaders()->has('Some-Specific-Header')) {
// Header is there, move along...
return;
}
return new ApiProblemResponse(new ApiProblem(
400,
'Missing Some-Specific-Header in the request!'
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment