Commit 2e6319ab authored by Webserver User's avatar Webserver User

alpha@1.0.5

parent e60a3a29
# 1.0.5
## notes
* not compatible with the 1.04
* now with a pageCreator, generate views and controllers on the fly
## added
* simplemvc/manifest.json
* Controller.class.php
* View.class.php
* Tools.class.php
* Manifest.class.php
## fixed
-
## removed
- some method from the MVC.class.php
# 1.0.4
## notes
* some directories moved to another place:
......
......@@ -6,7 +6,7 @@ Perhaps the simplest and easiest PHP MVC framework in the world.
* tidy, easy to understand and easy to use
* strict separation between code and view
* supports composer, just load what you need
* page creator, create pages with controller and view fully automatically and iteratively
* page creator, create controller and views on the fly
* routing & seo friendly urls
* high scalable
* for free
......
......@@ -12,112 +12,75 @@ class indexController {
}
public function indexAction($page) {
$page->title = 'simple-mvc';
$page->template('default');
/*
$array = array("header" => array(),
'config' => array(),
"sitemap" => array());
$json = json_encode($array);
*/
#$manifest = (new HM\File( dirname(__DIR__) . '/simplemvc/' . 'manifest.json'))->getJson();
#$manifest = $manifestFile;
#var_dump($manifest->sitemap);
/* GET SIMPLE
*
* Add a new pages with simple\Page
*
*/
# create a new path, similar to the url
$url = 'blog';
# !or directly several pages
# $url = 'blog/article/comment/';
#$return = $manifest->create();
// create a new page with simple\Page -- blog/list/article/comments
$newPage = (new simple\Page('warehouses/specials'))->add();
#$this->out = $newPage;
// or set path
#$newPage->setPath('');
#$manifest = new simple\Manifest();
#$manifest->build();
# create an object of the type page
$newPage = (new simple\Page($url));
# add the new page to you manifest
//$newPage->add();
# !or use the short way
# $pages = new simple\Page($url)->add();
# you new pages now in your manifest, that you find in /simplemvc
# now load your manifest
$manifest = new simple\Manifest();
# !if you want take a look, you can use
#$this->view = $manifest->get();
# build you added pages by the manifest build method
#$manifest->build();
# now register you new classes in composer
# $ composer dump-autoload -o
# !Congratulations, get a beer
# you can find you new files under /controller and /views
# or the url
// send $this to the view
//$this->view = "Hi, i am a view object";
#$this->user = "I am a user!";
#$this->dir = new HM\Dir('/path_to/MyNewDirectory');
# you want read more about simplemvc?
# https://gitlab.com/mascoda/simple-mvc/wikis/home
/* How to create a new page
* create a new page included controller and views
*
* first step, define the page / url
*
*/
#$url = "/blog/article/list";
/*
* second step, build a MVC object with the uri as parameter
* !Note: do not use the variable $page to create new pages, this will overwrite the current object
*/
#$newPage = new simple\MVC($url);
//new simple\Page($url);
/*
* third step, create page
* this will generated follow files:
*
* /controller/blog.controller.php
* /views/blog.view.php (maybe for list of all blog posts)
* /views/blog/article.view.php (a single blog post)
*
*/
#$newPage->create();
/*
*
* last steps
* go to you command line interface and register you new classes to composer
*
* $ composer dump-autoload -o
*
* Congratulations, thats all :-)
*
*/
/* GET SIMPLE
*
* Send data to the view
*
*/
}
public function moreOfIndexActionAction ($page) {
# you can send data to the view very easy
$page->title = 'simple-mvc';
$page->template('default');
# send a string to the view
$this->view = "Hi, i am a String";
// send $this to the view
$this->view = "Hi, i am a view object";
$this->user = "I am a user!";
$this->dir = new HM\Dir('/path_to/MyNewDirectory');
/* How to create a new page
* create a new page included controller and views
*
* first step, define the page / url
*
*/
$url = "/index/item";
/*
* second step, build a MVC object with the uri as parameter
* !Note: do not use the variable $page to create new pages, this will overwrite the current object
*/
$newPage = new simple\MVC($url);
# or a Model
# $this->dir = new HM\Dir('/path_to/MyNewDirectory');
/*
* third step, create page
* this will generated follow files:
*
* /controller/blog.controller.php
* /render/views/blog.view.php (maybe for the list of all articles)
* /render/views/blog/article.view.php (a single blog post)
*
*/
#$newPage->create();
# you cant get the data with the $view object
# send $this to the view
$this->view = "Hi, i am a view object";
$this->user = "I am a user!";
# or init a model
$this->dir = new HM\Dir('/path_to/MyNewDirectory');
}
}
\ No newline at end of file
......@@ -4,7 +4,7 @@ use HM;
class Controller {
/**
* Generate page with controller and view
* Controller
*
* @description
* https://gitlab.com/mascoda/simple-mvc/wikis/home
......@@ -19,14 +19,10 @@ use HM;
* Constructor
*
* @description
* build the complete page with controller and view
* build controller object on init
*
* @param
* page (string)
* template (string) [optional]
*
* @return
* -
* path (string)
*
*/
function __construct($path)
......@@ -55,36 +51,38 @@ use HM;
}
/*
* @description
* returned the filename
* set filename
*/
public function setFilename() {
$this->filename = $this->name . '.controller.php';
}
/*
* @description
* returned the filepath
* set filepath
*/
public function setFilepath() {
$this->filepath = dirname(__DIR__) . '/controllers/' . $this->name . '.controller.php';
}
/*
* @description
* returned the filepath
* check if controller file exists
*/
public function exists() {
return $exists = realpath($this->filepath) ? TRUE : FALSE;
}
}
/*
* @description
* returned the Actions (array)
* returned the Action
*
* @params
* $viewName (string)
*/
public function getAction($viewname) {
return $viewname . 'Action';
public function getAction($viewName) {
return $viewName . 'Action';
}
/*
* @description
* returned the Actions (array)
* returned namespace (string)
*/
public function getNamespace() {
return 'simpleController\\';
......@@ -111,7 +109,7 @@ use HM;
}
/*
* @description
* create controller action in controller file
* extended controller with a new action
*/
public function createAction($action) {
......
......@@ -5,7 +5,8 @@ use stdClass;
class Manifest {
/**
* Generate page with controller and view
* Manifest is a json file to handle the app
* you will find manifest.json in the simplemvc directory
*
* @description
* https://gitlab.com/mascoda/simple-mvc/wikis/home
......@@ -17,14 +18,7 @@ use stdClass;
* Constructor
*
* @description
* build the complete page with controller and view
*
* @param
* page (string)
* template (string) [optional]
*
* @return
* -
* set the path to the manifest.json
*
*/
function __construct()
......@@ -36,47 +30,29 @@ use stdClass;
/**
* @param
* page (string)
* @desc -
*
* @desc
* returned the manifest.json as array
* @return
* -
* manifest (array)
*
*/
public function get() {
return (new HM\File( $this->path))->getJson(TRUE);
}
/**
* Create pages from manifest
*
* @description
* Create a full page included controller and view by a path
* $page->create('/catalog/product/') will be create files in
* /controller/catalog.controller.php
* /render/views/catalog/catalog.view.php
* /render/views/catalog/product/product.view.php
*
* @param
* page (string)
* @desc -
*
* @return
* -
*
* Create iterativ pages from manifest
* included controller and views
*
*/
public function build() {
$manifest = $this->get();
$this->createPages($manifest['pages']);
}
/**
* @param
* page (string)
* @desc -
*
* @return
* -
*
* createPages for the build function
*
*/
public function createPages($pages) {
private function createPages($pages) {
foreach ($pages as $page) :
......@@ -86,8 +62,7 @@ use stdClass;
// create controller files
if ($controller->exists() === false) :
$controller->createFile();
endif;
endif;
// create views
$view = new View($page['view']['path']);
......@@ -104,8 +79,7 @@ use stdClass;
endif;
// create action by view in controller
$controller->createAction($view->action);
$controller->createAction($view->action);
// if subpages exists
if (is_array($page['sub'])) :
......
......@@ -100,96 +100,4 @@ use stdClass;
return $manifest;
}
/**
* Create a page
*
* @description
* Create a full page included controller and view by a path
* $page->create('/catalog/product/') will be create files in
* /controller/catalog.controller.php
* /render/views/catalog/catalog.view.php
* /render/views/catalog/product/product.view.php
*
* @param
* page (string)
* @desc -
*
* @return
* -
*
*/
public function create() {
$manifestFile = (new HM\File( __DIR__ . '/' . 'manifest.json'));
$manifest = $manifestFile->getJson(TRUE);
}
public function createOLD()
{
// need for subdirectories
$path_to = '';
// get pages of the given path (removed slashes)
$pages = explode('/', rtrim(ltrim($this->page, '/'),'/'));
// create directories for the views recursively
$viewDirectory = new HM\Dir(dirname(dirname(__DIR__) . '/views/' . $this->page));
if (!$viewDirectory->exists()) :
$viewDirectory->create($mode = 0775, $recursive = true);
endif;
// created controller and views
foreach ($pages as $page) :
$controller = new HM\File(dirname(__DIR__) . '/controller/' . $pages[0] .'.controller.php');
// create controller, if not exists,
if (!$controller->exists()) {
# create controller
$defaultController = SRC::getContent('controller', 'default.controller.php');
$search = array('{controllerName}', '{actionName}');
$replace = array($pages[0] . 'Controller', $pages[0]."Action");
$defaultController = str_replace($search, $replace, $defaultController);
$controller->create(0775);
$controller->write($defaultController);
} else {
$controllerContent = $controller->getContent();
# create action, if not exists
if (strpos($controllerContent, $page . 'Action') === false) :
$defaultAction = SRC::getContent('action', 'defaultAction.php');
$defaultAction = str_replace('{actionName}', $page . 'Action', $defaultAction);
$controllerContent = trim(substr($controllerContent, 0, -1));
$controller->write($controllerContent);
$controller->append($defaultAction);
endif;
}
// init a new page
$page = new MVC($page);
// create views
$view = new HM\File(dirname(__DIR__) . '/views/' . $path_to . $page->page . '.view.php');
if (!$view->exists()) :
$view->create(0775);
$view->write(SRC::getContent('views', 'default.view.php'));
endif;
// extend the path for viewfiles
$path_to .= $page->page . '/';
endforeach;
// replace placeholder
#$file->write(str_replace('{TITLE}' , basename($file->path), file_get_contents(dirname(__DIR__) . '/render/template/default.view.php')));
}
}
\ No newline at end of file
{"header":[],"config":[],"pages":{"blog":{"controller":{"name":"blog","action":"blogAction","filename":"blog.controller.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/controllers\/blog.controller.php"},"view":{"name":"blog","path":"blog","filename":"blog.view.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/views\/blog.view.php"},"sub":{"post":{"controller":{"name":"blog","action":"postAction","filename":"blog.controller.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/controllers\/blog.controller.php"},"view":{"name":"post","path":"blog\/post","filename":"post.view.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/views\/blog\/post.view.php"},"sub":[]}}},"shop":{"controller":{"name":"shop","action":"shopAction","filename":"shop.controller.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/controllers\/shop.controller.php"},"view":{"name":"shop","path":"shop","filename":"shop.view.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/views\/shop.view.php"},"sub":{"list":{"controller":{"name":"shop","action":"listAction","filename":"shop.controller.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/controllers\/shop.controller.php"},"view":{"name":"list","path":"shop\/list","filename":"list.view.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/views\/shop\/list.view.php"},"sub":[]}}},"warehouses":{"controller":{"name":"warehouses","action":"warehousesAction","filename":"warehouses.controller.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/controllers\/warehouses.controller.php"},"view":{"name":"warehouses","path":"warehouses","filename":"warehouses.view.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/views\/warehouses.view.php"},"sub":{"deals":{"controller":{"name":"warehouses","action":"dealsAction","filename":"warehouses.controller.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/controllers\/warehouses.controller.php"},"view":{"name":"deals","path":"warehouses\/deals","filename":"deals.view.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/views\/warehouses\/deals.view.php"},"sub":[]},"specials":{"controller":{"name":"warehouses","action":"specialsAction","filename":"warehouses.controller.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/controllers\/warehouses.controller.php"},"view":{"name":"specials","path":"warehouses\/specials","filename":"specials.view.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/views\/warehouses\/specials.view.php"},"sub":[]}}}}}
\ No newline at end of file
{"header":[],"config":[],"pages":{"warehouses":{"controller":{"name":"warehouses","action":"warehousesAction","filename":"warehouses.controller.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/controllers\/warehouses.controller.php"},"view":{"name":"warehouses","path":"warehouses","filename":"warehouses.view.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/views\/warehouses.view.php"},"sub":{"specials":{"controller":{"name":"warehouses","action":"specialsAction","filename":"warehouses.controller.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/controllers\/warehouses.controller.php"},"view":{"name":"specials","path":"warehouses\/specials","filename":"specials.view.php","filepath":"\/kunden\/440535_21147\/webseiten\/warzz.de\/views\/warehouses\/specials.view.php"},"sub":[]}}}}}
\ No newline at end of file
......@@ -12,53 +12,74 @@ class {controllerName} {
}
public function {actionName} ($page) {
$page->title = 'simple-mvc';
$page->template('default');
// send $this to the view
$this->view = "Hi, i am a view object";
$this->user = "I am a user!";
$this->dir = new HM\Dir('/path_to/MyNewDirectory');
$page->title = 'simple-mvc';
$page->template('default');
/* How to create a new page
* create a new page included controller and views
*
* first step, define the page / url
*
/* GET SIMPLE
*
* Add a new pages with simple\Page
*
*/
# create a new path, similar to the url
$url = 'blog';
# !or directly several pages
# $url = 'blog/article/comment/';
$url = "/blog/article";
# create an object of the type page
$newPage = (new simple\Page($url));
# add the new page to you manifest
//$newPage->add();
# !or use the short way
# $pages = new simple\Page($url)->add();
/*
* second step, build a MVC object with the uri as parameter
* !Note: do not use the variable $page to create new pages, this will overwrite the current object
*/
# you new pages now in your manifest, that you find in /simplemvc
# now load your manifest
$manifest = new simple\Manifest();
$newPage = new simple\MVC($url);
/*
* third step, create page
* this will generated follow files:
*
* /controller/blog.controller.php
* /views/blog.view.php (maybe for list of all blog posts)
* /views/blog/article.view.php (a single blog post)
*
*/
# !if you want take a look, you can use
#$this->view = $manifest->get();
# build you added pages by the manifest build method
#$manifest->build();
# now register you new classes in composer
# $ composer dump-autoload -o
# !Congratulations, get a beer
#$newPage->create();
# you can find you new files under /controller and /views
# or the url
# you want read more about simplemvc?
# https://gitlab.com/mascoda/simple-mvc/wikis/home
/*
*
* last steps
* go to you command line interface and register you new classes to composer
/* GET SIMPLE
*
* $ composer dump-autoload -o
* Send data to the view
*
* Congratulations, thats all :-)
*
*/
*/
# you can send data to the view very easy
# send a string to the view
$this->view = "Hi, i am a String";
# or a Model
# $this->dir = new HM\Dir('/path_to/MyNewDirectory');
# you cant get the data with the $view object
# send $this to the view
$this->view = "Hi, i am a view object";
$this->user = "I am a user!";
# or init a model
$this->dir = new HM\Dir('/path_to/MyNewDirectory');
}
}
\ No newline at end of file
......@@ -8,11 +8,8 @@ $baseDir = dirname($vendorDir);
return array(
'HM\\Dir' => $baseDir . '/models/Dir.class.php',
'HM\\File' => $baseDir . '/models/File.class.php',
'simpleController\\blogController' => $baseDir . '/controllers/blog.controller.php',
'simpleController\\indexController' => $baseDir . '/controllers/index.controller.php',
'simpleController\\notFoundController' => $baseDir . '/controllers/notFound.controller.php',
'simpleController\\shopController' => $baseDir . '/controllers/shop.controller.php',
'simpleController\\warehousesController' => $baseDir . '/controllers/warehouses.controller.php',
'simple\\Controller' => $baseDir . '/simplemvc/Controller.class.php',
'simple\\MVC' => $baseDir . '/simplemvc/MVC.class.php',
'simple\\Manifest' => $baseDir . '/simplemvc/Manifest.class.php',
......
......@@ -36,11 +36,8 @@ class ComposerStaticInitc9276e89b85b1a7c62ea9fd02827598c
public static $classMap = array (
'HM\\Dir' => __DIR__ . '/../..' . '/models/Dir.class.php',
'HM\\File' => __DIR__ . '/../..' . '/models/File.class.php',
'simpleController\\blogController' => __DIR__ . '/../..' . '/controllers/blog.controller.php',
'simpleController\\indexController' => __DIR__ . '/../..' . '/controllers/index.controller.php',
'simpleController\\notFoundController' => __DIR__ . '/../..' . '/controllers/notFound.controller.php',
'simpleController\\shopController' => __DIR__ . '/../..' . '/controllers/shop.controller.php',
'simpleController\\warehousesController' => __DIR__ . '/../..' . '/controllers/warehouses.controller.php',
'simple\\Controller' => __DIR__ . '/../..' . '/simplemvc/Controller.class.php',
'simple\\MVC' => __DIR__ . '/../..' . '/simplemvc/MVC.class.php',
'simple\\Manifest' => __DIR__ . '/../..' . '/simplemvc/Manifest.class.php',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment