temmyscope / sevenphp

High Speed Php MicroService Framework For Code Engineers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SevenPHP

About AltVel/SevenPHP

- AltVel (a.k.a SevenPHP) is developed by Elisha Temiloluwa a.k.a TemmyScope	

- Inspired By Phalcon & Laravel Php Web Application Frameworks.

***AltVel is a web application framework with priority on security, performance and standard-compliance (Im that order). We believe development must be enjoyable, flexible and creative; hence we take the "routines" out of web application development for php developers (code Engineers).


- Install using composer
composer require altvel/altvel
=> Recommended: Create Project automatically using composer
coomposer create-project altvel/altvel
- You can also download through github; This would involve a lot of manual configuration  

Built majorly with the Seven Library & Packages as a microservice restful framework with the intent to make it easily re-workable for any project (including SwoolePHP). The major focus for the development of the framework is to make most microservice development task as easy as possible while highly performant.

WorkSpace

All code you'd both write and edit are all in the root's app folder. Configuration settings and keys are kept in the config/app.php file and are all accessible using the app helper

#For example to get your app's url, you can do the following:
app()->get('APP_URL')

Creating Migrations

This section shows you how to :-

*create database,
*migrate, 
*populate, 
*drop 
table(s) using the name

Database Creation

Database can be created using the terminal, for example, to create a database called music, use:

	php Engineer app::db music

Migrations can be added to the App\Providers\MigrationEngine migrate method in the form:

###
return [
	//table ids are automatically generated as primary keys
	'apps' => [
		//the referenced table must already exist and the name must be exact to avoid errors
		'token' => $this->foreign_key($table='sessions_table', $column='session' $type = 'int' || 'string'),
		//$key can be one of [ 'primary', 'unique','fulltext', '' ]
		'name' => $this->string($max_length=125, $null=true),
		'pos' => $this->integer($max_length=10),
		//in other to specify a maximum length, float should be used instead of a double
		'account_balance' => $this->double() || $this->float($max_length=16), 
		'is_verified' => $this->oneOf($options=["'true'", "'false'"], $default="'false'" ),
		'created_at' => $this->datetime()
	],
	//constraints: a table can only have one primary key and it will be autogenerated
	'users' => [
		'name' => $this->string($max_length=125, $null=false),
		'email' => $this->string($max_length=125, $null=false, $key='unique'),
		'password' => $this->string($max_length=125),
		'backup_pass' => $this->string($max_length=150),
		'activation' => $this->string($max_length=225),
		'verified' => $this->oneOf($options=["'true'", "'false'"], $default="'false'" ),
		'created_at' => $this->datetime(),
		'deleted' => $this->oneOf($options=["'true'", "'false'"], $default="'false'" )
	],
	
	'user_sessions' => [
		'user_id' => $this->foreign_key($table='users', $column='id', $type = 'int' ),
		'session' => $this->string($max_length=225, $null=false),
		'user_agent' => $this->string($max_length=225, $null=false),
		'push_token' => $this->string($max_length=225, $null=false),
		'created_at' => $this->datetime(),
		'deleted' => $this->oneOf($options=["'true'", "'false'"], $default="'false'" )
	],
];
//constraints: a table can only have one primary key and it will be autogenerated
### id is auto-generated and would be ignored

Populating a table with data manually by the developer can be done by adding array of arrays to the App\Providers\MigrationEngine populate method's return array

return [
	'table name' => [ 'column name' => 'value' , 'column name' => 'value' , 'column name' => 'value' ],
	'table name' => [...],
];
#always remove the arrays after migration

Dropping table(s) can be done by adding table names to the App\Providers\MigrationEngine drop method's return array

return [ 'user', 'user_sessions' ]; //drop tables

Migration Generation Steps

=> After creating migrations

=> Add Name of tables to be migrated to the MIGRATION array in the configuration app.php file in the config folder

'MIGRATION' => [
	'users', 'user_session', 'contact_us'
]
#Always remember to remove already migrated models from the array

=>then run "php Engineer app::migrate" in the terminal

AltVel takes the pain out of development by easing common tasks used in many web projects, such as:

Simple, efficient & fast routing Engines

ModelTrait for database data retrieval built on Doctrine's dbal package

Supports all PHP PDO supported database types

Improved Model class for eloquent data retrieval[method chaining]

Engineer Console: [ To see all commands: php Engineer]

Automatically generate keys for secured session, cookie and salt

The following conventions are used:

=> All view files must reside in a folder within the view folder within the public folder with respect to the view they display.

