Skip to content

Commit 97c74f6

Browse files
committed
add console template
1 parent 8a4c442 commit 97c74f6

File tree

8 files changed

+108
-0
lines changed

8 files changed

+108
-0
lines changed

template/.gitignore

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

template/Program.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Application;
4+
5+
use DevNet\System\IO\Console;
6+
7+
class Program
8+
{
9+
public static function main(array $args = [])
10+
{
11+
Console::writeline("Hello World!");
12+
}
13+
}

template/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# DevNet Console Template
2+
This package is a Console application template of DevNet Framewark.
3+
4+
## 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/)
7+
8+
## Installation
9+
To create a DevNet Console Application project using composer, run the following command in your terminal:
10+
```
11+
composer create-project devnet/console-template [project-name]
12+
```
13+
Or using DevNet CLI
14+
```
15+
devnet new console --project [project-name]
16+
```
17+
18+
## Execution
19+
To run the application, navigate to the root of your project and run the following command in the Terminal:
20+
```
21+
./bin/run
22+
```
23+
Or using DevNet CLI
24+
```
25+
devnet run
26+
```
27+
28+
## Documentation
29+
Full documentation on how to use **DevNet Framework** is available at [devnet-framework.github.io](https://devnet-framework.github.io)

template/bin/apphost

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use DevNet\System\Runtime\Launcher;
4+
5+
$projectFile = simplexml_load_file(__DIR__ . "/../project.phproj");
6+
$namespace = $projectFile->properties->namespace;
7+
$entrypoint = $projectFile->properties->entrypoint;
8+
$packages = $projectFile->dependencies->package ?? [];
9+
10+
if (PHP_OS_FAMILY == 'Windows') {
11+
$path = getenv('path');
12+
$paths = explode(';', $path);
13+
} else {
14+
$path = getenv('PATH');
15+
$paths = explode(':', $path);
16+
}
17+
18+
foreach ($paths as $path) {
19+
if (file_exists($path . '/../autoload.php')) {
20+
require $path . '/../autoload.php';
21+
break;
22+
}
23+
}
24+
25+
foreach ($packages as $package) {
26+
$include = (string)$package->attributes()->include;
27+
if (file_exists(__DIR__ . '/../' . $include)) {
28+
require __DIR__ . '/../' . $include;
29+
}
30+
}
31+
32+
$launcher = Launcher::getLauncher();
33+
$launcher->workspace(dirname(__DIR__));
34+
$launcher->namespace((string)$namespace);
35+
$launcher->entryPoint((string)$entrypoint);
36+
$launcher->launch();

template/bin/run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require 'apphost';

template/bin/run.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@ECHO OFF
2+
setlocal DISABLEDELAYEDEXPANSION
3+
SET BIN_TARGET=%~dpn0
4+
php "%BIN_TARGET%" %*

template/composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "devnet/console-project",
3+
"description": "Console Application",
4+
"type": "project",
5+
"license": "MIT",
6+
"minimum-stability": "dev",
7+
"prefer-stable": true
8+
}

template/project.phproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<project>
3+
<properties>
4+
<namespace>Application</namespace>
5+
<entrypoint>Program</entrypoint>
6+
</properties>
7+
<dependencies>
8+
<package include="/vendor/autoload.php"/>
9+
</dependencies>
10+
</project>

0 commit comments

Comments
 (0)