Skip to content

Commit e519c94

Browse files
committed
added sample command, and post composer commands
1 parent c8695e0 commit e519c94

File tree

6 files changed

+51
-10
lines changed

6 files changed

+51
-10
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ This skeleton will come with 2 versions of a starter application. The robust ver
2222

2323
The robust version adds an `app/` directory where everything has a basic structure. This is how this skeleton is configured by default.
2424

25-
One additional thing you'll need to do is copy the `app/config/config_sample.php` file to `app/config/config.php` and update the values to be correct for your environment.
26-
2725
### Simple Setup of the Application
2826

2927
This is basically a single file application. The only exception to this is the config file which is still in the `app/config/` directory. This is a good starting point for smaller projects or projects that you don't anticipate will grow much.
3028

31-
To use the simple version, you'll need to copy the `app/config/config_sample.php` file to `app/config/config.php`. Then you'll need to move the `index-simple.php` file to the `public/` directory and rename it to `index.php`. You can delete any other controllers, views, or config files (except the `config.php` file of course).
29+
To use the simple version, you'll need to move the `index-simple.php` file to the `public/` directory and rename it to `index.php`. You can delete any other controllers, views, or config files (except the `config.php` file of course).
3230

3331
With the simple setup, there is two very import security steps to be aware of.
3432
- **DO NOT SAVE SENSITIVE CREDENTIALS TO THE `index.php` FILE**.

app/cache/.keep

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace flight\commands;
6+
7+
use flight\database\PdoWrapper;
8+
9+
class SampleDatabaseCommand extends AbstractBaseCommand
10+
{
11+
/**
12+
* Construct
13+
*
14+
* @param array<string,mixed> $config JSON config from .runway-config.json
15+
*/
16+
public function __construct(array $config)
17+
{
18+
parent::__construct('init:sample-db', 'Creates a sample SQLite database and tables.', $config);
19+
}
20+
21+
/**
22+
* Executes the function
23+
*
24+
* @return void
25+
*/
26+
public function execute()
27+
{
28+
$io = $this->app()->io();
29+
30+
$PdoWrapper = new PdoWrapper('sqlite:'. __DIR__ . '/../database.sqlite');
31+
32+
$io->info('Creating tables...');
33+
$PdoWrapper->exec('CREATE TABLE IF NOT EXISTS posts (id INTEGER PRIMARY KEY, title TEXT, content TEXT, username TEXT, created_at TEXT, updated_at TEXT)');
34+
$PdoWrapper->exec('CREATE TABLE IF NOT EXISTS comments (id INTEGER PRIMARY KEY, post_id INTEGER, username TEXT, content TEXT, created_at TEXT, updated_at TEXT)');
35+
$io->ok('Tables created!', true);
36+
}
37+
}

app/config/config_sample.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919
setlocale(LC_ALL, 'en_US.UTF-8');
2020
}
2121

22-
/*
23-
* Set some flight variables
24-
*/
22+
// Get the $app var to use below
2523
if(empty($app)) {
2624
$app = Flight::app();
2725
}
26+
2827
// if you want to load classes that have underscores in them, comment out the following line
2928
// Loader::setV2ClassLoading(false);
29+
30+
// This autoloads your code in the app directory so you don't have to require_once everything
3031
$app->path(__DIR__ . $ds . '..' . $ds . '..');
32+
33+
// This is where you can set some flight config variables.
3134
$app->set('flight.base_url', '/'); // if this is in a subdirectory, you'll need to change this
3235
$app->set('flight.case_sensitive', false); // if you want case sensitive routes, set this to true
3336
$app->set('flight.log_errors', true); // if you want to log errors, set this to true
@@ -36,9 +39,6 @@
3639
$app->set('flight.views.extension', '.php'); // set the file extension for your view/template/ui files
3740
$app->set('flight.content_length', true); // if flight should send a content length header
3841

39-
// This breaks the browser cache headers so requests don't get cached. This is good in a dynamic application
40-
$app->response()->header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0');
41-
4242
/*
4343
* Get Tracy up and running
4444
*

app/log/.keep

Whitespace-only changes.

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@
3434
},
3535
"scripts": {
3636
"start": "php -S localhost:8000 -t public",
37-
"post-create-project-cmd": "@php -r \"symlink('vendor/bin/runway', 'runway');\""
37+
"post-create-project-cmd": [
38+
"@php -r \"symlink('vendor/bin/runway', 'runway');\"",
39+
"@php -r \"copy('app/config/config_sample.php', 'app/config/config.php');\"",
40+
"@php -r \"mkdir('app/middlewares/');\"",
41+
"@php -r \"mkdir('app/cache/');\"",
42+
"@php -r \"mkdir('app/log/');\""
43+
]
3844
},
3945
"require-dev": {
4046
"flightphp/tracy-extensions": "^0.1"

0 commit comments

Comments
 (0)