Commit 378f9448 authored by Heiko Mettelsiefen's avatar Heiko Mettelsiefen 💬

clear and optimze codeformatting

parent aca8a8ca
# 1.0.7
## notes
* optimize codeformatting
## added
* some comments
## fixed
- some small fixes
## removed
# 1.0.5
## notes
* not compatible with the 1.04
......
......@@ -13,11 +13,11 @@
"require": {
},
"autoload": {
"psr-4": {
"HM\\":"models/",
"autoload": {
"psr-4": {
"HM\\":"models/",
"simple\\":"simplemvc/",
"simpleController\\":"controllers/"
}
}
}
}
}
<?
/*
* define global header data
* php inis, erro handling, output, general header data
* this settings will execute before the framework start
*/
// output as json
#header('Content-Type: application/json');
// error_reporting(E_ALL);
......
<?
\ No newline at end of file
<?
/*
* define global settings
* like global variables or constants for you appo
*
*/
\ No newline at end of file
......@@ -14,6 +14,7 @@ $page = new simple\MVC($app_route);
# show info about the $page object
#var_dump($page);
// routing to 404, if the page not found
if ($page->view->path === false) : header('Location: '.'/notFound'); endif;
// build view controller and call the page action
......
<?
namespace HM;
class Dir {
/**
* Set a persons weight in Kilogram
*
* @description
*/
public $path;
/**
* Build object
*
* @param path (string)
*
*/
function __construct($path)
{
$this->path = $path;
$this->realpath = realpath($path);
}
/**
* Build object
*
* @param -
* @desc check if dir exists
*/
public function exists()
{
return $return = is_dir($this->path) ? true : false;
}
/**
* Build object
*
* @param -
* @desc check if dir exists
*/
public function create($mode = 0777, $recursive = false)
{
if (mkdir($this->path, $mode, $recursive) === true) :
$oldmask = umask(0);
chmod($this->path, $mode);
umask($oldmask);
return true;
endif;
}
class Dir {
/**
* Directory Handler
*
*/
public $path;
/**
*
* @param
* path (string)
*
*/
function __construct($path)
{
$this->path = $path;
$this->realpath = realpath($path);
}
/**
*
* @desc
* check if dir exists
*
* @param
* -
*/
public function exists()
{
return $return = is_dir($this->path) ? true : false;
}
/**
* @desc
* create directory
*
* @param
* mode (int [optional], recursicve (bool) [optional]),
*/
public function create($mode = 0777, $recursive = false)
{
if (mkdir($this->path, $mode, $recursive) === true) :
$oldmask = umask(0);
chmod($this->path, $mode);
umask($oldmask);
return true;
endif;
}
}
\ No newline at end of file
<?
namespace HM;
class File {
/**
* Set a persons weight in Kilogram
*
* @description
*/
public $path;
/**
* Build object
*
* @param path (string)
*
*/
function __construct($path)
{
$this->path = $path;
$this->realpath = realpath($path);
}
/**
* Build object
*
* @param -
* @desc check if dir exists
*/
public function exists()
{
return $return = is_file($this->path) ? true : false;
}
/**
* Build object
*
* @param -
* @desc check if dir exists
*/
public function create($mode = 'a', $chmod = 0777)
{
if (file_put_contents($this->path,'') === true):
$oldmask = umask(0);
chmod($this->path, $mode);
umask($oldmask);
return true;
endif;
}
/**
* Build object
*
* @param -
* @desc write in a file (overwrite)
*/
public function write($content)
{
if (file_put_contents($this->path, $content, LOCK_EX)):
return true;
endif;
return false;
}
/**
* Build object
*
* @param -
* @desc write in a file (appends)
*/
public function append($content)
{
if (file_put_contents($this->path, $content, FILE_APPEND | LOCK_EX)):
return true;
endif;
return false;
}
/*
* getContent
*
* params -
* return $content (string)
*
*/
public function getContent(){
return file_get_contents($this->path);
}
/*
* getContent
*
* @description
* get content from files in the src directory
*
* @param
* path (string)
* filename (string)
*
* @return
* content (string)
*
*/
public function getJson($assoc = false) {
return json_decode($this->getContent($this->path), $assoc);
}
class File {
/**
* File handler
*
*/
public $path;
/**
* Build object
*
* @param
* path (string)
*
*/
function __construct($path)
{
$this->path = $path;
$this->realpath = realpath($path);
}
/**
* Build object
*
* @param -
* @desc check if dir exists
*/
public function exists()
{
return $return = is_file($this->path) ? true : false;
}
/**
*
* @desc
* check if file exists
*
* @param
* mode (string) [optional]
* chmod (int) [optional]
*
* @return
* bool
*/
public function create($mode = 'a', $chmod = 0777)
{
if (file_put_contents($this->path,'') === true):
$oldmask = umask(0);
chmod($this->path, $mode);
umask($oldmask);
return true;
endif;
}
/*
*
* @desc
* write in a file (overwrite)
*
* @param
* content (string)
*
* @return
* bool
*
*/
public function write($content)
{
if (file_put_contents($this->path, $content, LOCK_EX)):
return true;
endif;
return false;
}
/*
*
* @desc
* append content in file
*
* @param
* content (string)
*
* @return
* bool
*
*/
public function append($content)
{
if (file_put_contents($this->path, $content, FILE_APPEND | LOCK_EX)):
return true;
endif;
return false;
}
/*
*
* @desc
* get content from ther file
*
* @param
* -
*
* @return
* content (string)
*
*/
public function getContent(){
return file_get_contents($this->path);
}
/*
*
* @desc
* get json as object from a json file
*
* @param
* assoc (json_decode typ)
*
* @return
* object
*
*/
public function getJson($assoc = false) {
return json_decode($this->getContent($this->path), $assoc);
}
}
\ No newline at end of file
<!doctype html>
<html>
<head>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootswatch/4.3.1/simplex/bootstrap.min.css" rel="stylesheet">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootswatch/4.3.1/simplex/bootstrap.min.css" rel="stylesheet">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<title><?= $page->title; ?></title>
</head>
<body>
<? include($page->view->path); ?>
</body>
</html>
<!doctype html>
<html>
<head>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootswatch/4.3.1/cerulean/bootstrap.min.css" rel="stylesheet">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootswatch/4.3.1/cerulean/bootstrap.min.css" rel="stylesheet">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<title><?= $page->title; ?></title>
</head>
<body>
<? include($page->view->path); ?>
</body>
</html>
<?
namespace simple;
use HM;
class Controller {
/**
* Controller
*
* @description
* https://gitlab.com/mascoda/simple-mvc/wikis/home
*
*/
public $name;
class Controller {
/*
* Controller
*
* @description
* https://gitlab.com/mascoda/simple-mvc/wikis/home
*
*/
public $name;
public $filename;
public $filepath;
public $actions;
/*
* Constructor
*
* @description
* build controller object on init
*
* @param
* path (string)
*
*/
function __construct($path)
{
/*
* Constructor
*
* @description
* build controller object on init
*
* @param
* path (string)
*
*/
function __construct($path)
{
$this->setName($path);
$this->setFilename();
$this->setFilepath();
}
}
/*
* @description
* set name of controller
*/
private function setName($path) {
* @description
* set name of controller
*/
private function setName($path) {
$path = strtolower($path);
......@@ -48,50 +48,50 @@ use HM;
$name = array_shift($name);
$this->name = $name;
}
}
/*
* @description
* set filename
*/
public function setFilename() {
}
/*
* @description
* set filename
*/
public function setFilename() {
$this->filename = $this->name . '.controller.php';
}
}
/*
* @description
* set filepath
*/
public function setFilepath() {
* @description
* set filepath
*/
public function setFilepath() {
$this->filepath = dirname(__DIR__) . '/controllers/' . $this->name . '.controller.php';
}
}
/*
* @description
* check if controller file exists
*/
public function exists() {
* @description
* check if controller file exists
*/
public function exists() {
return $exists = realpath($this->filepath) ? TRUE : FALSE;
}
}
/*
* @description
* returned the Action
* @description
* returned the Action
*
* @params
* $viewName (string)
*/
public function getAction($viewName) {
*/
public function getAction($viewName) {
return $viewName . 'Action';
}
}
/*
* @description
* returned namespace (string)
*/
public function getNamespace() {
* @description
* returned namespace (string)
*/
public function getNamespace() {
return 'simpleController\\';
}
}
/*
* @description
* create controller file
*/
public function createFile() {
* @description
* create controller file
*/
public function createFile() {
// create a new file object
$file = new HM\File(dirname(__DIR__) . '/controllers/' . $this->name .'.controller.php');
......@@ -100,18 +100,18 @@ use HM;
$template = SRC::getContent('controller', 'default.controller.php');
// search and replace placeholder in default template
$search = array('{controllerName}', '{actionName}');
$replace = array($this->name . 'Controller', $this->name."Action");
$template = str_replace($search, $replace, $template);
$search = array('{controllerName}', '{actionName}');
$replace = array($this->name . 'Controller', $this->name."Action");
$template = str_replace($search, $replace, $template);
$file->create(0775);
$file->write($template);
}
$file->create(0775);
$file->write($template);
}
/*
* @description
* extended controller with a new action
*/
public function createAction($action) {
* @description
* extended controller with a new action
*/
public function createAction($action) {
// get controller as file
$controller = new HM\File($this->filepath);
......@@ -128,5 +128,5 @@ use HM;
$controller->append($template);
endif;
}
}
}
\ No newline at end of file
<?
namespace simple;
use HM;
class MVC {
/**
* Generate page with controller and view
*
* @description
* https://gitlab.com/mascoda/simple-mvc/wikis/home
*
*/
public $page;
public $controller;
public $method;
public $template;
public $view;
public $title;
/*
* Constructor
*
* @description
* build the complete page with controller and view
*
* @param
* page (string)
* template (string) [optional]
*
* @return
* -
*
*/
function __construct($page, $template = 'default')
{
class MVC {
/**
* Generate page with controller and view
*
* @description
* https://gitlab.com/mascoda/simple-mvc/wikis/home
*
*/
public $page;
public $controller;
public $method;
public $template;
public $view;
public $title;
/*
* Constructor
*
* @description
* build the complete page with controller and view
*
* @param
* page (string)
* template (string) [optional]
*
* @return
* -
*
*/
function __construct($page, $template = 'default')
{
$this->page($page);
$this->getController();
$this->template($template);
$this->view();
$this->getController();
$this->template($template);
$this->view();
}
/*
* Page
*
* @description
* create page, if it does not exist, move on to 404
*
* @param
* page (string)
*
* @return
* -
*
*/
private function page($page)
{
}
/*
* Page
*
* @description
* create page, if it does not exist, move on to 404
*
* @param
* page (string)
*
* @return
* -
*
*/
private function page($page)
{
# define page from the uri
$page = ltrim(rtrim($page, '/'), '/');
$this->page = ($page === '') ? 'index' : $page;
$page = ltrim(rtrim($page, '/'), '/');
$this->page = ($page === '') ? 'index' : $page;
}
/**
* Controller