Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#add missing license file #7

Merged
merged 2 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 murage

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 0 additions & 17 deletions app/controllers/HomeController.php

This file was deleted.

20 changes: 20 additions & 0 deletions app/controllers/StaticPagesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* All rights reserved.
* User: mimidots
* Date: 06-Aug-17
* Time: 16:50
*/

class StaticPagesController{

public static function serveLogin(){
view('login');
}

public static function serveHome(){
view('home',['somedata'=>["this","is","awesome"]]);
}

}
17 changes: 17 additions & 0 deletions app/controllers/UsersController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Created by PhpStorm.
* User: mimidots
* Date: 7/7/2019
* Time: 1:55 PM
*/

class UsersController
{
static function add(){}

static function fetch(){}

static function delete(){}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Time: 21:10
*/

namespace Middleware;

class Auth {

Expand Down
26 changes: 0 additions & 26 deletions app/models/AppGlobalsModel.php

This file was deleted.

14 changes: 14 additions & 0 deletions app/models/BaseModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: mimidots
* Date: 7/16/2019
* Time: 9:04 PM
*/

namespace Models;

class BaseModel
{

}
20 changes: 20 additions & 0 deletions app/models/UsersModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* Created by PhpStorm.
* User: mimidots
* Date: 6/5/2018
* Time: 6:33 PM
*/
namespace Models;
class UsersModel extends BaseModel {

static function getAll(){
return json_encode([]);
}

static function add(){}

static function delete(){}

}
18 changes: 18 additions & 0 deletions app/services/Tokens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: mimidots
* Date: 7/6/2019
* Time: 10:28 PM
*/

namespace Services;


class Tokens
{

static function csrfToken(){
return str_replace('.','-',uniqid(null,true));
}
}
File renamed without changes.
39 changes: 33 additions & 6 deletions app/Router.php → bootstrap/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ class Router {

public static $routes = [
'GET' => [],
"POST" => []
"POST" => [],
"DELETE" => [],
"PATCH" => [],
"OPTIONS" => [],
"PUT" => []
];


Expand All @@ -29,16 +33,39 @@ public static function post( $uri, $controller ) {

return self::$routes["POST"][ trim($uri,'/') ] = $controller;
}

public static function load( $file ) {
$instance = new static();

require $file;

public static function delete( $uri, $controller ) {

return self::$routes["DELETE"][ trim($uri,'/') ] = $controller;
}

public static function patch( $uri, $controller ) {

return self::$routes["PATCH"][ trim($uri,'/') ] = $controller;
}

/**
* @param array $files
* @return Router
*/
public static function load($files=[] ) {
$instance = new static();

foreach ($files as $file) {
require_once $file;
}
return $instance;
}

public static function direct( $uri,$requestType ) {

if(!isset(self::$routes[$requestType])){
http_response_code(503);
header('Content-type:application/json');
echo json_encode(['status'=>'error','message'=>'Bad Request. Unknown request method '.$requestType,
'code'=>503]);
return 1; }

if(array_key_exists(trim($uri,'/'),self::$routes[$requestType])){

return static::mapController(
Expand Down
25 changes: 0 additions & 25 deletions bootstrap/TwigApp.php

This file was deleted.

76 changes: 25 additions & 51 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
use Dotenv\Dotenv;

/*
|--------------------------------------------------------------------------
Expand All @@ -14,76 +13,51 @@
*/
require_once 'vendor/autoload.php';


/*
* Die and Dump
/**
*
* @param $data
* Initialize the twig library
*/
function dd( $data = [] ) {
echo '<pre>';
die( var_dump( $data ).'</pre>' );
function render($view,$data){
$loader=new \Twig\Loader\FilesystemLoader('resources/views/');

}
if(!$loader->exists($view)){ $view='errors/500.twig';}

$twig = new \Twig\Environment($loader, []);
try {
echo $twig->render($view, $data);
} catch (\Twig\Error\LoaderError $e) {
var_dump($e);
} catch (\Twig\Error\RuntimeError $e) {
var_dump($e);

} catch (\Twig\Error\SyntaxError $e) {
var_dump($e);

}
}

/**
* @param $name :the name of the view
* @param array $data :optional data to be passed to the view
*/
function view( $name ,$data=[]) {

//add any global data
$data['app_author']=AppGlobalsModel::author();
$data['appname']=AppGlobalsModel::appname();
$data['baseUrl']=AppGlobalsModel::baseurl();


/*twig rendering now comes into play*/
TwigApp::render($name.'.twig',$data);
render($name.'.twig',$data);

}



/**
* Provide and easy method to load environment variables
* This function requires vlucas phpdotenv module <code>https://github.com/vlucas/phpdotenv </code>
*
* @param $key :the key (string) of the value one want to get
*
* @return mixed
/*
* Die and Dump
*
* @throws Exception :if the key is not found
* @param $data
*/
function env($key){

if(!is_string($key)){

throw new Exception("Invalid key provided {$key}");
}
function dd( $data = [] ) {
echo '<pre>';
die( var_dump( $data ).'</pre>' );

if(array_key_exists($key,Env::getEnv())){
return Env::getEnv()[$key];
}
throw new Exception("no defined environment variable for {$key}");
}


class Env {


public static function getEnv() {
$c = new Dotenv( './' );
$envVariables=[];

foreach ( $c->load() as $var ) {
$config=explode('=',$var);

$envVariables[$config[0]]=$config[1];
}
return $envVariables;

}
}
?>
Loading