Skip to content

Commit

Permalink
Create lastModified method and added server bag to kernel (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
danijelgalic committed Oct 22, 2024
1 parent 4b467b9 commit 74fd1ec
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 7 deletions.
Binary file modified phar/core.min.phar
Binary file not shown.
Binary file modified phar/core.phar
Binary file not shown.
7 changes: 6 additions & 1 deletion src/kernel/console/firehub.Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use FireHub\Core\Initializers\Kernel as BaseKernel;
use FireHub\Core\Kernel\Request as BaseRequest;
use FireHub\Core\Components\DI\Container;

/**
* ### Console Kernel
Expand All @@ -30,6 +31,8 @@ class Kernel extends BaseKernel {
*
* @since 1.0.0
*
* @uses \FireHub\Core\Components\DI\Container::resolve() To resolve binding from the container.
* @uses \FireHub\Core\Kernel\Console\Server As Console Server and execution environment information.
* @uses \FireHub\Core\Kernel\Console\Response As return.
*
* @param \FireHub\Core\Kernel\Console\Request $request <p>
Expand All @@ -40,7 +43,9 @@ class Kernel extends BaseKernel {
*/
public function handle (BaseRequest $request):Response {

return new Response($request, 'Console Torch');
return new Response(
Container::getInstance()->resolve(Server::class), $request, 'Console Torch'
);

}

Expand Down
5 changes: 5 additions & 0 deletions src/kernel/console/firehub.Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace FireHub\Core\Kernel\Console;

use FireHub\Core\Kernel\Response as BaseResponse;
use FireHub\Core\Kernel\Console\Server;

/**
* ### Console Response
Expand All @@ -28,6 +29,9 @@ class Response extends BaseResponse {
* ### Constructor
* @since 1.0.0
*
* @param \FireHub\Core\Kernel\Console\Server $server <p>
* Console Server and execution environment information.
* </p>
* @param \FireHub\Core\Kernel\Console\Request $request <p>
* Interact with the current console request being handled by your application.
* </p>
Expand All @@ -38,6 +42,7 @@ class Response extends BaseResponse {
* @return void
*/
public function __construct (
protected readonly Server $server,
protected readonly Request $request,
protected string $content = ''
) {}
Expand Down
7 changes: 6 additions & 1 deletion src/kernel/http/firehub.Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use FireHub\Core\Initializers\Kernel as BaseKernel;
use FireHub\Core\Kernel\Request as BaseRequest;
use FireHub\Core\Components\DI\Container;

/**
* ### HTTP Kernel
Expand All @@ -30,6 +31,8 @@ class Kernel extends BaseKernel {
*
* @since 1.0.0
*
* @uses \FireHub\Core\Components\DI\Container::resolve() To resolve binding from the container.
* @uses \FireHub\Core\Kernel\HTTP\Server As HTTP Server and execution environment information.
* @uses \FireHub\Core\Kernel\HTTP\Response As return.
*
* @param \FireHub\Core\Kernel\HTTP\Request $request <p>
Expand All @@ -40,7 +43,9 @@ class Kernel extends BaseKernel {
*/
public function handle (BaseRequest $request):Response {

return (new Response($request, 'HTTP Torch'));
return (new Response(
Container::getInstance()->resolve(Server::class), $request, 'HTTP Torch')
);

}

Expand Down
42 changes: 39 additions & 3 deletions src/kernel/http/firehub.Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
use FireHub\Core\Kernel\Response as BaseResponse;
use FireHub\Core\Support\Str;
use FireHub\Core\Support\Collection\Type\Indexed;
use FireHub\Core\Support\Zwick\ {
DateTime, Timestamp
};
use FireHub\Core\Support\Enums\HTTP\ {
CommonMimeType, ContentDisposition, ContentEncoding, SiteData, StatusCode,
Authentication\Scheme, Contracts\StatusCode as StatusCodeContract, CSP\Directive, CSP\Value
Authentication\Scheme, Contracts\StatusCode as StatusCodeContract, CSP\Value
};
use FireHub\Core\Support\Enums\ {
Language, Hash\Algorithm, String\Encoding
Language, DateTime\Format\Predefined, Hash\Algorithm, String\Encoding
};
use FireHub\Core\Support\LowLevel\ {
Hash, HTTP
File, Hash, HTTP
};

/**
Expand All @@ -42,6 +45,9 @@ class Response extends BaseResponse {
* ### Constructor
* @since 1.0.0
*
* @param \FireHub\Core\Kernel\HTTP\Server $server <p>
* HTTP Server and execution environment information.
* </p>
* @param \FireHub\Core\Kernel\HTTP\Request $request <p>
* Interact with the current HTTP request being handled by your application.
* </p>
Expand All @@ -52,6 +58,7 @@ class Response extends BaseResponse {
* @return void
*/
public function __construct (
protected readonly Server $server,
protected readonly Request $request,
protected string $content = ''
) {}
Expand Down Expand Up @@ -346,6 +353,35 @@ public function eTag (string $value):self {

}

/**
* ### Identifier for a specific version of a resource
*
* It lets caches be more efficient and save bandwidth, as a web server doesn't need to resend a full response if
* the content wasn't changed. Additionally, e-tags help to prevent simultaneous updates of a resource from
* overwriting each other ("midair collisions").
* @since 1.0.0
*
* @uses \FireHub\Core\Kernel\HTTP\Response::replaceHeader() To send and replace a raw HTTP header.
* @uses \FireHub\Core\Support\Zwick\DateTime::fromTimestamp() To create datetime from a script modified time.
* @uses \FireHub\Core\Support\Zwick\DateTime::parse() To parse date according to the given format.
* @uses \FireHub\Core\Support\Zwick\Timestamp::from() To create a timestamp from a script modified time.
* @uses \FireHub\Core\Support\LowLevel\File::lastModified() To get the last modification time of a script.
* @uses \FireHub\Core\Kernel\HTTP\Server::scriptFilename() To get the absolute pathname of the currently executing
* script.
* @uses \FireHub\Core\Support\Enums\DateTime\Format\Predefined::RFC7231 As datetime format.
*
* @return $this This response.
*/
public function lastModified ():self {

$this->replaceHeader('Last-Modified: '.DateTime::fromTimestamp(
Timestamp::from(File::lastModified($this->server->scriptFilename()))
)->parse(Predefined::RFC7231));

return $this;

}

/**
* ### Send a raw HTTP header
* @since 1.0.0
Expand Down
11 changes: 9 additions & 2 deletions src/kernel/http/micro/firehub.Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
use FireHub\Core\Kernel\ {
Request as BaseRequest, Response as BaseResponse
};
use FireHub\Core\Kernel\HTTP\Response;
use FireHub\Core\Kernel\HTTP\ {
Response, Server
};
use FireHub\Core\Components\DI\Container;

/**
* ### Micro HTTP Kernel
Expand All @@ -33,6 +36,8 @@ class Kernel extends BaseKernel {
*
* @since 1.0.0
*
* @uses \FireHub\Core\Components\DI\Container::resolve() To resolve binding from the container.
* @uses \FireHub\Core\Kernel\HTTP\Server As HTTP Server and execution environment information.
* @uses \FireHub\Core\Kernel\HTTP\Response As return.
*
* @param \FireHub\Core\Kernel\HTTP\Request $request <p>
Expand All @@ -43,7 +48,9 @@ class Kernel extends BaseKernel {
*/
public function handle (BaseRequest $request):BaseResponse {

return new Response($request, 'HTTP Micro Torch');
return new Response(
Container::getInstance()->resolve(Server::class), $request, 'HTTP Micro Torch'
);

}

Expand Down

0 comments on commit 74fd1ec

Please sign in to comment.