Skip to content

Commit

Permalink
Minor bugs fixed & added oauth module
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandPilania committed Sep 4, 2018
1 parent 7ea615a commit 451be80
Show file tree
Hide file tree
Showing 191 changed files with 56,204 additions and 86 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/vendor
/public/tmp
/public/compressed
/storage/db
/storage/app
/storage/temp
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
"# F3Module"

## KNOWN ISSUES
1: Rendering modules views:
This issue can be resolved by modifying `Preview->render` as below:
if(is_file($view = $f3->fixslashes($dir.$file))) // REPLACE THIS WITH


$_f = $fw->fixslashes($dir.$file);
$_fr = str_ireplace('./', '', $_f);
$view = (is_file($_f) ? $_f : (is_file($_fr) ? $_fr : null));
if ($view) {
101 changes: 101 additions & 0 deletions app
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env php

<?php

class App {

public function __construct($args) {
$this->args = $args;
}

public function help() {
echo "\n";
echo "Syntax: php app <command> [<args>]".PHP_EOL;
echo PHP_EOL;
echo "Commands: \n";
echo "php app --help --> Displays the help menu.".PHP_EOL;
echo "php app generate --> Generate SECRET key.".PHP_EOL;
echo "php app serve --> Start WebServer.".PHP_EOL;
echo "php app serve --port --> Start WebServer to specific port.".PHP_EOL;
echo PHP_EOL;
}

public function run() {
if (count($this->args) <= 1) {
$this->help();
} else {
switch ($this->args[1]) {
case "generate":
$this->generateKey();
break;
case "serve":
$this->serve();
break;
case "help":
case "--help":
$this->help();
break;
default:
$this->error();
}
}
}

private function serve() {
$command = 'php -S';
$ip = '127.0.0.1';
$port = 8888;
$dir = './';

foreach($this->args as $key => $arg) {
$arg = strtolower($arg);
if($arg === 'ip' || $arg === '--ip'){
$host = $this->args[++$key];
if(
(is_numeric($host) && !filter_var($host, FILTER_VALIDATE_IP))
||
(is_string($host) && strtolower($host) !== 'localhost')
){
$this->error($arg.': '.$host.' must be localhost OR an valid IP!');
break;
}
$ip = $host;
}
if($arg === 'port' || $arg === '--port'){
$port = $this->args[++$key];
}
if($arg === 'dir' || $arg === '--dir'){
$dir = $this->args[++$key];
}
}

echo "Served as {$ip}:{$port} to {$dir}";
$started = exec($command.' '.$ip.':'.$port.' -t '.$dir);
$this->error($started);
}

private function generateKey() {
$cipher = 'AES-256-CBC';
echo 'base64:'.base64_encode(random_bytes($cipher == 'AES-128-CBC' ? 16 : 32));
}

private function error($msg = null) {
if($msg){
echo "\t{$msg}";
exit();
}

echo "\nSupplied argument/s is not supported:\n";
foreach($this->args as $arg) {
if($arg == 'app') { continue; }
echo "\t";
echo "{$arg}";
echo "\n";
}

echo PHP_EOL;
}
}

$app = new App($argv);
$app->run();
38 changes: 24 additions & 14 deletions bootstrap/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ function status($code = 404)
{
f3()->error($code);
}
function view($template, array $data = [])
{
Response::instance()->view($template, $data);
exit();
}
function response($key, $val = null)
{
if(!is_array($key)) {
$key = [$key => $val];
}
header('Content-Type: application/json; charset='.f3()->CHARSET);
echo json_encode($key);
exit();
}
function reroute($where)
{
f3()->reroute($where);
Expand All @@ -46,6 +32,30 @@ function is_api($path)
}
return false;
}
function view($template, array $data = [])
{
return Response::instance()->view($template, $data);
}
function response($key, $val = null)
{
return Response::instance()->json($key, $val);
}
function template($layout, $f3)
{
$loc = null;
if(Str::contains($layout, '::')) {
$module = explode('::', $layout)[0];
foreach(explode(';', $f3->UI) as $path) {
if(Str::contains($path, 'modules/'.$module) || Str::contains($path, str_ireplace('/', '', 'modules\/'.$module))) {
$loc = str_ireplace($module.'::', '', $path.$layout);
break;
}
}
}else{
$loc = $layout;
}
return $loc;
}
function generateKey($chiper = 'AES-256-CBC')
{
return 'base64:'.generateEncKey($chiper);
Expand Down
66 changes: 33 additions & 33 deletions composer.lock

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

5 changes: 4 additions & 1 deletion helpers/ApiController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

abstract class ApiController extends Controller
{}
{
public function response($data, $headers = null)
{}
}
6 changes: 6 additions & 0 deletions helpers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

abstract class Controller
{
public function __construct()
{
$this->initMiddlewares();
}
public function initMiddlewares()
{}
public function validate($data = [], $rules = [])
{
return Validator::instance()->validate($data, $rules);
Expand Down
Loading

0 comments on commit 451be80

Please sign in to comment.