Skip to content

Commit

Permalink
Changes 1.2:
Browse files Browse the repository at this point in the history
- Remove bramusRouter package
- Refactor Environment.php. Added exceptions.
- Refactor Router.php. This modified bramus\router.
- Refactor App.php
- Refactor Engine.php for new Router.php
- Added Response controller
- Added the ability to administer the framework via the CLI interface.
  • Loading branch information
shmelevdi committed Jul 23, 2021
1 parent 7840338 commit 9337357
Show file tree
Hide file tree
Showing 8 changed files with 520 additions and 86 deletions.
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
},
"require": {
"php": ">=7.2",
"composer-runtime-api": "^2.0",
"vlucas/phpdotenv": "^5.0",
"gabordemooij/redbean": "^5.6",
"tymon/jwt-auth": "^1.0",
"bramus/router": "~1.4",
"ext-json": "*"
}
}
54 changes: 1 addition & 53 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions controllers/Regular/DefaultController.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<?php
namespace Roast\Controllers\Regular;
use Carbon\Carbon;
use Roast\App;
use Roast\Controller;
use Roast\Environment;
use Roast\ExceptionHandler;
use Roast\Headers;
use Roast\Response;

class DefaultController extends Controller
Expand Down
2 changes: 1 addition & 1 deletion vendor/engine/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct()

public static function Ver()
{
return (object)["app_name"=>$_ENV['APP_NAME'], "app_version"=>"1.0", "framework"=>"Roast 1.1"];
return (object)["app_name"=>$_ENV['APP_NAME'], "app_version"=>"1.0", "framework"=>"Roast 1.2"];
}

}
65 changes: 54 additions & 11 deletions vendor/engine/Console/ControllersConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,79 @@
//Точка входа в приложение
// @App.php
namespace Roast\Console;

use Roast\Console\Colors;

class ControllersConsole
{
public $return;
public $InvalidChar;
public function __construct()
{
$this->return = new Colors();
$this->InvalidChar = ["/", "|", ",", ".", ")", "(", "_", "*", "?", ">", "<", ")", "&", "^", "%", "+", "#", "!", "\\", ";", ":", "-", " "];
}

public function Make($arg)
{
if(strpos($arg, '\\') || strpos($arg, '/')) {
$arg = str_replace(['\\', '/'], '/', $arg);
$exparg = explode('/', $arg);
$structure = preg_replace('/(.)\1+/', '$1', str_replace($exparg[count($exparg)-1], '', $arg));
$controllername = $exparg[count($exparg)-1];
$dir = "controllers/$structure";
if(!is_dir($dir))
if (str_contains($arg, '\\') || str_contains($arg, '/')) {
$arg = str_replace(['\\', '/'], '\\', $arg);
$exparg = explode('\\', $arg);
$structure = preg_replace('/(.)\1+/', '$1', str_replace($exparg[count($exparg) - 1], '', $arg));
if(substr($structure, -1) == '\\') $structure = substr_replace($structure,'',-1);
$controllername = $exparg[count($exparg) - 1];
if($this->strposa($controllername))
{
print $this->return->getColoredString("Failed to create controller $controllername. The controller name cannot contain special chars!" . PHP_EOL, "red");
exit(1);
}
$dir = "controllers\\$structure\\";
$controller_content = "<?php\nnamespace Roast\Controllers\\$structure;\nuse Roast\App;\nuse Roast\Controller;\nuse Roast\Response;\n\nclass $controllername extends Controller\n{\n\n\n}";
if (!is_dir($dir)) {
if (!mkdir($dir, 0775, true)) {
$this->return->getColoredString("Failed to create namespace $structure", "red");
$this->return->getColoredString("Failed to create namespace $structure" . PHP_EOL, "red");
exit(1);
}
} else {
print $this->return->getColoredString("Namespace $structure already exists. OK." . PHP_EOL, "green");
}
else
if (file_exists($dir . $controllername)) {
$this->return->getColoredString("Failed to create controller $controllername. Already exists!" . PHP_EOL, "red");
exit(1);
} else {
file_put_contents($dir . $controllername . ".php", $controller_content);
print $this->return->getColoredString("Controller $controllername created successfully!" . PHP_EOL, "green");
exit(0);
}
}
else
{
$controllername = $arg;
if($this->strposa($controllername))
{
print $this->return->getColoredString("Namespace $structure already exists. OK.", "green");
print $this->return->getColoredString("Failed to create controller $controllername. The controller name cannot contain special chars!" . PHP_EOL, "red");
exit(1);
}
$controller_content = "<?php\nnamespace Roast\Controllers;\nuse Roast\App;\nuse Roast\Controller;\nuse Roast\Response;\n\nclass $controllername extends Controller\n{\n\n\n}";
if (file_exists($controllername)) {
print $this->return->getColoredString("Failed to create controller $controllername. Already exists!" . PHP_EOL, "red");
exit(1);
} else {
file_put_contents("controllers\\".$controllername . ".php", $controller_content);
print $this->return->getColoredString("Controller $controllername created successfully!" . PHP_EOL, "green");
exit(0);
}
}
}


private function strposa($haystack) {
$chr = array();
foreach($this->InvalidChar as $needle) {
$res = strpos($haystack, $needle);
if ($res !== false) $chr[$needle] = $res;
}
if(empty($chr)) return false;
return min($chr);
}

}
2 changes: 1 addition & 1 deletion vendor/engine/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function require_dir($dir, $sort=0)
*/
public function run()
{
$route = (new \Roast\Router)->middleware();
$route = new \Roast\Router;
$routes = $this->require_dir(__DIR__."/../../routes");
foreach ($routes as $router)
{
Expand Down
22 changes: 16 additions & 6 deletions vendor/engine/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@

class Environment
{

private $dotenv;

/**
* __construct
*
* @return void
* @throws \ErrorException
*/
public function __construct()
public function __construct()
{
$dotenv = \Dotenv\Dotenv::createImmutable($_SERVER['DOCUMENT_ROOT'].'/../');
$dotenv->load();
}
}
if(!file_exists("../.env"))
{
throw new \ErrorException('Environment file (.env) is not found. If this is the first launch of the application - create .env from the example .env.example.', 1);
}
else
{
$this->dotenv = \Dotenv\Dotenv::createImmutable($_SERVER['DOCUMENT_ROOT'].'/../');
$this->dotenv->load();
}

?>
}
}
Loading

0 comments on commit 9337357

Please sign in to comment.