From 081433c99d4261b6436049c6d4c1277feef8c805 Mon Sep 17 00:00:00 2001
From: Mohammed Moussaoui <42718534+Artister@users.noreply.github.com>
Date: Thu, 30 Nov 2023 18:17:33 -0500
Subject: [PATCH] update the template with the new structure
---
.gitignore | 4 +---
.vscode/launch.json | 28 ++++++++++++++++++++++++++++
Program.php | 37 -------------------------------------
README.md | 4 ++--
bin/apphost | 40 +++++++++++++++++++---------------------
composer.json | 4 ++--
devnet.proj | 9 +++++++++
project.phproj | 10 ----------
settings.json | 14 +++++++++-----
src/Program.php | 28 ++++++++++++++++++++++++++++
10 files changed, 98 insertions(+), 80 deletions(-)
create mode 100644 .vscode/launch.json
delete mode 100644 Program.php
create mode 100644 devnet.proj
delete mode 100644 project.phproj
create mode 100644 src/Program.php
diff --git a/.gitignore b/.gitignore
index 24f8843..d1502b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,2 @@
-.idea/
-.vscode/
-/vendor/
+vendor/
composer.lock
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..839cddc
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,28 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Launch Built-in web server",
+ "type": "php",
+ "request": "launch",
+ "cwd": "${workspaceRoot}/webroot",
+ "runtimeArgs": [
+ "-dxdebug.mode=debug",
+ "-dxdebug.start_with_request=yes",
+ "-S",
+ "localhost:8000"
+ ],
+ "serverReadyAction": {
+ "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
+ "uriFormat": "http://localhost:%s",
+ "action": "openExternally"
+ },
+ "env": {
+ "DEVNET_ENVIRONMENT": "development"
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Program.php b/Program.php
deleted file mode 100644
index cbcc8e4..0000000
--- a/Program.php
+++ /dev/null
@@ -1,37 +0,0 @@
-ConfigBuilder->build();
-
- $builder->configureServices(function ($services) {
- // services
- });
-
- $host = $builder->build();
-
- $host->start(function ($app) use ($configuration) {
- if ($configuration->getValue('environment') == 'development') {
- $app->UseExceptionHandler();
- } else {
- $app->UseExceptionHandler("/home/error");
- }
-
- $app->useRouter();
- // middlewares
- $app->useEndpoint(function ($routes) {
- $routes->mapGet("/", fn (HttpContext $context) => $context->Response->writeAsync("Hello World!"));
- });
- });
- }
-}
diff --git a/README.md b/README.md
index d5867c3..e8f9b7d 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,8 @@
This package is a minimal web API template of DevNet Framework, which is suitable for building microservices.
## Requirements
-- PHP 7.4 or higher version from [php.net](https://www.php.net/)
-- Composer the dependency manager from [getcomposer.org](https://getcomposer.org/)
+- [PHP](https://www.php.net/) version 8.1 or higher
+- [Composer](https://getcomposer.org/) version 2.0 or higher
## Installation
To create a DevNet minimal Web API project using composer, run the following command in your terminal:
diff --git a/bin/apphost b/bin/apphost
index 3ce81d7..39da7e6 100644
--- a/bin/apphost
+++ b/bin/apphost
@@ -2,35 +2,33 @@
use DevNet\System\Runtime\Launcher;
-$projectFile = simplexml_load_file(__DIR__ . "/../project.phproj");
-$namespace = $projectFile->properties->namespace;
-$entrypoint = $projectFile->properties->entrypoint;
-$packages = $projectFile->dependencies->package ?? [];
+$root = dirname(__FILE__, 2);
+// Loads local devnet core host if exist
+if (is_file($root . '/vendor/devnet/core/host/corehost.php')) {
+ require $root . '/vendor/devnet/core/host/corehost.php';
+}
+
+// Gets the path environment variable
if (PHP_OS_FAMILY == 'Windows') {
- $path = getenv('path');
- $paths = explode(';', $path);
+ $paths = explode(';', getenv('path'));
} else {
- $path = getenv('PATH');
- $paths = explode(':', $path);
+ $paths = explode(':', getenv('PATH'));
}
+// Search for the global devnet core host
foreach ($paths as $path) {
- if (file_exists($path . '/../autoload.php')) {
- require $path . '/../autoload.php';
+ if (is_file($path . '/../devnet/core/host/corehost.php')) {
+ require $path . '/../devnet/core/host/corehost.php';
break;
}
}
-foreach ($packages as $package) {
- $include = (string)$package->attributes()->include;
- if (file_exists(__DIR__ . '/../' . $include)) {
- require __DIR__ . '/../' . $include;
- }
-}
-$launcher = Launcher::getLauncher();
-$launcher->workspace(dirname(__DIR__));
-$launcher->namespace((string)$namespace);
-$launcher->entryPoint((string)$entrypoint);
-$launcher->launch();
+// Gets the console arguments without command name
+$args = $GLOBALS['argv'] ?? [];
+array_shift($args);
+
+// Initialize and launch the application
+$launcher = Launcher::initialize($root . '/devnet.proj');
+$launcher->launch($args);
diff --git a/composer.json b/composer.json
index d53f8fb..344024e 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "devnet/web-template",
- "description": "DevNet Web Application (Minimal APIs)",
- "type": "devnet-project",
+ "description": "Web Application",
+ "type": "project",
"license": "MIT",
"minimum-stability": "dev",
"prefer-stable": true
diff --git a/devnet.proj b/devnet.proj
new file mode 100644
index 0000000..8ba44fc
--- /dev/null
+++ b/devnet.proj
@@ -0,0 +1,9 @@
+
+
+
+ Application\Program
+
+
+
+
+
\ No newline at end of file
diff --git a/project.phproj b/project.phproj
deleted file mode 100644
index f99ad75..0000000
--- a/project.phproj
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
- Application
- Program
-
-
-
-
-
diff --git a/settings.json b/settings.json
index 29ac207..18cfe33 100644
--- a/settings.json
+++ b/settings.json
@@ -1,7 +1,11 @@
{
- "database": {
- "connection": "//username:password@127.0.0.1/database",
- "charset": "utf-8"
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information"
+ }
},
- "environment" : "production"
-}
+ "Database": {
+ "ProviderType": "DevNet\\Entity\\PgSql\\PgSqlDataProvider",
+ "ConnectionString": "host=localhost;database=dbname;user=username;password=password"
+ }
+}
\ No newline at end of file
diff --git a/src/Program.php b/src/Program.php
new file mode 100644
index 0000000..581ca8a
--- /dev/null
+++ b/src/Program.php
@@ -0,0 +1,28 @@
+register(function ($services) {
+ // Services
+ });
+
+ $host = $builder->build();
+ $host->start(function ($app) {
+ // Middlewares
+ $app->useRouter();
+ $app->useEndpoint(function ($routes) {
+ // Routes
+ $routes->mapGet("/", fn () => "Hello World!");
+ });
+ });
+ }
+}