Skip to content

Commit 158a642

Browse files
committed
- added namespace "PHPCommandLine\" to the command line library
1 parent fd0265c commit 158a642

File tree

20 files changed

+82
-29
lines changed

20 files changed

+82
-29
lines changed

commandline/autocomplete.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<?php
2-
require 'library/init.php';
3-
header("Content-Type: text/json;");
2+
require 'library/init.php';
3+
use PHPCommandLine\lCommand;
4+
use PHPCommandLine\lConnection;
5+
use PHPCommandLine\lJSON;
46

5-
lConnection::init();
7+
// set answer to json
8+
header("Content-Type: text/json;");
69

7-
$input = (isset($_GET["input"]) and $_GET["input"]!="") ? trim($_GET["input"]) : null;
8-
if(lConnection::isAuthorized()){
9-
lJSON::dump(lCommand::getAutoCompleteFor($input));
10-
}else{
11-
lJSON::dump(str_replace($input, "", "login"));
12-
}
10+
lConnection::init();
11+
12+
$input = (isset($_GET["input"]) and $_GET["input"]!="") ? trim($_GET["input"]) : null;
13+
if(lConnection::isAuthorized()){
14+
lJSON::dump(lCommand::getAutoCompleteFor($input));
15+
}else{
16+
lJSON::dump(str_replace($input, "", "login"));
17+
}
1318

1419
?>

commandline/index.php

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
<?php
2-
require 'library/init.php';
3-
header("Content-Type: text/json;");
2+
require 'library/init.php';
3+
use PHPCommandLine\lCommand;
4+
use PHPCommandLine\lConnection;
5+
use PHPCommandLine\lJSON;
46

5-
lConnection::init();
7+
// set answer to json
8+
header("Content-Type: text/json;");
69

7-
$command = (isset($_GET["command"]) and $_GET["command"]!="") ? trim($_GET["command"]) : null;
8-
if($command!=null){
9-
if($command=="init"){
10-
if(!lConnection::isAuthorized()) lCommand::write("welcome to the php command line. please login via the command \"login\"");
11-
}else{
12-
lCommand::addToStack($command);
10+
lConnection::init();
11+
12+
$command = (isset($_GET["command"]) and $_GET["command"]!="") ? trim($_GET["command"]) : null;
13+
if($command!=null){
14+
if($command=="init"){
15+
if(!lConnection::isAuthorized()) lCommand::write("welcome to the php command line. please login via the command \"login\"");
16+
}else{
17+
lCommand::addToStack($command);
18+
}
1319
}
14-
}
1520

16-
lCommand::performNextCommand();
21+
lCommand::performNextCommand();
1722

18-
lJSON::dump(lCommand::getResult());
23+
lJSON::dump(lCommand::getResult());
1924
?>

commandline/library/lCommand.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace PHPCommandLine;
3+
24
abstract class lCommand{
35
static function getAutoCompleteFor($input){
46
$input = explode(" ", $input);

commandline/library/lConnection.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace PHPCommandLine;
3+
24
abstract class lConnection{
35
static function init(){
46
session_start();

commandline/library/lJSON.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace PHPCommandLine;
3+
24
abstract class lJSON{
35
static function dump($object){
46
echo json_encode([

commandline/library/lStorage.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace PHPCommandLine;
3+
24
abstract class lStorage{
35
static $program = ".main";
46

commandline/library/lSystem.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace PHPCommandLine;
3+
24
abstract class lSystem{
35
static private $version = "0.1";
46

commandline/programs/cd/init.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
use PHPCommandLine\lSystem;
4+
25
function cdMain($args, $command){
36
lCommand::write("> $command");
47
if(count($args)>=1){

commandline/programs/echo/init.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
24
function echoMain($args, $command){
35
lCommand::write("> $command");
46
$str = "";

commandline/programs/exit/init.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2-
function exitMain($args, $command){
3-
lCommand::write("> $command");
4-
lCommand::write("note that exit is just an alias for logout");
5-
lCommand::setNextCommand("logout");
6-
lCommand::performNextCommand();
7-
}
2+
use PHPCommandLine\lCommand;
3+
4+
function exitMain($args, $command){
5+
lCommand::write("> $command");
6+
lCommand::write("note that exit is just an alias for logout");
7+
lCommand::setNextCommand("logout");
8+
lCommand::performNextCommand();
9+
}
810
?>

commandline/programs/help/init.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
24
function helpMain($args, $command){
35
lCommand::write("> $command");
46
$content = "pre-installed programs:\n";

commandline/programs/login/init.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
use PHPCommandLine\lConnection;
4+
use PHPCommandLine\lStorage;
5+
26
function loginMain($args, $command){
37
if(count($args)==0){
48
lCommand::write("> login");
@@ -19,8 +23,6 @@ function loginMain($args, $command){
1923
lCommand::write("welcome, ".$username);
2024
}else{
2125
lCommand::write("not authorized");
22-
// lCommand::addToStack("login");
23-
// lCommand::performNextCommand();
2426
}
2527
}
2628
}

commandline/programs/logout/init.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
24
function logoutMain($args, $command){
35
lCommand::write("> logout");
46
lCommand::write("logged out successfully. bye.");

commandline/programs/ls/init.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
use PHPCommandLine\lSystem;
4+
25
function lsMain($args, $command){
36
lCommand::write("> $command");
47
$files = scandir(lSystem::getPWD());

commandline/programs/more/init.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
use PHPCommandLine\lSystem;
4+
25
function moreMain($args, $command){
36
lCommand::write("> $command");
47
if(count($args)==1){

commandline/programs/pwd/init.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
use PHPCommandLine\lSystem;
4+
25
function pwdMain($args, $command){
36
lCommand::write("> $command");
47
$pwd = lSystem::getPWD();

commandline/programs/reset/init.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
24
function resetMain($args, $command){
35
lCommand::write("> $command");
46
lCommand::write("session storage and command stack resetted successfully. this is now a clear session.");

commandline/programs/rm/init.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
use PHPCommandLine\lSystem;
4+
25
function rmMain($args, $command){
36
lCommand::write("> $command");
47
if(count($args)==1){

commandline/programs/touch/init.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
use PHPCommandLine\lSystem;
4+
25
function touchMain($args, $command){
36
lCommand::write("> $command");
47
if(count($args)==1){

commandline/programs/update/init.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
use PHPCommandLine\lCommand;
3+
use PHPCommandLine\lSystem;
4+
25
function updateMain($args, $command){
36
if(count($args)==0){
47
lCommand::write("> $command");

0 commit comments

Comments
 (0)