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

Develope #3

Merged
merged 6 commits into from
Mar 28, 2019
Merged
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
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Cherry-request Changelog

## [v1.0.0](https://github.com/ABGEO07/cherry-request/releases/tag/v1.0.0 "v1.0.0") (2019-03-25)
## [v1.0.1](https://github.com/ABGEO07/cherry-request/releases/tag/v1.0.1 "v1.0.1") (2019-03-28)

- Change Namespace

Now you should use new namespace `Cherry\HttpUtils\Request`

- Validate code in PHP CodeSniffer

Code and comments has checked on [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)

## [v1.0.0](https://github.com/ABGEO07/cherry-request/releases/tag/v1.0.0 "v1.0.0") (2019-02-25)
#### The first stable version

- Package available on: `composer require cherry-project/request`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require_once __DIR__ . '/vendor/autoload.php';
## Class Request
Import class
```php
use Cherry\Request;
use Cherry\HttpUtils\Request;
```
Crete class new object
```php
Expand Down
2 changes: 1 addition & 1 deletion examples/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//Include autoloader
require_once __DIR__ . '/../vendor/autoload.php';

use Cherry\Request;
use Cherry\HttpUtils\Request;

$request = new Request();

Expand Down
49 changes: 37 additions & 12 deletions src/Request.php → src/HttpUtils/Request.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
<?php
/**
* The file contains Request class
*
* PHP version 5
*
* @category Library
* @package Cherry
* @author Temuri Takalandze <takalandzet@gmail.com>
* @license https://github.com/ABGEO07/cherry-request/blob/master/LICENSE MIT
* @link https://github.com/ABGEO07/cherry-request
*/

namespace Cherry;
namespace Cherry\HttpUtils;

/**
* Cherry project request class
*
* @package Cherry
* @author Temuri Takalandze(ABGEO) <takalandzet@gmail.com>
* @category Library
* @package Cherry
* @author Temuri Takalandze <takalandzet@gmail.com>
* @license https://github.com/ABGEO07/cherry-request/blob/master/LICENSE MIT
* @link https://github.com/ABGEO07/cherry-request
*/

class Request
{
/**
* Get request HTTP headers
*
* @param null|array|string $key
* @param null|array|string $key Searched key or array of keys
*
* @return array|string
*/
public function getHeaders($key = null)
Expand All @@ -27,17 +42,21 @@ public function getHeaders($key = null)
$value = isset($headers[$k]) ? $headers[$k] : null;
$return[$k] = $value;
}
} else
} else {
$return = isset($headers[$key]) ? $headers[$key] : null;
} else
}
} else {
$return = $headers;
}

return $return;
}

/**
* Check if request has header
*
* @param $key
* @param string $key Http header for searching
*
* @return bool
*/
public function hasHeader($key)
Expand Down Expand Up @@ -72,7 +91,8 @@ public function getPath()
*/
function getScheme()
{
return stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://';
return stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ?
'https://' : 'http://';
}

/**
Expand All @@ -95,14 +115,17 @@ function getQueryParams()
/**
* Get request query parameter by key
*
* @param $key
* @param string $key Query parameter name
*
* @return string|null
*/
function getQuery($key)
{
$queryArray = $this->getQueryParams();
if (isset($queryArray[$key]))
if (isset($queryArray[$key])) {
return $queryArray[$key];
}

return null;
}

Expand All @@ -115,10 +138,12 @@ function getData()
{
$method = $this->getMethod();
$return = null;
if ($method == 'GET')
if ($method == 'GET') {
$return = $_GET;
else if ($method == 'POST')
} else if ($method == 'POST') {
$return = $_POST;
}

return $return;
}
}