Generate using the commandline:

To generate a home view folder and initialize an index blade file...

 php Engineer app::view home

To generate a specific file in an existing view folder: For example creating edit blade file in profile folder

 php Engineer app::view profile edit
=> The only file exempted is the app.blade.php which is the default view file for rendering.

=> All classes that extend the Model class, should be placed directly under the app folder.

AltVel is accessible, flexible, editable, powerful, and provides tools required for large, robust applications.

Learning AltVel

AltVel has no syntax of its own but uses the inherited php syntax, making it extremely easy for an average php developer to make use of.

AltVel How-To

The HTML template builder Helper class does not eliminate the need for a frontend designer:

=> Several helper methods are available for use.

=> Generates csrf token for each page to improve security against cross-site request forgery

=> Generates CSRF-secured Form using  Array construct passed to generateForm static method

Database Creation, Migrations & Populations

This section shows you how to :-

create database, migrate & populate table(s) using the name

Database Creation

=> Database can be created using the terminal, for example, to create a database called music, use:
	php Engineer app::db music

Population

You can check the link below to see how to populate a table using the console

Read Seven Consoler (Altvel-Only Use) Documentation.

To run Migrations

php Engineer app::populate

Creating & Running Migration & Population

Check Link to see how to create table migrations in Migration.php file

Read Seven Consoler (Altvel-Only Use) Documentation.

To run Migrations

php Engineer app::migrate

Connecting to a Database & Using Models

Models generated by Altvel Engineer are connected to this Library

Read Seven Model ORM Documentation.

AltVel Helpers: Global $app object, methods & functions

- App specific objects
$app->url(): #returns the APP_URL set in tee app.php config or .env file


$app->dateTime(); #returns the current time based on the application Time Zone


$app->encrypt(string $str); #encrypts passed string


$app->decrypt(string $str); # decrypts the passed encrypted string


$app->config()->get(string $str); #returns a data entry from the app.php config file


/**
* @example $arr1 = [
*           'function'=> 'strpos',
*           'parameters'=> ['home.php', '.']
*   ]; 
*   
* @example $arr2 = [
*           'function'=> 'strstr',
*           'parameters'=> ['home.php', '.']
*   ];
* $app->compareSpeed($arr1, $arr2);
*/
$app->compareSpeed(...$args);
- Request Object, Methods & Properties: $app->request() ... It is injected into every callable action for each endpoint
$request = $app->request();
  
$request->input(string $name): #To access all end user requests whether from form requests or json api calls

$request->has(string $name): #To access if an input is present; returns True OR False

$request->validate(array $rules); #provides an object of the Seven\Vars\Validation class, preloaded with the request body

$request->all(); #returns all inputs data as an associative array

$request->userAgent(); #returns processed user agent information if availale; returns an empty string if not available

$request->htmlSanitize(string $input); #returns html entities sanitizeed data
- Response Object, methods & Properties: $app->response() ... It is injected into every callable action for each endpoint
$response = $app->response();

$response->send(string | array $resp, int $code = 200, $headers = []);

$response->sendAndCache(string | array $response, int $code = 200, $timeInSeconds);

Preparing yo

Preparing your altvel application for deployment simply removes all files not loaded
by the PHP Server or Application in deployment.

Note: Make sure to keep a development backup.

php Engineer app::production

AltVel Sponsors

If you are interested in becoming a sponsor, please visit the AltVel Patreon page.

Contributing

Improve the code as much as possible; keeping syntax-flebility (ability to use plain php), security, standard-compliance and performance in mind. All Efforts will be appreciated. Ensure to add your name to the comment section on the index.php page.

Security Vulnerabilities

If you discover a security vulnerability within AltVel, please send an e-mail to TemmyScope via [temmyscope@protonmail.com] All security vulnerabilities will be promptly addressed.

License

The AltVel framework is an open-source software.

Todos

Readme.md, Console helper, unit testing and intrinsic application configurations, such as logging, other helpers, structuring are still being improved.

Development & Library Integration

integrations are done to fit a minimal, lightweight and performant production version. Hence libraries that are not required for production are not added to the framework using composer, rather they are built into the Application, so they are only autoloaded when called. A loose and less-overwhelming feel is kept on the number of folders and files. Due to the PHP-8 feature for preloading, any simple library not necessary for development would not be added/required to reduce the memory effect of preloading autoloaded files.

About

High Speed Php MicroService Framework For Code Engineers


Languages

Language:PHP 100.0%