Skip to content
Merged

Dev #80

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1896f7d
chore: release v4.0.0
usernane Aug 6, 2025
aa534be
Merge branch 'main' into dev
usernane Aug 26, 2025
4d57d85
chore: Ignore Tests Cache
usernane Nov 9, 2025
1fcbc47
refactor: `Uri` Enhancements
usernane Nov 12, 2025
474db18
feat: Added `HttpMessage`
usernane Nov 12, 2025
37acd59
chore: Updated License Headers
usernane Nov 12, 2025
6718e2a
chore: Config Changes
usernane Nov 12, 2025
b7f4e25
feat: Added `RequestURI`
usernane Nov 12, 2025
85bab63
refactor: Removed Non-Needed Methods
usernane Nov 12, 2025
74a4e3a
refactor: Removal of Static Dep
usernane Nov 12, 2025
bc99675
refactor: Fix Order of Parameters
usernane Nov 12, 2025
cc6b3ac
test: Updated URI Tests
usernane Nov 12, 2025
205cd5f
refactor: Added Missing Methods
usernane Nov 12, 2025
53adf06
Update Uri.php
usernane Nov 12, 2025
66effd1
chore: Multiple Fixes
usernane Nov 12, 2025
24f0865
chore: Multiple Fixes
usernane Nov 13, 2025
eeaa146
refactor: Updated Dep
usernane Nov 13, 2025
f790e7f
refactor: Revert to Original
usernane Nov 13, 2025
3f0b8ae
refactor: Allow No Domain For Cookie
usernane Nov 16, 2025
43c13d1
fix: Get URI With Fragment or Query String
usernane Nov 16, 2025
949b4fe
test: Fix Test Cases
usernane Nov 18, 2025
4effd3a
fix: URI Parameter
usernane Nov 18, 2025
d2c9c4a
fix: Multiple Fixes to Core
usernane Nov 18, 2025
dc30bb9
test: Updated Test Cases
usernane Nov 24, 2025
7a08fc7
ci: Fix Workflow
usernane Nov 25, 2025
00fe54a
refactor: Deprecation of Old Response Class
usernane Nov 25, 2025
a86a946
fix: Fixes to Request Class
usernane Nov 25, 2025
5cabecc
refactor: Rename of Class
usernane Nov 25, 2025
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
2 changes: 0 additions & 2 deletions .github/workflows/php83.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ jobs:
name: Code Quality
needs: test
uses: WebFiori/workflows/.github/workflows/quality-sonarcloud.yaml@main
with:
coverage-file: 'php-8.3-coverage.xml'
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ php-cs-fixer-v2.phar
php-cs-fixer.phar
.php-cs-fixer.cache
*.Identifier
/tests/.phpunit.cache
/.vscode
2 changes: 1 addition & 1 deletion WebFiori/Http/APIFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2019 Ibrahim BinAlshikh
* Copyright (c) 2019 WebFiori Framework
*
* For more information on the license, please visit:
* https://github.com/WebFiori/http/blob/master/LICENSE
Expand Down
3 changes: 2 additions & 1 deletion WebFiori/Http/APITestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2024 Ibrahim BinAlshikh
* Copyright (c) 2019 WebFiori Framework
*
* For more information on the license, please visit:
* https://github.com/WebFiori/http/blob/master/LICENSE
Expand Down Expand Up @@ -294,6 +294,7 @@ private function unset(array &$arr, array $params, WebServicesManager $m, array
$_SERVER['HTTP_'.strtoupper($trHeader)] = $trVal;
}
}
$m->setRequest(Request::createFromGlobals());
$m->process();

