Onur Özgür ÖZKAN

Php, Ruby, Kebab, Git Geek

Develop a Simple Installer for Kebab Project on PHP CLI

In this post i’m going to explain how to write a simple installer for Kebab Project. Above codes and informations are trials and i am writing them right now. So don’t use them in really life. :) First of all we should understand PHP CLI. So it is a good idea to quick look

  1. http://php.net/manual/en/features.commandline.php
  2. http://www.php-cli.com/php-cli-tutorial.shtml

Now we create a menu because developer want to choices what to install. showMenu function echo a menu with 4 choice.

1
2
3
4
5
6
7
8
function showMenu()
{
    echo "What do you install?\n"
      . "1. Kebab \n"
      . "2. Doctrine \n"
      . "3. Zend Framework \n"
      . "4. ExtJs \n";
}

Now we need to access the user input all we need to do is read from stdin. getLine function is accessed the input and trimed.

1
2
3
4
5
function getLine()
{
    $handle = fopen ("php://stdin","r");
    return trim(fgets($handle));
}

Now we do action here. I mean get the user choice and install what they want to. But this is an other post issue thats why i just wanna echo a sentence what they wanna install.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
switch (getLine()) {
    case "1":
        echo "You wanna install Kebab Project\n";
        break;
    case "2":
        echo "You wanna install Doctrine\n";
        break;
    case "3":
        echo "You wanna install Zend Framework\n";
        break;
    case "4":
        echo "You wanna install ExtJS\n";
        break;
    default:
        echo "\033[31mWrong choice\033[37m\r\n";
}

exit;

If we concat the all code, it will be like that…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env php
<?php

showMenu();

switch (getLine()) {
    case "1":
        echo "You wanna install Kebab Project\n";
        break;
    case "2":
        echo "You wanna install Doctrine\n";
        break;
    case "3":
        echo "You wanna install Zend Framework\n";
        break;
    case "4":
        echo "You wanna install ExtJS\n";
        break;
    default:
        echo "\033[31mWrong choice\033[37m\r\n";
}

exit;

function getLine()
{
    $handle = fopen ("php://stdin","r");
    return trim(fgets($handle));
}

function showMenu()
{
    echo "What do you install?\n"
      . "1. Kebab \n"
      . "2. Doctrine \n"
      . "3. Zend Framework \n"
      . "4. ExtJs \n";
}

Next post i will explain how we install Kebab Project from git with this install. :) I wish i will be finished until next post :)

Best Regards.