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 078ca81 commit b19d748
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 40 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
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// 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 DevNet Application",
"type": "php",
"request": "launch",
"cwd": "${workspaceRoot}/bin/",
"runtimeArgs": [
"-dxdebug.start_with_request=yes",
"apphost"
],
"env": {
"XDEBUG_MODE": "debug,develop"
}
}
]
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# DevNet Console Template
This package is a Console application template of DevNet Framewark.
This package is a Console application template of DevNet Framework.

## 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 Console Application 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/console-template",
"description": "DevNet Console Application",
"type": "devnet-project",
"description": "Console 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.

2 changes: 1 addition & 1 deletion Program.php → src/Program.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class Program
{
public static function main(array $args = [])
{
Console::writeline("Hello World!");
Console::writeLine("Hello World!");
}
}

0 comments on commit b19d748

Please sign in to comment.