Skip to content

chandan07cse/Elham

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Elham - Inspiring You The Next - A Product Of UROSD Lab

πŸ“’ 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

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