Skip to content

Commit

Permalink
added sample command, and post composer commands
Browse files Browse the repository at this point in the history
  • Loading branch information
n0nag0n committed Jun 29, 2024
1 parent c8695e0 commit e519c94
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ This skeleton will come with 2 versions of a starter application. The robust ver

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

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.

### Simple Setup of the Application

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.

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).
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).

With the simple setup, there is two very import security steps to be aware of.
- **DO NOT SAVE SENSITIVE CREDENTIALS TO THE `index.php` FILE**.
Expand Down
Empty file removed app/cache/.keep
Empty file.
37 changes: 37 additions & 0 deletions app/commands/SampleDatabaseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace flight\commands;

use flight\database\PdoWrapper;

class SampleDatabaseCommand extends AbstractBaseCommand
{
/**
* Construct
*
* @param array<string,mixed> $config JSON config from .runway-config.json
*/
public function __construct(array $config)
{
parent::__construct('init:sample-db', 'Creates a sample SQLite database and tables.', $config);
}

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

$PdoWrapper = new PdoWrapper('sqlite:'. __DIR__ . '/../database.sqlite');

$io->info('Creating tables...');
$PdoWrapper->exec('CREATE TABLE IF NOT EXISTS posts (id INTEGER PRIMARY KEY, title TEXT, content TEXT, username TEXT, created_at TEXT, updated_at TEXT)');
$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)');
$io->ok('Tables created!', true);
}
}
12 changes: 6 additions & 6 deletions app/config/config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
setlocale(LC_ALL, 'en_US.UTF-8');
}

/*
* Set some flight variables
*/
// Get the $app var to use below
if(empty($app)) {
$app = Flight::app();
}

// if you want to load classes that have underscores in them, comment out the following line
// Loader::setV2ClassLoading(false);

// This autoloads your code in the app directory so you don't have to require_once everything
$app->path(__DIR__ . $ds . '..' . $ds . '..');

// This is where you can set some flight config variables.
$app->set('flight.base_url', '/'); // if this is in a subdirectory, you'll need to change this
$app->set('flight.case_sensitive', false); // if you want case sensitive routes, set this to true
$app->set('flight.log_errors', true); // if you want to log errors, set this to true
Expand All @@ -36,9 +39,6 @@
$app->set('flight.views.extension', '.php'); // set the file extension for your view/template/ui files
$app->set('flight.content_length', true); // if flight should send a content length header

// This breaks the browser cache headers so requests don't get cached. This is good in a dynamic application
$app->response()->header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0');

/*
* Get Tracy up and running
*
Expand Down
Empty file removed app/log/.keep
Empty file.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
},
"scripts": {
"start": "php -S localhost:8000 -t public",
"post-create-project-cmd": "@php -r \"symlink('vendor/bin/runway', 'runway');\""
"post-create-project-cmd": [
"@php -r \"symlink('vendor/bin/runway', 'runway');\"",
"@php -r \"copy('app/config/config_sample.php', 'app/config/config.php');\"",
"@php -r \"mkdir('app/middlewares/');\"",
"@php -r \"mkdir('app/cache/');\"",
"@php -r \"mkdir('app/log/');\""
]
},
"require-dev": {
"flightphp/tracy-extensions": "^0.1"
Expand Down

0 comments on commit e519c94

Please sign in to comment.