foreach ($params as $key => $val) {
Expand Down
36 changes: 30 additions & 6 deletions WebFiori/Http/AbstractWebService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2019 Ibrahim BinAlshikh
* Copyright (c) 2019 WebFiori Framework
*
* For more information on the license, please visit:
* https://github.com/WebFiori/http/blob/master/LICENSE
Expand Down Expand Up @@ -36,7 +36,12 @@ abstract class AbstractWebService implements JsonI {
*
*/
const I = 'info';

/**
* A constant which is used to indicate that the message that will be
* sent is of type success.
*
*/
const S = 'success';
/**
* The name of the service.
*
Expand Down Expand Up @@ -65,6 +70,13 @@ abstract class AbstractWebService implements JsonI {
*
*/
private $reqMethods;
/**
* The request instance used by the service.
*
* @var Request
*
*/
private $request;
/**
* This is used to indicate if authentication is required when the service
* is called.
Expand Down Expand Up @@ -123,6 +135,7 @@ public function __construct(string $name) {
$this->requireAuth = true;
$this->sinceVersion = '1.0.0';
$this->serviceDesc = '';
$this->request = Request::createFromGlobals();
}
/**
* Returns an array that contains all possible requests methods at which the
Expand Down Expand Up @@ -326,10 +339,21 @@ public final function addResponseDescription(string $description) {
* ('basic', 'bearer', 'digest', etc...). The 'credentials' will contain
* the credentials which can be used to authenticate the client.
*
* @throws InvalidArgumentException
*/
public function getAuthHeader() {
return Request::getAuthHeader();
if ($this->request !== null) {
return $this->request->getAuthHeader();
}
return null;
}

/**
* Sets the request instance for the service.
*
* @param mixed $request The request instance (Request, etc.)
*/
public function setRequest($request) {
$this->request = $request;
}
/**
* Returns the description of the service.
Expand Down Expand Up @@ -690,11 +714,11 @@ public function send(string $contentType, $data, int $code = 200) {
* will be not included in response. Default is empty string. Default is null.
*
*/
public function sendResponse(string $message, string $type = '', int $code = 200, mixed $otherInfo = '') {
public function sendResponse(string $message, int $code = 200, string $type = '', mixed $otherInfo = '') {
$manager = $this->getManager();

if ($manager !== null) {
$manager->sendResponse($message, $type, $code, $otherInfo);
$manager->sendResponse($message, $code, $type, $otherInfo);
}
}
/**
Expand Down
2 changes: 1 addition & 1 deletion WebFiori/Http/HeadersPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2022 Ibrahim BinAlshikh
* Copyright (c) 2019 WebFiori Framework
*
* For more information on the license, please visit:
* https://github.com/WebFiori/http/blob/master/LICENSE
Expand Down
6 changes: 3 additions & 3 deletions WebFiori/Http/HttpCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2022 Ibrahim BinAlshikh
* Copyright (c) 2019 WebFiori Framework
*
* For more information on the license, please visit:
* https://github.com/WebFiori/http/blob/master/LICENSE
Expand Down Expand Up @@ -57,7 +57,7 @@ class HttpCookie {
* <li>path: /</li>
* <li>secure: true</li>
* <li>http only: true</li>
* <li>domain: The domain at which the library is operating from.</li>
* <li>domain: The domain at which the cookie is operating from.</li>
* <li>same site: Lax</li>
* <li>expires: 0</li>
* <li>value: sha256 hash</li>
Expand All @@ -68,7 +68,7 @@ public function __construct() {
$this->cookieName = 'new-cookie';
$this->path = '/';
$this->secure = true;
$this->domain = Request::getUri()->getHost();
$this->domain = null;
$this->sameSite = 'Lax';
$this->val = hash('sha256', date('Y-m-d H:i:s'));
$this->expires = 0;
Expand Down
2 changes: 1 addition & 1 deletion WebFiori/Http/HttpHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2022 Ibrahim BinAlshikh
* Copyright (c) 2019 WebFiori Framework
*
* For more information on the license, please visit:
* https://github.com/WebFiori/http/blob/master/LICENSE
Expand Down
167 changes: 167 additions & 0 deletions WebFiori/Http/HttpMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2024 WebFiori Framework
*
* For more information on the license, please visit:
* https://github.com/WebFiori/http/blob/master/LICENSE
*/
namespace WebFiori\Http;

/**
* Base class for HTTP messages (Request and Response).
*
* @author Ibrahim
*/
class HttpMessage {
/**
* @var HeadersPool
*/
private $headersPool;

/**
* @var string
*/
private $body;

/**
* @var string
*/
private $protocolVersion;

/**
* @var string
*/
private $requestMethod;

/**
* Creates new instance of the class.
*/
public function __construct() {
$this->headersPool = new HeadersPool();
$this->body = '';
$this->protocolVersion = '1.1';
$this->requestMethod = 'GET';
}

/**
* Returns the headers pool.
*
* @return HeadersPool
*/
public function getHeadersPool() : HeadersPool {
return $this->headersPool;
}

/**
* Returns the value(s) of specific HTTP header.
*
* @param string $name The name of the header.
*
* @return array
*/
public function getHeader(string $name) : array {
return $this->headersPool->getHeader($name);
}

/**
* Returns an array that contains all headers.
*
* @return array
*/
public function getHeaders() : array {
return $this->headersPool->getHeaders();
}

/**
* Checks if specific header exists.
*
* @param string $name The name of the header.
* @param string|null $val Optional header value to check.
*
* @return bool
*/
public function hasHeader(string $name, ?string $val = '') : bool {
return $this->headersPool->hasHeader($name, $val);
}

/**
* Removes specific header.
*
* @param string $name The name of the header.
* @param string|null $val Optional header value to remove.
*
* @return bool
*/
public function removeHeader(string $name, ?string $val = '') : bool {
return $this->headersPool->removeHeader($name, $val);
}

/**
* Adds a header to the message.
*
* @param string $name The name of the header.
* @param string $value The value of the header.
* @param string|null $replaceValue Optional value to replace.
*
* @return bool
*/
public function addHeader(string $name, string $value, ?string $replaceValue = '') : bool {
return $this->headersPool->addHeader($name, $value, $replaceValue);
}

/**
* Gets the body of the message.
*
* @return string
*/
public function getBody() : string {
return $this->body;
}

/**
* Sets the body of the message.
*
* @param string $body
*/
public function setBody(string $body) {
$this->body = $body;
}

/**
* Gets the protocol version.
*
* @return string
*/
public function getProtocolVersion() : string {
return $this->protocolVersion;
}

/**
* Sets the protocol version.
*
* @param string $version
*/
public function setProtocolVersion(string $version) {
$this->protocolVersion = $version;
}

/**
* Gets the request method.
*
* @return string
*/
public function getRequestMethod() : string {
return $this->requestMethod;
}

/**
* Sets the request method.
*
* @param string $method
*/
public function setRequestMethod(string $method) {
$this->requestMethod = $method;
}
}
2 changes: 1 addition & 1 deletion WebFiori/Http/ManagerInfoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2020 Ibrahim BinAlshikh
* Copyright (c) 2019 WebFiori Framework
*
* For more information on the license, please visit:
* https://github.com/WebFiori/http/blob/master/LICENSE
Expand Down
2 changes: 1 addition & 1 deletion WebFiori/Http/ObjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2023 Ibrahim BinAlshikh
* Copyright (c) 2019 WebFiori Framework
*
* For more information on the license, please visit:
* https://github.com/WebFiori/.github/blob/main/LICENSE
Expand Down
2 changes: 1 addition & 1 deletion WebFiori/Http/ParamOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2024 Ibrahim BinAlshikh
* Copyright (c) 2019 WebFiori Framework
*
* For more information on the license, please visit:
* https://github.com/WebFiori/http/blob/master/LICENSE
Expand Down
2 changes: 1 addition & 1 deletion WebFiori/Http/ParamType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2019 Ibrahim BinAlshikh
* Copyright (c) 2019 WebFiori Framework
*
* For more information on the license, please visit:
* https://github.com/WebFiori/http/blob/master/LICENSE
Expand Down
Loading
Loading