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

Configurable Default Format #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 16 additions & 2 deletions source/Jacwright/RestServer/RestServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class RestServer {
public $useCors = false;
public $allowedOrigin = '*';

protected $defaultFormat = RestFormat::PLAIN;
protected $data = null; // special parameter for post data
protected $query = null; // special parameter for query string
protected $map = array();
Expand All @@ -67,8 +68,10 @@ class RestServer {
* The constructor.
*
* @param string $mode The mode, either debug or production
* @param string $defaultFormat
*/
public function __construct($mode = 'debug') {
public function __construct($mode = 'debug', $defaultFormat = RestFormat::PLAIN) {
$this->defaultFormat = $defaultFormat;
$this->mode = $mode;

// Set the root
Expand Down Expand Up @@ -171,6 +174,17 @@ public function setJsonAssoc($value) {
$this->jsonAssoc = ($value === true);
}

/**
* @param string $defaultFormat
*
* @return RestServer
*/
public function setDefaultFormat( $defaultFormat ) {
$this->defaultFormat = $defaultFormat;

return $this;
}

public function addClass($class, $basePath = '') {
$this->loadCache();

Expand Down Expand Up @@ -433,7 +447,7 @@ public function getMethod() {
}

public function getFormat() {
$format = RestFormat::PLAIN;
$format = $this->defaultFormat;
$accept_mod = null;

if (isset($_SERVER["HTTP_ACCEPT"])) {
Expand Down