Skip to content

Commit 081433c

Browse files
committed
update the template with the new structure
1 parent b58e62b commit 081433c

File tree

10 files changed

+98
-80
lines changed

10 files changed

+98
-80
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
.idea/
2-
.vscode/
3-
/vendor/
1+
vendor/
42
composer.lock

.vscode/launch.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch Built-in web server",
9+
"type": "php",
10+
"request": "launch",
11+
"cwd": "${workspaceRoot}/webroot",
12+
"runtimeArgs": [
13+
"-dxdebug.mode=debug",
14+
"-dxdebug.start_with_request=yes",
15+
"-S",
16+
"localhost:8000"
17+
],
18+
"serverReadyAction": {
19+
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
20+
"uriFormat": "http://localhost:%s",
21+
"action": "openExternally"
22+
},
23+
"env": {
24+
"DEVNET_ENVIRONMENT": "development"
25+
}
26+
}
27+
]
28+
}

Program.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
This package is a minimal web API template of DevNet Framework, which is suitable for building microservices.
33

44
## Requirements
5-
- PHP 7.4 or higher version from [php.net](https://www.php.net/)
6-
- Composer the dependency manager from [getcomposer.org](https://getcomposer.org/)
5+
- [PHP](https://www.php.net/) version 8.1 or higher
6+
- [Composer](https://getcomposer.org/) version 2.0 or higher
77

88
## Installation
99
To create a DevNet minimal Web API project using composer, run the following command in your terminal:

bin/apphost

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,33 @@
22

33
use DevNet\System\Runtime\Launcher;
44

5-
$projectFile = simplexml_load_file(__DIR__ . "/../project.phproj");
6-
$namespace = $projectFile->properties->namespace;
7-
$entrypoint = $projectFile->properties->entrypoint;
8-
$packages = $projectFile->dependencies->package ?? [];
5+
$root = dirname(__FILE__, 2);
96

7+
// Loads local devnet core host if exist
8+
if (is_file($root . '/vendor/devnet/core/host/corehost.php')) {
9+
require $root . '/vendor/devnet/core/host/corehost.php';
10+
}
11+
12+
// Gets the path environment variable
1013
if (PHP_OS_FAMILY == 'Windows') {
11-
$path = getenv('path');
12-
$paths = explode(';', $path);
14+
$paths = explode(';', getenv('path'));
1315
} else {
14-
$path = getenv('PATH');
15-
$paths = explode(':', $path);
16+
$paths = explode(':', getenv('PATH'));
1617
}
1718

19+
// Search for the global devnet core host
1820
foreach ($paths as $path) {
19-
if (file_exists($path . '/../autoload.php')) {
20-
require $path . '/../autoload.php';
21+
if (is_file($path . '/../devnet/core/host/corehost.php')) {
22+
require $path . '/../devnet/core/host/corehost.php';
2123
break;
2224
}
2325
}
2426

25-
foreach ($packages as $package) {
26-
$include = (string)$package->attributes()->include;
27-
if (file_exists(__DIR__ . '/../' . $include)) {
28-
require __DIR__ . '/../' . $include;
29-
}
30-
}
3127

32-
$launcher = Launcher::getLauncher();
33-
$launcher->workspace(dirname(__DIR__));
34-
$launcher->namespace((string)$namespace);
35-
$launcher->entryPoint((string)$entrypoint);
36-
$launcher->launch();
28+
// Gets the console arguments without command name
29+
$args = $GLOBALS['argv'] ?? [];
30+
array_shift($args);
31+
32+
// Initialize and launch the application
33+
$launcher = Launcher::initialize($root . '/devnet.proj');
34+
$launcher->launch($args);

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "devnet/web-template",
3-
"description": "DevNet Web Application (Minimal APIs)",
4-
"type": "devnet-project",
3+
"description": "Web Application",
4+
"type": "project",
55
"license": "MIT",
66
"minimum-stability": "dev",
77
"prefer-stable": true

devnet.proj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<Project>
3+
<Properties>
4+
<StartupObject>Application\Program</StartupObject>
5+
</Properties>
6+
<Items>
7+
<CodeFile include="vendor/autoload.php"/>
8+
</Items>
9+
</Project>

project.phproj

Lines changed: 0 additions & 10 deletions
This file was deleted.

settings.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2-
"database": {
3-
"connection": "//username:[email protected]/database",
4-
"charset": "utf-8"
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information"
5+
}
56
},
6-
"environment" : "production"
7-
}
7+
"Database": {
8+
"ProviderType": "DevNet\\Entity\\PgSql\\PgSqlDataProvider",
9+
"ConnectionString": "host=localhost;database=dbname;user=username;password=password"
10+
}
11+
}

src/Program.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Application;
4+
5+
use DevNet\Web\Extensions\ApplicationBuilderExtensions;
6+
use DevNet\Web\Extensions\ServiceCollectionExtensions;
7+
use DevNet\Web\Hosting\WebHost;
8+
9+
class Program
10+
{
11+
public static function main(array $args = [])
12+
{
13+
$builder = WebHost::createDefaultBuilder($args);
14+
$builder->register(function ($services) {
15+
// Services
16+
});
17+
18+
$host = $builder->build();
19+
$host->start(function ($app) {
20+
// Middlewares
21+
$app->useRouter();
22+
$app->useEndpoint(function ($routes) {
23+
// Routes
24+
$routes->mapGet("/", fn () => "Hello World!");
25+
});
26+
});
27+
}
28+
}

0 commit comments

Comments
 (0)