chandan07cse / elham
Inspiring You The Next - A Product Of UROSD Lab
Installs: 155
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 3
Forks: 5
Open Issues: 0
Language:JavaScript
Type:project
Requires
- illuminate/database: ^5.2
- philo/laravel-blade: 3.*
- respect/validation: ^1.1
- robmorgan/phinx: ^0.6.3
- swiftmailer/swiftmailer: ^5.4
- symfony/class-loader: 3.1.*
- symfony/http-foundation: 3.1.*
- symfony/http-kernel: 3.1.*
- symfony/routing: 3.1.*
- vlucas/phpdotenv: ^2.3
Requires (Dev)
- fzaninotto/faker: ^1.6
- psy/psysh: @stable
This package is not auto-updated.
Last update: 2024-11-09 20:33:43 UTC
README
π’ Let's build together by not reinventing the wheel but assembling the wheels to reinvent a new π
π° Version 1.0.0
πΎ Installation
πΉ First install composer globally(if you don't have it) by running the following commands
For Ubuntu
curl -sS https://getcomposer.org/installer | php && sudo mv composer.phar /usr/local/bin/composer
For Cent OS
curl -sS https://getcomposer.org/installer | php && chmod +x composer.phar && sudo mv composer.phar /usr/local/bin/composer
πΉ Then install Elham by the following command(for latest stable releases)
composer create-project chandan07cse/elham YOUR_PROJECT_NAME
πΉ But if you want Elham from its master branch, then you could certainly type it
composer create-project chandan07cse/elham=dev-master YOUR_PROJECT_NAME
πΉ Now cd into your_project_name/public & run by the php command
cd YOUR_PROJECT_NAME/public
php -S localhost:8000
πΉ Note : For the rest of the project we'll run each & every command from the project directory. For that
cd ../
π¦ Dependencies
πΉ To check the list of dependencies Elham relies, run the command
composer info
π¦ Visual Dependencies
- To check the visual dependencies, please go to the link Visual Dependecies
πΉ Elham Command Alias
πΉ Let's run the below command to run elham command if you are in Linux
echo "alias elham='./elham'" >> ~/.bash_aliases && source ~/.bash_aliases
πΉ But if you are in windows machine add the executibles in your path. If you are using Laragon then it can be
C:\laragon\www\project_name\vendor\bin\;C:\laragon\www\project_name\;
πΉ Now you can run elham command through out your project. To check run from the terminal if you are in linux enviornment
elham
πΉ But if you are in windows, then
php elham
π» Build Controller Through CLI
πΉ Elham provides you the build:controller command
elham build:controller YourController
πΉ Check it by finding it in app/Controller directory of your project.
πΉ By default elham generates resourceful controller. But if you want you can always make a plain controller by running
elham build:controller YourController plain
πΈ Build Model Through CLI
πΉ Elham also provides you build:model command
elham build:model YourModel
πΉ It'll create a model with necessary properties & methods based on your database table.
π· Build Form Through CLI
πΉ Elham ships with build:form command
elham build:form YourForm
πΉ A dummy blade form will be generated inside app/Views/_partials directory.
πΌ Build Validator Through CLI
πΉ Elham also provides you build:validator command
elham build:validator YourValidator
πΉ A validation class will be generated inside app/Validation directory.
π€ Help keyword for CLI generators
πΉ Now if you need any help just type
elham help build:keyword
πΉ All the commands check the existing ones as well for simplicity.
π π Elham Templating Engines
πΉ Elham ships with Blade and Plain view for rendering its View. But if you want you can use twig too. For that you will need to install TWIG by the following command
composer require twig/twig
π΄ π± Elham Migrations & Seeding
πΉ As Elham used Phinx for migrations & seeding, so to use phinx command just run from the terminal
echo "alias phinx='./phinx'" >> ~/.bash_aliases && source ~/.bash_aliases
πΉ Now you'll be able to run phinx command. To make sure phinx running correctly, run in terminal
phinx
πΉ You'll get the list of Phinx command. To use phinx, first initialize it by the following command
phinx init
πΉ A phinx.yml file will be generated. You need to customize it. Sample customization for development listed below
environments:
default_database: development
development:
adapter: sqlite
host: localhost
name: db/database.sqlite
user: root
pass: ''
port: 3306
charset: utf8
πΉ Phinx uses π« CamelCase for its functioning & it'll store the migrations & seeding inside db/migration & db/seeds directory respectively. So if you wanna create a migration for Students table, just run in terminal
phinx create Students
πΉ A new unique migration for Students will be generated inside db/migrations directory of Elham like below
use Phinx\Migration\AbstractMigration; class Students extends AbstractMigration { public function change() { } }
πΉ Now we not gonna use the change method for the migration. Beside we'll create two methods up() & down() for our migration & rollback. So for that we gonna code a bit something like below. Say we've our student table consisting with roll & name.
use Phinx\Migration\AbstractMigration; class Students extends AbstractMigration { public function up() { $students = $this->table('students'); $students->addColumn('name','string',['length'=>100]) ->addColumn('roll','string') ->create(); } public function down() { $this->dropTable('students'); } }
πΉ Now to migrate, run from terminal
phinx migrate
πΉ It'll affect our default db/databse.sqlite hopefully. Now to rollback, just run from terminal
phinx rollback
πΉ To explore more about Phinx, please read the πdocumentation.
πΉ Now for seeding, we just need to create the seeder class from the cli. Say, we need to create a UserSeeder to seed some datumn into users table. To create the UserSeeder class
phinx seed:create UserSeeder
πΉ We'll get the UserSeeder class inside db/seeds directory. Inside there, we'll get
<?php use Phinx\Seed\AbstractSeed; class UserSeeder extends AbstractSeed { public function run() { } }
πΉ Actually we can seed in βοΈ ways.
1οΈβ£ Manual Seeding
2οΈβ£ Faker Seeding
πΉ For Manual Seeding we can write something like this in UserSeeder class
<?php use Phinx\Seed\AbstractSeed; class UserSeeder extends AbstractSeed { public function run() { $data = array( array( 'username' => 'chandan07cse', 'password' => md5('me'), 'email' => 'freak.arian@gmail.com', 'image' => 'public/images/chandan07cse.jpg', 'activation_code' => md5(rand(0,1000)), 'active' => 1 ), array( 'username' => 'mamun10pgd', 'password' => md5('mamun10pgd@!'), 'email' => 'rajmamunet@gmail.com', 'image' => 'public/images/mamun10pgd.jpg', 'activation_code' => md5(rand(0,1000)), 'active' => 0 ) ); $this->insert('users', $data); } }
πΉ Now run from terminal
phinx seed:run
πΉ If you wanna run a specific class then run
phinx seed:run -s UserSeeder
πΉ For faker seeding, we can write something like this in UserSeeder class
<?php use Phinx\Seed\AbstractSeed; class UserSeeder extends AbstractSeed { public function run() { $faker = Faker\Factory::create(); $data = []; for ($i = 0; $i < 4; $i++) { $data[] = [ 'username' => $faker->userName, 'password' => md5($faker->password), 'email' => $faker->email, 'image' => $faker->image($dir = 'public/images',$width = 640, $height = 480), 'activation_code'=> $faker->randomElement(), 'active' => $faker->boolean ]; } $this->insert('users', $data); } }
β½ππβΎπΎ Elham Playground
πΉ Elham also uses Psyshell for tinkering with its functionalities, so to use psysh command just run from the terminal
echo "alias psysh='./psysh'" >> ~/.bash_aliases && source ~/.bash_aliases
πΉ Now if you wanna tinkering with psyshell just run in terminal
psysh
πΉ You'll be into the Psyshell now. If you wanna start toying around then first initialize the proper environment. To init the environment, run in terminal
$environment = new Dotenv\Dotenv(__DIR__); $environment->load();
πΉ To init the database with eloquent, run in terminal
$db = new config\Database;
πΉ Now if you wanna query through Eloquent/Query Builder, create an instance of the Capsule
$db->eloquent();
πΉ Now if you wanna play with User model, create an object of User by running in terminal
$user = new Elham\Model\User;
πΉ To get all data from User model, just run in terminal
$user->all()->toArray();
πΉ And if you wanna query through PDO, create an instance of the PDO
$pdo = $db->pdo();
πΉ If you wanna insert some data into users table using pdo, do the following
$pdo = $pdo->prepare("insert into users values(:id,:username,:email,:password,:image,:activation_code,:active)"); $pdo->execute([':id'=>null,':username'=>'moin07cse',':password'=>'hjkkjhkjjk',':image'=>'moin.png',':activation_code'=>'dfsf',':active'=>0]); $pdo->fetchAll(PDO::FETCH_ASSOC);
πΉ You can run every bit of eloquent & pdo queries along with other functionalities through Psyshell.
π² Elham API Call
πΉ Elham uses Unirest libraries for its api calling. Its pretty easy to call an api using the Elham's api method like below
$uri = 'http://mockbin.com/request'; $content_type = 'application/json'; $request_parameter = ['foo' => 'hello', 'bar' => 'world']; $request_type = 'post'; $api_response = $this->api($uri,$content_type,$request_parameter,$request_type);
π Elham Vulnerability Scan
πΉ To check any vulnerable package issue in Elham, just run the following command
elham check:vulnerability
π‘ Elham Frontend Housekeeping
πΉ Elham uses Gulp for basic front-end housekeeping of tasks like minifying css,js, autoprefixing of css and so on & so forth. To use gulp, first install node js by the following command
sudo apt-get install npm
πΉ After that we need to install gulp globaly by the following command in ubuntu.
sudo npm install -g gulp
πΉ But if you are in windows then in Laragon terminal type
npm install -g gulp
πΉ As pacakge.json already ships with Elham. So you don't have to create it. To install gulp just run the following command
sudo npm install gulp --save-dev
πΉ But if you are in windows, then run
npm install gulp --save-dev
πΉ The way Gulp work is - Everything is split into various plugins. So each plugin does one job & one job only. And that way we can pipe the output of one function to another. So we can say - Let's autoprefix this file & then minify it & then output it some file & then finally provide some sort of notifications. All of that stuff is really easy with Gulp.
πΉ So if we want to use plugins, we need to install some. Lets install, just to get started, How about minifying our css We can do that by running into ubuntu terminal
sudo npm install gulp-clean-css --save-dev
πΉ For windows run
npm install gulp-clean-css --save-dev
πΉ Now if you wanna minifying the js then in ubuntu terminal
sudo npm install gulp-jsmin --save-dev
πΉ But if you are in windows then run in Laragon terminal
npm install gulp-jsmin --save-dev
πΉ To use gulp, run from terminal
gulp
π Elham Zero Second Deployment
πΉ Elham proudly compatibles with ngrok. So you can deploy it less than a second. For that you'll have to install node & nodejs-legacy by the following command
sudo apt-get install node sudo apt install nodejs-legacy
πΉ After that we gonna install ngrok through (npm)node package manager globally
sudo npm install ngrok -g
πΉ Now we gonna deploy our project by just running the following command
ngrok http 8000
πΉ Make sure you are running your project through port 8000. If you are using other port, then use that port to ngrok
π Elham Production Deployment
πΉ Don't worry it also supports any repo(Github,Gitlab,Bitbucket....) and any CI (Jenkins) and any server(Linux Distro. preferred) in deployment.