Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #10

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/WebKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ class WebKernel
*/
protected $responder;

protected $available = [
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea is to get the available via the user, may be an extra parameter in constructor.

'text/html',
'application/json',
'application/xml',
'text/csv'
];

/**
*
* Constructor.
Expand Down Expand Up @@ -91,7 +98,18 @@ public function __get($key)
public function __invoke()
{
$this->router->__invoke();
$this->dispatcher->__invoke();
$content = $this->dispatcher->__invoke();
if (! $this->responder->getResponse()->content->get()) {
$media = $this->dispatcher->getRequest()->accept->media
->negotiate($this->available);
if (! is_string($content)) {
throw new \Exception("Response content must be a string");
}
$this->responder->getResponse()->content->set($content);
$this->responder->getResponse()->content->setType(
$media->available->getValue()
);
}
$this->responder->__invoke();
}
}
7 changes: 6 additions & 1 deletion src/WebKernelDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function __invoke()
$this->logControllerValue($controller);
$this->checkForMissingController($controller);
try {
$this->dispatcher->__invoke($this->request->params->get());
return $this->dispatcher->__invoke($this->request->params->get());
} catch (Exception $e) {
$this->caughtException($e);
}
Expand Down Expand Up @@ -150,4 +150,9 @@ protected function caughtException(Exception $e)
'exception' => $e,
));
}

public function getRequest()
{
return $this->request;
}
}
5 changes: 5 additions & 0 deletions src/WebKernelResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,9 @@ protected function setcookie(
) {
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
}

public function getResponse()
{
return $this->response;
}
}