Skip to content

Commit

Permalink
feat(Commands): add commands
Browse files Browse the repository at this point in the history
  • Loading branch information
markhughes committed Nov 21, 2024
1 parent 7179a79 commit 8364648
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .runway-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"index_root": "public/index.php",
"app_root": "src/Acme/Demo/",
"root_paths": ["."]
}
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This skeleton provides a quick start for the development of an application with the [Flight](http://flightphp.com) PHP microframework. The
goal here is to get going as fast as possible.

It also adds support for Sass, Twig, and even TypeScript (it also includes Volta for npm version managing)!
It also adds support for Runway (CLI), Sass, Twig, and even TypeScript (it also includes Volta for npm version managing)!

## Downloading the skeleton

Expand All @@ -24,14 +24,14 @@ To define your routes, use the file `app/config/routes.php`:
```php
<?php

Flight::route("/", ["\Acme\Demo\Controller\Demo", "index"]);
Flight::route("/", ["\Acme\Demo\Controllers\Demo", "index"]);
```

An example API router has been created in `src/Acme/Demo/Controller/API.php` where `Flight::json` is used to send the response back.
An example API router has been created in `src/Acme/Demo/Controllers/API.php` where `Flight::json` is used to send the response back.

### Controllers

Place your code in the `src` folder. All classes from here are autoloaded by their namespace. For an example, have a look in the demo code in `src/Acme/demo/Controller/Demo.php`. As you can see, the controller uses the namespace `Acme\Demo\Controller`.
Place your code in the `src` folder. All classes from here are autoloaded by their namespace. For an example, have a look in the demo code in `src/Acme/demo/Controllers/Demo.php`. As you can see, the controller uses the namespace `Acme\Demo\Controllers`.

### Templates

Expand All @@ -54,7 +54,23 @@ Compile your scripts using `npm run build` which will throw it all together in `

You can also run `npm run dev` to start webpack in watch mode, great for development.

### Commands

Using Runway you can add commands into the application.

```
./runway example:example-command
```

Will execute the command in src/Acme/Demo/Comands/ExampleCommand.php

Runway has a few strict restrictions for commands:

1. They must be in a directory called "commands"
2. The file name must end in Command.php

## Volta

This project uses [Volta](https://volta.sh/) to manage the node and npm version, it is optional to setup but it is a great tool to manage your JavaScript toolchain.

# License
Expand Down
4 changes: 2 additions & 2 deletions app/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// ROUTES
// -------------------------------------------------- //

Flight::route("/", ["\Acme\Demo\Controller\Demo", "index"]);
Flight::route("/api/message", ["\Acme\Demo\Controller\API", "message"]);
Flight::route("/", ["\Acme\Demo\Controllers\Demo", "index"]);
Flight::route("/api/message", ["\Acme\Demo\Controllers\API", "message"]);

// -------------------------------------------------- //
// MAPPINGS
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
],
"require": {
"php": ">=8.0",
"mikecao/flight": "~2.0",
"monolog/monolog": "^3.2.0",
"twig/twig": "~3.0"
"mikecao/flight": "~3.12",
"monolog/monolog": "^3.7.0",
"twig/twig": "~3.14",
"flightphp/runway": "^1.1"
},
"autoload": {
"psr-0": {
Expand Down
9 changes: 9 additions & 0 deletions runway
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env php
<?php

if (!file_exists("vendor/bin/runway")) {
echo("Runway not installed. Please run 'composer install' first.\n");
exit(1);
}

require_once("vendor/bin/runway");
File renamed without changes.
34 changes: 34 additions & 0 deletions src/Acme/Demo/Commands/ExampleCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace flight\commands;

class ExampleCommand extends AbstractBaseCommand
{
/**
* Construct
*
* @param array<string,mixed> $config JSON config from .runway-config.json
*/
public function __construct(array $config)
{
parent::__construct('example:example-command', 'This is a sample command.', $config);
}

/**
* Executes the function
*
* @return void
*/
public function execute()
{
$io = $this->app()->io();

$io->info('This is an example... ');

$io->info('remember to pass `true` in the $io functions to add a new line at the end of the message.', true);

// ... do something here ...

$io->ok('Example completed!', true);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Acme\Demo\Controller;
namespace Acme\Demo\Controllers;

use Flight;
use Flight\template\View;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Acme\Demo\Controller;
namespace Acme\Demo\Controllers;

use Flight;

Expand Down

0 comments on commit 8364648

Please sign in to comment.