Skip to content

Commit

Permalink
Lemonade kernel hotif
Browse files Browse the repository at this point in the history
  • Loading branch information
tenmajkl committed May 24, 2021
1 parent ac98059 commit 777d528
Show file tree
Hide file tree
Showing 9 changed files with 462 additions and 3 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/testing/
/lemon/kernel
/vendor/
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Documentation: https://tenmajkl.github.io/docs.html
Installation is provided via composer:\
`composer create-project lemon_framework/lemon:dev-master project-name`

Lemon doesn't use project generator, so you need to make files manually and run app using `php -S localhost:port`\
// Lemonade coming soon :)
If you want to build starting app type `php lemonade build type:project`

# Minimal app

Expand Down
138 changes: 138 additions & 0 deletions lemon/kernel/Builders/builder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

require "templates.php";
require "licenses.php";

/*
*
* Class for build command
*
* Can build project or license
*
* */
class Builder
{
// List of all arguments provided by user
private $arguments;

/*
*
* Assigns arguments
*
* @param array $arguments;
*
* */
public function __construct($arguments)
{
$this->arguments = $arguments;
}

/*
*
* Parses arguments to associative array
*
* @param array $arguments
*
* */
private function parse($arguments)
{
$parsed = [];
foreach($this->arguments as $argument)
{
if(str_contains($argument, ":"))
{
$argument = explode(':', $argument);
$parsed[$argument[0]] = $argument[1];
}
}

return $parsed;
}

/*
*
* Executes specific builder
*
* Executing is provided by argument `type`
*
* */
public function execute()
{
global $types;
$arguments = $this->parse($this->arguments);
if (!isset($arguments["type"]))
{
echo textFormat("Type argument is missing!\n", 31);
return;
}
if(in_array($arguments["type"], $types))
{
$action = $arguments["type"];
$this->$action($arguments);
return;
}
echo textFormat("Type not found!\n", 31);
}

/*
*
* Builds starting project
*
* */
private function project()
{
global $dirs;
global $files;

echo textFormat("\nBuilding project...\n\n", "33");
foreach ($dirs as $dir)
{
if(!file_exists($dir))
{
echo textFormat("Building {$dir}...\n", "33");
mkdir($dir);
}
}
foreach ($files as $file => $link)
{
echo textFormat("Building {$file}...\n", "33");
$file = fopen($file, "w");
$content = file_get_contents($link);
fwrite($file, $content);
}
echo textFormat("\nDone!\n\n", "33");
}

/*
*
* Provider of generating license
*
* Generator is in LicenseBuilder class
*
* */
private function license()
{
$licenses = new LicenseBuilder();

$licenses->buildLicense();



}
}

/*
*
* Function for creating Builder instance
*
* @param array $arguments
*
* */
function build($arguments)
{
$builder = new Builder($arguments);

$builder->execute();
}

?>
106 changes: 106 additions & 0 deletions lemon/kernel/Builders/licenses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
require "templates.php";

/*
*
* Class for building licenses using interactive command
*
* */
class LicenseBuilder
{
// License parameters
private $parameters = [
"license" => "",
"author" => "",
"date" => ""
];

/*
*
* Starts interactive command
*
* */
public function __construct()
{
echo textFormat("License Builder\n\n", "33");
$this->licenseType();
}

/*
*
* Assigns license type
*
* */
private function licenseType()
{
global $licenses;
$type = readline("Type license you want to build: ");

if (isset($licenses[$type]))
{
$this->parameters["license"] = $type;
$this->licenseAuthor();
$this->parameters["date"] = date("Y");
return;
}

if ($type == "custom")
{
$license = readline("Type your license content: ");
$this->parameters["license"] = $license;
return;
}

echo textFormat("This license is not available!\n", "31");
$this->licenseType();

}

/*
*
* Assigns license author
*
* */
private function licenseAuthor()
{
$name = readline("Type author name: ");

if ($name != null)
{
$this->parameters["author"] = $name;
return;
}

echo textFormat("Name must be specified!\n", "31");
$this->licenseAuthor();
}

/*
*
* Builds whole license file
*
* */
public function buildLicense()
{
global $licenses;
$file = fopen("LICENSE.md", "w");
$license = $this->parameters["license"];

if (!in_array($license, $licenses))
{
echo textFormat("Building license...\n", "33");
fwrite($file, $license);
echo textFormat("Done!\n", "33");
return;
}
$content = file_get_contents($licenses[$license]);
$content = str_replace("<copyright holders>", $this->parameters["author"], $content);
$content = str_replace("<date>", $this->parameters["date"], $content);
echo textFormat("Building license...\n", "33");
fwrite($file, $content);
echo textFormat("Done!\n\n", "33");
}

}

?>
42 changes: 42 additions & 0 deletions lemon/kernel/Builders/templates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
*
* Builders variables
*
* */

// List of supported arguments
$arg_list = [
"type",
];

// List of builder types
$types = [
"project",
"license"
];


// List of project directories
$dirs = [
"public",
"views",
"routes",
"controllers",
];

// List of project files
$files = [
"public/index.php" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/index.php",
"routes/web.php" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/web_routes.php"
];


// List of supported licenses
$licenses = [
"mit" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/licences/mit.txt",
"apache" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/licences/apache.txt"

];
?>
20 changes: 20 additions & 0 deletions lemon/kernel/Helpers/commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

require "info.php";
require __DIR__."/../Server/server.php";
require __DIR__."/../Builders/builder.php";

/*
*
* List of all commands
*
* */
$commands = [
"-h" => "help",
"-i" => "info",
"-v" => "version",
"serve" => "serve",
"build" => "build",

];
?>
9 changes: 9 additions & 0 deletions lemon/kernel/Helpers/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

// Formats text with color
function textFormat($text, $color)
{
return "\033[{$color}m{$text}\033[0m";
}

?>
49 changes: 49 additions & 0 deletions lemon/kernel/Helpers/info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

// Importing text format for better colors
require "helpers.php";

// List of all commands
$help = "
-h Shows this help
-i Shows info about lemon
-v Shows version of Lemon
serve Starts development server
build type:project - Builds starter project
:license - Builds license
";

$version = "2.0.0";

// Shows help
function help()
{
global $help;

echo textFormat("\n\u{1F34B} Lemon help\n", "33");
echo $help;

}

// Shows info about project
function info()
{
global $version;

echo textFormat("\n\u{1F34B} Lemon info\n", "33");
echo "\nLemon is simple micro framework that provides routing, etc.\n";
echo "Developed by TEN MAJKL -> Version {$version}\n\n";
}

// Show version
function version()
{
global $version;

echo textFormat("\n\u{1F34B} Lemon version\n", "33");
echo "\n->{$version}\n";
}

?>
Loading

0 comments on commit 777d528

Please sign in to comment.