Commit 1912e06f authored by Webserver User's avatar Webserver User

1.0.3

parent 617906ec
# 1.0.0
## notes
Initial commit simple-mvc
Perhaps the simplest and easiest MVC framework in the world.
## added
* complete framework
## fixed
-
## removed
-
\ No newline at end of file
MIT License
Copyright (c) 2019 Heiko Mettelsiefen
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.
...@@ -6,9 +6,10 @@ Perhaps the simplest and easiest PHP MVC framework in the world. ...@@ -6,9 +6,10 @@ Perhaps the simplest and easiest PHP MVC framework in the world.
* tidy, easy to understand and easy to use * tidy, easy to understand and easy to use
* strict separation between code and view * strict separation between code and view
* supports composer, just load what you need * supports composer, just load what you need
* page creator, create pages with controller and view fully automatically and iteratively
# next features # next features
* page creator, create pages with controller and view fully automatically and iteratively
# documenation # documenation
https://gitlab.com/mascoda/simple-mvc/wikis/home https://gitlab.com/mascoda/simple-mvc/wikis/home
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"HM\\":"classes/" "HM\\":"models/",
"simple\\":"simplemvc/"
} }
} }
} }
<?
$page->title = 'console';
$page->template('custom');
/* How to create a new page
* create a new page included controller and views
*
* first step, define the page / url
*
*/
$url = "/items/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 HM\MVC($url);
/*
* 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();
<? <?
$page->title = 'simple-mvc'; $page->title = 'simple-mvc';
$page->template('default'); $page->template('custom');
/* How to create a new page /* How to create a new page
...@@ -9,12 +9,12 @@ $page->template('default'); ...@@ -9,12 +9,12 @@ $page->template('default');
* first step, define the page / url * first step, define the page / url
* *
*/ */
$url = "/items/item"; $url = "/catalog/list/item";
/* /*
* second step, build a MVC object with the uri as parameter * 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 * !Note: do not use the variable $page to create new pages, this will overwrite the current object
*/ */
$newPage = new HM\MVC($url); $newPage = new simple\MVC($url);
/* /*
* third step, create page * third step, create page
...@@ -25,4 +25,5 @@ $newPage = new HM\MVC($url); ...@@ -25,4 +25,5 @@ $newPage = new HM\MVC($url);
* /render/views/blog/article.view.php (a single blog post) * /render/views/blog/article.view.php (a single blog post)
* *
*/ */
#$newPage->create(); # $newPage->create();
\ No newline at end of file
...@@ -3,7 +3,7 @@ require __DIR__ . '/globals/header.php'; ...@@ -3,7 +3,7 @@ require __DIR__ . '/globals/header.php';
require __DIR__ . '/globals/settings.php'; require __DIR__ . '/globals/settings.php';
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
$page = new HM\MVC($_SERVER["SCRIPT_URL"]); $page = new simple\MVC($_SERVER["SCRIPT_URL"]);
# show info about the $page object # show info about the $page object
# var_dump($page); # var_dump($page);
......
<main role="main" class="flex-shrink-0">
<div class="container">
<h1 class="mt-5">console.view.php</h1>
<p class="lead">Console: </p>
<p class="card"><pre><? var_dump($newPage) ?></pre></p>
</div>
</main>
<? <?
namespace HM; namespace simple;
use HM;
class MVC { class MVC {
/** /**
...@@ -32,11 +33,11 @@ namespace HM; ...@@ -32,11 +33,11 @@ namespace HM;
function __construct($page, $template = 'default') function __construct($page, $template = 'default')
{ {
$this->page($page); $this->page($page);
$this->controller(); $this->controller();
$this->template($template); $this->template($template);
$this->view(); $this->view();
} }
/* /*
* Page * Page
...@@ -53,10 +54,10 @@ namespace HM; ...@@ -53,10 +54,10 @@ namespace HM;
*/ */
private function page($page) private function page($page)
{ {
# define page from the uri # define page from the uri
$page = rtrim($page, '/'); $page = rtrim($page, '/');
$this->page = ($page === '') ? 'index' : $page; $this->page = ($page === '') ? 'index' : $page;
} }
/** /**
* Controller * Controller
* *
...@@ -73,9 +74,9 @@ namespace HM; ...@@ -73,9 +74,9 @@ namespace HM;
*/ */
private function controller() private function controller()
{ {
# define the first directory from path as controller # define the first directory from path as controller
$controller = array_shift(array_filter(explode('/', $this->page))); $controller = array_shift(array_filter(explode('/', $this->page)));
$this->controller = realpath(dirname(__DIR__) . '/controller/' . $controller .'.controller.php'); $this->controller = realpath(dirname(__DIR__) . '/controller/' . $controller .'.controller.php');
} }
/** /**
* View * View
...@@ -97,8 +98,8 @@ namespace HM; ...@@ -97,8 +98,8 @@ namespace HM;
*/ */
private function view() private function view()
{ {
# create the template # create the template
$this->view = realpath(dirname(__DIR__) . '/render/views/' . $this->page . '.view.php'); $this->view = realpath(dirname(__DIR__) . '/render/views/' . $this->page . '.view.php');
} }
/** /**
* View * View
...@@ -116,8 +117,8 @@ namespace HM; ...@@ -116,8 +117,8 @@ namespace HM;
*/ */
public function template($template) public function template($template)
{ {
# create the template # create the template
$this->template = dirname(__DIR__) . '/render/template/' . $template .'.template.php'; $this->template = dirname(__DIR__) . '/render/template/' . $template .'.template.php';
} }
/** /**
...@@ -141,44 +142,44 @@ namespace HM; ...@@ -141,44 +142,44 @@ namespace HM;
public function create() public function create()
{ {
// need for subdirectories // need for subdirectories
$path_to = ''; $path_to = '';
// get pages of the given path (removed slashes) // get pages of the given path (removed slashes)
$pages = explode('/', rtrim(ltrim($this->page, '/'),'/')); $pages = explode('/', rtrim(ltrim($this->page, '/'),'/'));
// create directories for the views recursively // create directories for the views recursively
$viewDirectory = new Dir(dirname(dirname(__DIR__) . '/render/views/' . $this->page)); $viewDirectory = new HM\Dir(dirname(dirname(__DIR__) . '/render/views/' . $this->page));
if (!$viewDirectory->exists()) : if (!$viewDirectory->exists()) :
$viewDirectory->create($mode = 0775, $recursive = true); $viewDirectory->create($mode = 0775, $recursive = true);
endif; endif;
// created controller and views // created controller and views
foreach ($pages as $page) : foreach ($pages as $page) :
// init a new page // init a new page
$page = new MVC($page); $page = new MVC($page);
// create controller // create controller
$controller = new File(dirname(__DIR__) . '/controller/' . $page->page .'.controller.php'); $controller = new HM\File(dirname(__DIR__) . '/controller/' . $page->page .'.controller.php');
if (!$controller->exists()) : if (!$controller->exists()) :
$controller->write(SRC::getContent('controller', 'default.controller.php')); $controller->write(SRC::getContent('controller', 'default.controller.php'));
endif; endif;
// create views // create views
$view = new File(dirname(__DIR__) . '/render/views/' . $path_to . $page->page . '.view.php'); $view = new HM\File(dirname(__DIR__) . '/render/views/' . $path_to . $page->page . '.view.php');
if (!$view->exists()) : if (!$view->exists()) :
$view->create($mode = 0755); $view->create($mode = 0755);
$view->write(SRC::getContent('views', 'default.view.php')); $view->write(SRC::getContent('views', 'default.view.php'));
endif; endif;
// extend the path for viewfiles // extend the path for viewfiles
$path_to .= $page->page . '/'; $path_to .= $page->page . '/';
endforeach; endforeach;
// replace placeholder // replace placeholder
#$file->write(str_replace('{TITLE}' , basename($file->path), file_get_contents(dirname(__DIR__) . '/render/template/default.view.php'))); #$file->write(str_replace('{TITLE}' , basename($file->path), file_get_contents(dirname(__DIR__) . '/render/template/default.view.php')));
} }
} }
\ No newline at end of file
<? <?
namespace HM; namespace simple;
class SRC { class SRC {
/** /**
......
...@@ -6,8 +6,8 @@ $vendorDir = dirname(dirname(__FILE__)); ...@@ -6,8 +6,8 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
'HM\\Dir' => $baseDir . '/classes/Dir.class.php', 'HM\\Dir' => $baseDir . '/models/Dir.class.php',
'HM\\File' => $baseDir . '/classes/File.class.php', 'HM\\File' => $baseDir . '/models/File.class.php',
'HM\\MVC' => $baseDir . '/classes/MVC.class.php', 'simple\\MVC' => $baseDir . '/simplemvc/MVC.class.php',
'HM\\SRC' => $baseDir . '/classes/SRC.class.php', 'simple\\SRC' => $baseDir . '/simplemvc/SRC.class.php',
); );
...@@ -6,5 +6,6 @@ $vendorDir = dirname(dirname(__FILE__)); ...@@ -6,5 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
'HM\\' => array($baseDir . '/classes'), 'simple\\' => array($baseDir . '/simplemvc'),
'HM\\' => array($baseDir . '/models'),
); );
...@@ -7,6 +7,10 @@ namespace Composer\Autoload; ...@@ -7,6 +7,10 @@ namespace Composer\Autoload;
class ComposerStaticInitc9276e89b85b1a7c62ea9fd02827598c class ComposerStaticInitc9276e89b85b1a7c62ea9fd02827598c
{ {
public static $prefixLengthsPsr4 = array ( public static $prefixLengthsPsr4 = array (
's' =>
array (
'simple\\' => 7,
),
'H' => 'H' =>
array ( array (
'HM\\' => 3, 'HM\\' => 3,
...@@ -14,17 +18,21 @@ class ComposerStaticInitc9276e89b85b1a7c62ea9fd02827598c ...@@ -14,17 +18,21 @@ class ComposerStaticInitc9276e89b85b1a7c62ea9fd02827598c
); );
public static $prefixDirsPsr4 = array ( public static $prefixDirsPsr4 = array (
'simple\\' =>
array (
0 => __DIR__ . '/../..' . '/simplemvc',
),
'HM\\' => 'HM\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/classes', 0 => __DIR__ . '/../..' . '/models',
), ),
); );
public static $classMap = array ( public static $classMap = array (
'HM\\Dir' => __DIR__ . '/../..' . '/classes/Dir.class.php', 'HM\\Dir' => __DIR__ . '/../..' . '/models/Dir.class.php',
'HM\\File' => __DIR__ . '/../..' . '/classes/File.class.php', 'HM\\File' => __DIR__ . '/../..' . '/models/File.class.php',
'HM\\MVC' => __DIR__ . '/../..' . '/classes/MVC.class.php', 'simple\\MVC' => __DIR__ . '/../..' . '/simplemvc/MVC.class.php',
'HM\\SRC' => __DIR__ . '/../..' . '/classes/SRC.class.php', 'simple\\SRC' => __DIR__ . '/../..' . '/simplemvc/SRC.class.php',
); );
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
......
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