Skip to content

Instantly share code, notes, and snippets.

@ppeiris
Created September 8, 2016 20:11
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 ppeiris/78c4e4cc96d09adbbc8b9e9754b3397a to your computer and use it in GitHub Desktop.
Save ppeiris/78c4e4cc96d09adbbc8b9e9754b3397a to your computer and use it in GitHub Desktop.
<?php
namespace ispaccount;
use ZF\ApiProblem\ApiProblem;
use ZF\Apigility\Provider\ApigilityProviderInterface;
use Zend\Http\Response\ApiProblemResponse;
use Zend\Mvc\MvcEvent;
class Module implements ApigilityProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/../../config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'ZF\Apigility\Autoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__,
),
),
);
}
public function onBootstrap($e)
{
$eventm = $e->getTarget()->getEventManager();
$eventm->attach(MvcEvent::EVENT_ROUTE, [$this, 'onEventRoute']);
}
public function onEventRoute($e)
{
$eventManager = $e->getTarget()->getEventManager();
$request = $e->getRequest();
if (strpos($e->getRouter()->getRequestUri()->getPath(), 'api') == false) {
return; // not a api call
}
if (!method_exists($request, 'getUri')) {
return; // Not a HTTP request
}
$routematch = $e->getRouteMatch();
if (!$routematch) {
return;
}
print_r($routematch->getMatchedRouteName());
if ($routematch->getMatchedRouteName() != 'ispaccount.rest.ispaccount') {
return;
}
print_r(get_class_methods($request));
// print_r($routematch->getMatchedRouteName());
print_r($routematch->getParam('ispaccount_id'));
$eventManager->trigger('logit', $this, array("in the renderEntity"));
$apiProblem = new ApiProblem(200, 'There were no routes found matching your request.');
// $e->stopPropagation(true);
// $e->setResponse(new ApiProblemResponse($apiProblem));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment