diff --git a/.gitignore b/.gitignore index 844ee15..212e57c 100644 --- a/.gitignore +++ b/.gitignore @@ -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.* diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..94ed20c --- /dev/null +++ b/CONTRIBUTING.md @@ -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 + */ +``` +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. \ No newline at end of file diff --git a/README.md b/README.md index c856bda..9c30163 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 @@ -651,6 +652,38 @@ In a sample case, we have this controller: ``` +### 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 + 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. diff --git a/system/engine/VERSION b/system/engine/VERSION index a73b432..1d5e9e0 100644 --- a/system/engine/VERSION +++ b/system/engine/VERSION @@ -1 +1 @@ -1.5.2 \ No newline at end of file +1.5.3 \ No newline at end of file diff --git a/system/engine/response.php b/system/engine/response.php index 0f56875..b6e1779 100644 --- a/system/engine/response.php +++ b/system/engine/response.php @@ -17,7 +17,14 @@ final class Response { $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; } @@ -68,5 +75,13 @@ final class Response { echo $ouput; } } -} -?> \ No newline at end of file + + 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.""); + } +} \ No newline at end of file