mafuth/php-cli

About simple command line interface and framework for PHP focuesed on light weight and simplicity

3.2 2022-09-17 08:11 UTC

This package is auto-updated.

Last update: 2024-04-29 05:06:04 UTC


README

Contributors Forks Stargazers Issues


68747470733a2f2f646576656c6f7065722e6665646f726170726f6a6563742e6f72672f7374617469632f6c6f676f2f636c692d6170702e706e67

php-CLI

This project requires PHP as an executable command

Installation

  1. Create a project
    composer create-project mafuth/php-cli:dev-main test
  2. Check for installation
    php cli --v
  3. Configure the installation
    php cli --config
  4. test connection to database
    php cli test data-base-connection
  5. Start a local server
    php cli --serve

ajax folder

This is where cli generates ajax request files

comands folder

This is where cli generates all you run command files

database folder

inside database/create is all the cli generates database table controllers

handlers folder

This is where cli generates handle files

views folder

This is where you put you php code files that generate views on the front end

index and main files

Please do not edit these files as these are important components

requests file

This file handles all the requests to the server, edit this file as needed

To disable minification change request file compiler like shown below

echo $COMPILER->output($PAGE,false);

If you want to use blade templating engine you can check documentation of BladeOne

config.ini file

This is the main config file of the server

[app configs]
appname = "Your App Name"
port = "8080" #Your app port default to 8080

[database configs]
servername = "Your database server here"
username = "server username"
password = "server password"
dbname = "database name"

[Mail server]
mailServer = "Your mailserver here"
mailUsername = "server username"
mailPassword = "servr password"
mailport = "server port"

[encryption keys]
KEY_ONE = "encryption key 1"
KEY_TWO = "encryption key 2"

[maintanance mode]
maintanance = false # true or false

[error reporting]
error = false # true or false

[auto ssl]
autossl = false # true or false (true will force ssl on every request)

Usage

git commands

  1. Configure git
git config --global user.name "Full Name as on github"
git config --global user.email "Email as on github"

On the next step press Enter to choose the default value

ssh-keygen -t rsa -C "Email as on github"

windows

notepad ~/.ssh/id_rsa.pub

mac & linux

cat ~/.ssh/id_rsa.pub

Now go to https://github.com/settings/keys and add the key you just generated / opened on note pad , save the ssh keys

  1. Test git
ssh -T git@github.com

If you see a message like 'Hi user! You've successfully authenticated, but GitHub does not provide shell access.' then everything is okay

php cli --git

create command

Create a database table (replace '-- your table name --' with any name of your choice)

php cli create table -- your table name --

Create a handler for post request (replace '-- your handler name --' with any name of your choice)

php cli create handler -- your handler name --

Create a ajax request handler for all xml requests (replace '-- your handler name --' with any name of your choice)

php cli create ajax -- your handler name --

Create a new run command (replace '-- your command name --' with any name of your choice)

php cli create run-command -- your command name --

Data base tables command

Drop all tables and delete create function files

php cli drop-tables

or use

php cli drop-table -- your table name --

if want edit a table layout just edit the table lay out file at (database/create) directory and run the command below

php cli recreate-tables

or use

php cli recreate-table -- your table name --

run command

This command is used to run scripts created using (php cli create run-command -- your command name -- )

php cli run -- your command name --

building Database queries ( reffer to 'classes/db.class.php' )

select from

$DB->selectFrom($table);
$data = $DB->execute(); // this will return an array of all data selected;

select from where

$DB->selectFrom($table);
$DB->where(array(
  'id'=>1,
  'name'=>array(
      'john',
      'doe'
  )
));
$data = $DB->execute(); // this will return an array of all data selected;

delete from

$DB->deleteFrom($table);
$DB->where(array(
  'id'=>1,
  'name'=>array(
      'john',
      'doe'
  )
));
$data = $DB->execute(); // this will return true if successful and false if failed
$error = $data['message]; // this has the error message

update from

$DB->updateFrom($table);
$DB->set(array(
  'name'=>'john'
));
$DB->where(array(
  'id'=>1
));
$data = $DB->execute(); // this will return true if successful and false if failed
$error = $data['message]; // this has the error message

insert to

$DB->insert(array(
  'john'
));
$DB->to($table);
$data = $DB->execute(); // this will return true if successful and false if failed
$error = $data['message]; // this has the error message

$DB->insertTo($table,array(
  'name'=>'john'
));
$data = $DB->execute(); // this will return true if successful and false if failed
$error = $data['message]; // this has the error message

PWA command

This command is used generate PWA code for ur website this command requires node js and pwa asset generator by onderceylan
PWA also supports onesignal SDK which is also included in php-CLI

php cli pwa-code

Composer commands

Install new composer packeges (replace '-- package name --' with any composer package of your choice)

php cli install -- package name --

Ftp deploy from github

Setup github workflow to easily deploy your websites to your servers using ftp or sftp

php cli --git make ftp deploy
php cli --git make sftp deploy

Docker

Setup a full docker enviroment for development

php cli make docker container

Database Backup

Backup your database

php cli db backup

restore your database from backup

php cli db restore

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!