Skip to content

Commit

Permalink
update the template with the new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Maometos committed Nov 30, 2023
1 parent b58e62b commit 081433c
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 80 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
.idea/
.vscode/
/vendor/
vendor/
composer.lock
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
37 changes: 0 additions & 37 deletions Program.php

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 19 additions & 21 deletions bin/apphost
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions devnet.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<Project>
<Properties>
<StartupObject>Application\Program</StartupObject>
</Properties>
<Items>
<CodeFile include="vendor/autoload.php"/>
</Items>
</Project>
10 changes: 0 additions & 10 deletions project.phproj

This file was deleted.

14 changes: 9 additions & 5 deletions settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"database": {
"connection": "//username:[email protected]/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"
}
}
28 changes: 28 additions & 0 deletions src/Program.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Application;

use DevNet\Web\Extensions\ApplicationBuilderExtensions;
use DevNet\Web\Extensions\ServiceCollectionExtensions;
use DevNet\Web\Hosting\WebHost;

class Program
{
public static function main(array $args = [])
{
$builder = WebHost::createDefaultBuilder($args);
$builder->register(function ($services) {
// Services
});

$host = $builder->build();
$host->start(function ($app) {
// Middlewares
$app->useRouter();
$app->useEndpoint(function ($routes) {
// Routes
$routes->mapGet("/", fn () => "Hello World!");
});
});
}
}

0 comments on commit 081433c

Please sign in to comment.