Skip to content
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 build.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
},
"execute": {
"command": "webpack",
"arguments": ["--entry","./script/script.es6", "--output-path", "./www", "--output-filename", "script.js", "--devtool", "source-map", "--mode", "production"]
"arguments": ["--entry","./script/script.es6", "--output-path", "./www", "--output-filename", "script.js", "--devtool", "source-map", "--mode", "development"]
}
},

"script/*sw.js": {
"require": {
"vendor/bin/sync": "*"
},
"execute": {
"command": "vendor/bin/sync",
"arguments": ["--pattern", "*sw.js", "script", "www/"]
}
},

Expand Down
38 changes: 19 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion go.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
chdir(dirname($_SERVER["DOCUMENT_ROOT"]));
ini_set("display_errors", "on");
ini_set("html_errors", "false");
/**
* Before any code is executed, return false here if a static file is requested.
* When running the PHP inbuilt server, this will output the static file.
Expand All @@ -26,7 +27,7 @@
* files exist.
* @link https://getcomposer.org/doc/00-intro.md
*/
foreach([__DIR__, dirname($_SERVER["DOCUMENT_ROOT"])] as $dir) {
foreach([dirname($_SERVER["DOCUMENT_ROOT"]), __DIR__] as $dir) {
$autoloadPath = "$dir/vendor/autoload.php";
if(file_exists($autoloadPath)) {
/** @noinspection PhpIncludeInspection */
Expand Down
8 changes: 6 additions & 2 deletions src/Logic/LogicExecutor.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Gt\WebEngine\Logic;

use Generator;
use Gt\Routing\Assembly;
use Gt\Routing\LogicStream\LogicStreamNamespace;
use Gt\Routing\LogicStream\LogicStreamWrapper;
Expand All @@ -17,7 +18,8 @@ public function __construct(
}
}

public function invoke(string $name):void {
/** @return Generator<string> filename::function() */
public function invoke(string $name):Generator {
foreach($this->assembly as $file) {
$nsProject = (string)(new LogicProjectNamespace(
$file,
Expand All @@ -36,6 +38,7 @@ public function invoke(string $name):void {
$instance,
$name
);
yield "$file::$name()";
}
}
else {
Expand All @@ -52,6 +55,7 @@ public function invoke(string $name):void {
null,
$fnReference
);
yield "$file::$name()";
}
}
}
Expand All @@ -60,6 +64,6 @@ public function invoke(string $name):void {

private function loadLogicFile(string $file):void {
$streamPath = LogicStreamWrapper::STREAM_NAME . "://$file";
require($streamPath);
require_once($streamPath);
}
}
8 changes: 8 additions & 0 deletions src/Middleware/DefaultServiceLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use Gt\DomTemplate\PlaceholderBinder;
use Gt\DomTemplate\TableBinder;
use Gt\DomTemplate\TemplateCollection;
use Gt\Http\Header\ResponseHeaders;
use Gt\Http\Request;
use Gt\Http\Response;
use Gt\Http\Uri;
use Gt\ServiceContainer\Container;
use Gt\ServiceContainer\LazyLoad;
Expand All @@ -26,6 +28,12 @@ public function __construct(
) {
}

#[LazyLoad]
public function loadResponseHeaders():ResponseHeaders {
$response = $this->container->get(Response::class);
return $response->headers;
}

#[LazyLoad]
public function loadDatabase():Database {
$dbSettings = new Settings(
Expand Down
43 changes: 43 additions & 0 deletions src/Middleware/ErrorRequestHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace Gt\WebEngine\Middleware;

use Gt\Config\Config;
use Gt\Dom\HTMLDocument;
use Gt\DomTemplate\DocumentBinder;
use Gt\Http\ResponseStatusException\ClientError\ClientErrorException;
use Gt\Http\ResponseStatusException\ResponseStatusException;
use Gt\Http\Uri;
use Gt\ServiceContainer\Container;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;

class ErrorRequestHandler extends RequestHandler {
public function __construct(
Config $config,
callable $finishCallback,
callable $obCallback,
private Throwable $throwable,
protected Container $serviceContainer,
) {
parent::__construct($config, $finishCallback, $obCallback);
}

public function handle(
ServerRequestInterface $request
):ResponseInterface {
$errorCode = 500;
/** @noinspection PhpConditionAlreadyCheckedInspection */
if($this->throwable instanceof ResponseStatusException
|| $this->throwable instanceof ClientErrorException) {
$errorCode = $this->throwable->getHttpCode();
}

$errorUri = new Uri("/_error/$errorCode/");
$errorRequest = $request->withUri($errorUri);

$this->completeRequestHandling($errorRequest, $this->serviceContainer);
$this->response = $this->response->withStatus($errorCode);
return $this->response;
}
}
Loading