Skip to content

Commit

Permalink
Response class implements functions to JSON and REST facilities. Giti…
Browse files Browse the repository at this point in the history
…gnore add VS Code files, add contributing guideline.
  • Loading branch information
oliveira131 committed Nov 28, 2020
1 parent fde068e commit 6ef6db4
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ bld/
# Visual Studio 2017 auto generated files
Generated\ Files/

# ---> VisualStudioCode
.vscode/*
.vscode/settings.json
.vscode/tasks.json
.vscode/launch.json
.vscode/extensions.json

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
Expand Down
80 changes: 80 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Contribution Guidelines

## Introduction

This document explains how to contribute changes to the Phacil Framework project.
It assumes you have followed the
installation instructions on readme file.
Sensitive security-related issues should be reported to
[bug-reports@exactiweb.com](mailto:bug-reports@exactiweb.com) or on our website [exacti.com.br/contato](https://www.exacti.com.br/contato).


## Bug reports

Please search the issues on the issue tracker with a variety of keywords to ensure your bug is not already reported.

If unique, [open an issue](https://github.com/exacti/phacil-framework/issues/new) and answer the questions so we can understand and reproduce the problematic behavior.

To show us that the issue you are having is in Phacil itself, please write clear, concise instructions so we can reproduce the behavior, even if it seems obvious. The more detailed and specific you are, the faster we can fix the issue. Check out [How to Report Bugs Effectively](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html) article.

Even though it is maintained by a company of Brazilian origin, the chosen language for issue reports is English.

**Don't forget**: *maintain your code compatibility at base version and the max PHP version described in README.md file*.

Please be kind, remember that Phacil Framework comes at no cost to you, and you're getting free help.


## Code review

Changes to Phacil must be reviewed before they are accepted, no matter who makes the change, even if they are an owner or a maintainer. We use GitHub's pull request workflow to do that.

Please try to make your pull request easy to review for us. And, please read the *[How to get faster PR reviews](https://github.com/kubernetes/community/blob/261cb0fd089b64002c91e8eddceebf032462ccd6/contributors/guide/pull-requests.md#best-practices-for-faster-reviews)* guide. It has lots of useful tips for any project you may want to contribute.

Some of the key points:

* Make small pull requests. The smaller, the faster to review and the more likely it will be merged soon.
* Don't make changes unrelated to your PR. Maybe there are typos on some comments, maybe refactoring would be welcome on a function... but if that is not related to your PR, please make *another* PR for that.
* Split big pull requests into multiple small ones. An incremental change will be faster to review than a huge PR.


## Languages

All repository comunications work only with English language.


## Add features

If you contribute with a new feature, few free to explain how to use in README.md file. This isn't required but we will take into consideration.

Please, describe better as you can the new feature in the pull request.

Changes on license file inst's allow (even intentional).


## Versions

We at ExacTI determined the versioning value of this project in the major.minor.fix system.

If your changes is just a bugfix, we increment a +1 in fix version. If your add some feature or change a behavior, we add +1 in minor value. Only for big changes in the struct of Phacil Framework we can consider to change major value, but it's rare for now.

Plans for major increments are communicated months in advance to prepare a direction and help contributors understand the way that the project will follow.

The versions changes are decided by ExacTI team. The file VERSION in system/engine can be changed like a suggestion, but the ExacTI team can be modify for the value most appropriate.


## Copyright

Code that you contribute should use the standard copyright header:

```php
/**
* Copyright (c) 2019. ExacTI Technology Solutions
* GPLv3 General License.
* https://exacti.com.br
* Phacil PHP Framework - https://github.com/exacti/phacil-framework
* Author: YOUR NAME HERE <your@email.com>
*/
```
You also can add your GitHub profile link bellow the author line.

Files in the repository contain copyright from the year they are added to the year they are last changed. If the copyright author is changed, just paste the header below the old one.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,14 @@ In a sample case, we have this controller:

$json = json_encode($record);

$this->response->addHeader('Content-Type: application/json');
$this->response->isJSON(); //Auto send the 'Content-Type: application/json' header

$this->response->setOutput($json);
}
}
```

The `$this->response->addHeader` is responsible to send a personalized HTTP header to browser, in this case specify the *Content-Type* information. The `$this->response->setOutput()` works for send output of the content of a variable, function, constant, etc., to the browser.
The `$this->response->isJSON` is responsible to send a JSON Content-Type HTTP header to browser. The `$this->response->setOutput()` works for send output of the content of a variable, function, constant, etc., to the browser.

We have this output:

Expand Down Expand Up @@ -642,6 +642,7 @@ In a sample case, we have this controller:
}
```

The `$this->response->addHeader` have a function to send a personalized HTTP header to browser, in this case specify the *Content-Type* information.
The response is:
```xml
<?xml version="1.0"?>
Expand All @@ -651,6 +652,38 @@ In a sample case, we have this controller:
</root>
```

### setOutput utilities

In response we have *setOutput* function with parameters to facility for JSON and REST use.

The parameters are `$this->response->setOutput($output, bool $isJSON, int $HTTPCODE, string $HTTPDESC);` on automatic apply the JSON Content-type header if the second parameter is true and define the HTTP response code in third parameter. A description for HTTP code also can be send, if you need.

Except for the first parameter, the others are optional.

#### Sample of use for JSON Rest output only with setOutput function

```php
<?php
class ControllerApiData extends Controller {
public function index() {
$record = [
[
"index" => 482,
"id" => 221
],
[
"index" => 566,
"id" => 328
]
];

$json = json_encode($record);

$this->response->setOutput($json, true, 404);
}
}
```

## Set and load configurations

The config library in Phacil Framework obtains values to use in entire web app of: `$config` array in *config.php* file, the settings table in your configured database or both.
Expand Down
2 changes: 1 addition & 1 deletion system/engine/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.2
1.5.3
21 changes: 18 additions & 3 deletions system/engine/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ public function setCompression($level) {
$this->level = $level;
}

public function setOutput($output) {
public function setOutput($output, bool $isJSON = false, int $HTTPCODE = 0, string $HTTPDESC = null) {

if($isJSON)
$this->isJSON();

if($HTTPCODE !== 0)
$this->code($HTTPCODE, $HTTPDESC);

$this->output = $output;
}

Expand Down Expand Up @@ -68,5 +75,13 @@ public function output() {
echo $ouput;
}
}
}
?>

public function isJSON() {
$this->addHeader('Content-Type: application/json');
}

public function code(int $code, string $description = null){
$this->addHeader("HTTP/1.1 ".$code.(($description) ? " ". $description : ""));
$this->addHeader("Status: ".$code."");
}
}

0 comments on commit 6ef6db4

Please sign in to comment.