Namespace autoloading,and unify under 'Meta' namespace

This commit is contained in:
Timothy Warren 2015-08-04 16:45:24 -04:00
parent 4bb6ca9711
commit eee3c1f96e
32 changed files with 116 additions and 275 deletions

55
sys/core/Controller.php → Meta/Base/Controller.php Executable file → Normal file
View File

@ -1,25 +1,23 @@
<?php
/**
* MiniMVC
* meta
*
* Convention-based micro-framework for PHP
* Hierarchial data tool
*
* @package miniMVC
* @package meta
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/aviat4ion/miniMVC
* @copyright Copyright (c) 2012 - 2015
* @link https://github.com/aviat4ion/meta
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
namespace miniMVC;
namespace Meta\Base;
use Meta\Model\Data as Data_Model;
/**
* Base Controller Class
*
* @package miniMVC
* @subpackage System
*/
class Controller {
@ -43,47 +41,16 @@ class Controller {
$this->page = new Page();
}
$this->load_model('meta\data_model');
$db = \miniMVC\db::get_instance();
$this->data_model = new Data_Model();
$db = \Meta\Base\db::get_instance();
$this->page->queries =& $db->queries;
}
// --------------------------------------------------------------------------
/**
* Function for loading a model into the current class
*
* @param string $file
* @param array $args
* @return void
*/
public function load_model($file, $args=array())
{
$segments = explode('\\', $file);
$file_name = end($segments);
// The module is set via the router
$path = MM_APP_PATH . "models/{$file_name}.php";
if (is_file($path))
{
require_once($path);
}
if ( ! empty($args))
{
$this->$file_name = new $file($args);
}
else
{
$this->$file_name = new $file;
}
}
// --------------------------------------------------------------------------
/**
* Function for loading a view
*

15
sys/core/Model.php → Meta/Base/Model.php Executable file → Normal file
View File

@ -1,25 +1,22 @@
<?php
/**
* MiniMVC
* meta
*
* Convention-based micro-framework for PHP
* Hierarchial data tool
*
* @package miniMVC
* @package meta
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/aviat4ion/miniMVC
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/meta
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
namespace miniMVC;
namespace Meta\Base;
/**
* Base Model Class
*
* @package miniMVC
* @subpackage System
*/
class Model extends \ArrayObject {

15
sys/core/Page.php → Meta/Base/Page.php Executable file → Normal file
View File

@ -1,28 +1,25 @@
<?php
/**
* MiniMVC
* meta
*
* Convention-based micro-framework for PHP
* Hierarchial data tool
*
* @package miniMVC
* @package meta
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/aviat4ion/miniMVC
* @copyright Copyright (c) 2012 - 2015
* @link https://github.com/aviat4ion/meta
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
namespace miniMVC;
namespace Meta\Base;
/**
* Class for building pages
*
* All methods are chainable, with the exception of the constructor,
* build_header(), build_footer(), and _headers() methods.
*
* @package miniMVC
* @subpackage System
*/
class Page {

View File

@ -1,65 +1,22 @@
<?php
/**
* MiniMVC
* meta
*
* Convention-based micro-framework for PHP
* Simple hierarchial data management
*
* @package miniMVC
* @package meta
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/aviat4ion/miniMVC
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/meta
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* File including common framework-wide functions
*
* @package miniMVC
* @subpackage System
*/
namespace Meta\Base;
namespace miniMVC;
use \Aura\Router\RouterFactory;
// --------------------------------------------------------------------------
// ! Autoloading
// --------------------------------------------------------------------------
/**
* Function to autoload system libraries
*
* @param string
*/
function autoload($name)
{
if ($name == '') return;
// strip off namespaces - they all go to the same folder
$names = explode('\\', trim($name));
$name = end($names);
// Paths to load from
$sys_path = MM_SYS_PATH . "core/{$name}.php";
$lib_path = MM_SYS_PATH . "libraries/{$name}.php";
$class_path = MM_APP_PATH . "classes/{$name}.php";
if (is_file($sys_path))
{
require_once($sys_path);
}
elseif (is_file($lib_path))
{
require_once($lib_path);
}
if (is_file($class_path))
{
require_once($class_path);
}
}
// --------------------------------------------------------------------------
// ! Messages
// --------------------------------------------------------------------------
@ -144,7 +101,7 @@ function controller_methods($controller)
$methods = \get_class_methods($controller);
// Eliminate methods from Controller and Model classes
$skip_methods = array_merge(\get_class_methods('miniMVC\Controller'), \get_class_methods('miniMVC\Model'));
$skip_methods = array_merge(\get_class_methods('\Meta\Base\Controller'), \get_class_methods('\Meta\Base\Model'));
$methods = array_diff($methods, $skip_methods);
return $methods;
@ -218,19 +175,6 @@ if ( ! function_exists('do_include'))
// ! Bootstrap functions
// --------------------------------------------------------------------------
/**
* Load required classes for bootstraping
*
* @return void
*/
function init()
{
// Map to the appropriate module/controller/function
route();
}
// --------------------------------------------------------------------------
/**
* Returns the last segment of the current url
*
@ -338,32 +282,21 @@ function route()
*/
function run($controller, $func, $args = array())
{
$path = MM_APP_PATH . "controllers/{$controller}.php";
$controller_class = ucfirst($controller);
$controller = "Meta\\Controller\\{$controller_class}";
if (is_file($path))
// Get the list of valid methods for that controller
$methods = controller_methods($controller);
if (in_array($func, $methods))
{
require_once($path);
// Get the list of valid methods for that controller
$methods = controller_methods($controller);
if (in_array($func, $methods))
if (class_exists($controller))
{
// Define the name of the current module for file loading
if ( ! defined('MM_MOD'))
{
define('MM_MOD', 'meta');
}
if (class_exists($controller))
{
$class = new $controller();
}
call_user_func_array(array($class, $func), $args);
return;
$class = new $controller();
}
call_user_func_array(array($class, $func), $args);
return;
}
// Function doesn't exist...404

View File

@ -1,25 +1,23 @@
<?php
/**
* MiniMVC
* meta
*
* Convention-based micro-framework for PHP
* Simple hierarchial data management
*
* @package miniMVC
* @package meta
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/aviat4ion/miniMVC
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/meta
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
namespace miniMVC;
namespace Meta\Base;
/**
* Extend PHP's PDO class to add some more functionality
*
* @package miniMVC
* @subpackage System
*/
class db extends \Query\Query_Builder {
@ -81,7 +79,7 @@ class db extends \Query\Query_Builder {
{
$error = $this->errorInfo();
}
list($code, $driver_code, $message) = $error;
// Contain the content for buffering

View File

@ -13,20 +13,14 @@
// --------------------------------------------------------------------------
namespace Meta\Controller;
/**
* Category controller
*
* @package meta
*/
class category extends \miniMVC\Controller {
/**
* Initialize the Controller
*/
public function __construct()
{
parent::__construct();
}
class Category extends \Meta\Base\Controller {
/**
* Returns the sections / editing options for a category
@ -79,4 +73,4 @@ class category extends \miniMVC\Controller {
}
}
// End of genre.php
// End of category.php

View File

@ -13,12 +13,14 @@
// --------------------------------------------------------------------------
namespace Meta\Controller;
/**
* Genre controller
*
* @package meta
*/
class genre extends \miniMVC\Controller {
class Genre extends \Meta\Base\Controller {
/**
* Default controller method

View File

@ -13,20 +13,14 @@
// --------------------------------------------------------------------------
namespace Meta\Controller;
/**
* Section Controller
*
* @package meta
*/
class section extends \miniMVC\Controller {
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
}
class Section extends \Meta\Base\Controller {
/**
* Default controller method

15
app/models/data_model.php → Meta/Model/Data.php Executable file → Normal file
View File

@ -13,16 +13,13 @@
// --------------------------------------------------------------------------
namespace meta;
use \miniMVC\db;
namespace Meta\Model;
use \Meta\Base\db;
/**
* Main Model for database interaction
*
* @package meta
* Main Model for DB interaction
*/
class data_model extends \miniMVC\Model {
class Data extends \Meta\Base\Model {
/**
* Reference to database connection
@ -695,7 +692,5 @@ class data_model extends \miniMVC\Model {
}
}
}
// End of data_model.php
// End of data.php

4
app/config/config.php → Meta/config/config.php Executable file → Normal file
View File

@ -42,7 +42,7 @@ define('BASE_URL', '//' . $_SERVER['HTTP_HOST'] . '/');
| slash.
|
*/
define('BASE_PATH', 'meta/');
define('BASE_PATH', '');
/*
|--------------------------------------------------------------------------
@ -52,7 +52,7 @@ define('BASE_PATH', 'meta/');
| This determines whether "index.php" is in generated urls
|
*/
define('URL_INDEX_FILE', BASE_PATH . 'index.php/');
define('URL_INDEX_FILE', BASE_PATH . '');
/*
|--------------------------------------------------------------------------

0
app/config/routes.php → Meta/config/routes.php Executable file → Normal file
View File

View File

@ -1,8 +1,8 @@
<p class="breadcrumbs">
<a href="<?= miniMVC\site_url('') ?>">Genres</a> > <a href="<?= miniMVC\site_url('genre/detail/'.$genre['id']) ?>"><?= $genre['genre'] ?></a> > <?= $category ?>
<a href="<?= \Meta\Base\site_url('') ?>">Genres</a> > <a href="<?= \Meta\Base\site_url('genre/detail/'.$genre['id']) ?>"><?= $genre['genre'] ?></a> > <?= $category ?>
</p>
<form class="add" action="<?= miniMVC\site_url("category/add_section") ?>" method="post">
<form class="add" action="<?= \Meta\Base\site_url("category/add_section") ?>" method="post">
<fieldset>
<legend>Add Section</legend>
<dl>
@ -21,7 +21,7 @@
<?php foreach($sections as $id => $section): ?>
<?php if (is_array($section)) list($section, $d) = $section ?>
<li>
<h4><a href="<?= miniMVC\site_url("section/detail/{$id}") ?>"><?= $section ?></a></h4>
<h4><a href="<?= \Meta\Base\site_url("section/detail/{$id}") ?>"><?= $section ?></a></h4>
<span class="modify" data-id="<?= $id ?>" data-type="section" data-parent="<?= $category_id ?>">
<button class="edit">Edit Section</button>
<button class="delete">Delete Section</button>

0
app/views/edit_form.php → Meta/views/edit_form.php Executable file → Normal file
View File

View File

View File

0
app/views/footer.php → Meta/views/footer.php Executable file → Normal file
View File

View File

@ -1,8 +1,8 @@
<p class="breadcrumbs">
<a href="<?= miniMVC\site_url('') ?>">Genres</a> > <?= $genre ?>
<a href="<?= \Meta\Base\site_url('') ?>">Genres</a> > <?= $genre ?>
</p>
<form class="add" action="<?= miniMVC\site_url("genre/add_category") ?>" method="post">
<form class="add" action="<?= \Meta\Base\site_url("genre/add_category") ?>" method="post">
<fieldset>
<legend>Add Category</legend>
<dl>
@ -19,7 +19,7 @@
<ul class="list">
<?php foreach($categories as $id => $cat): ?>
<li>
<a href="<?= miniMVC\site_url("category/detail/{$id}") ?>"><?= $cat ?></a>
<a href="<?= \Meta\Base\site_url("category/detail/{$id}") ?>"><?= $cat ?></a>
<span class="modify" data-type="category" data-id="<?=$id ?>" data-parent="<?=$genre_id ?>">
<button class="edit">Edit Category</button>
<button class="delete">Delete Category</button>

4
app/views/genres.php → Meta/views/genres.php Executable file → Normal file
View File

@ -1,6 +1,6 @@
<p class="breadcrumbs">Genres</p>
<form class="add" action="<?= miniMVC\site_url("genre/add") ?>" method="post">
<form class="add" action="<?= Meta\Base\site_url("genre/add") ?>" method="post">
<fieldset>
<legend>Add Genre</legend>
<dl>
@ -18,7 +18,7 @@
<ul class="list">
<?php foreach($genres as $id => $name): ?>
<li>
<a href="<?= miniMVC\site_url("genre/detail/{$id}") ?>">
<a href="<?= Meta\Base\site_url("genre/detail/{$id}") ?>">
<?= $name ?>
</a>
<span class="modify" data-id="<?= $id ?>" data-type="genre" data-parent="<?=$id ?>">

0
app/views/header.php → Meta/views/header.php Executable file → Normal file
View File

0
app/views/message.php → Meta/views/message.php Executable file → Normal file
View File

6
app/views/outline.php → Meta/views/outline.php Executable file → Normal file
View File

@ -20,7 +20,7 @@
<!-- Genres -->
<?php foreach($genre_array as $genre => $cat_array): ?>
<dt>
<a href="<?= \miniMVC\site_url("genre/detail/{$genre_id}") ?>"><?= $genre ?></a>
<a href="<?= \Meta\Base\site_url("genre/detail/{$genre_id}") ?>"><?= $genre ?></a>
</dt>
<dd>
@ -29,14 +29,14 @@
<!-- Categories -->
<?php foreach($cname_array as $category => $sect_array): ?>
<li>
<a href="<?= \miniMVC\site_url("category/detail/{$cat_id}") ?>"><?= $category ?></a>
<a href="<?= \Meta\Base\site_url("category/detail/{$cat_id}") ?>"><?= $category ?></a>
<?php if ( ! empty($sect_array)): ?>
<ul>
<!-- Sections -->
<?php foreach($sect_array as $section_id => $section): ?>
<li>
<a href="<?= \miniMVC\site_url("section/detail/{$section_id}") ?>">
<a href="<?= \Meta\Base\site_url("section/detail/{$section_id}") ?>">
<?= $section ?>
</a>
</li>

View File

@ -1,10 +1,10 @@
<p class="breadcrumbs">
<a href="<?= miniMVC\site_url('') ?>">Genres</a> >
<a href="<?= miniMVC\site_url('genres/detail/'.$p['genre_id']) ?>"><?= $p['genre'] ?></a> >
<a href="<?= miniMVC\site_url('category/detail/'.$p['category_id']) ?>"><?= $p['category'] ?></a> >
<a href="<?= \Meta\Base\site_url('') ?>">Genres</a> >
<a href="<?= \Meta\Base\site_url('genres/detail/'.$p['genre_id']) ?>"><?= $p['genre'] ?></a> >
<a href="<?= \Meta\Base\site_url('category/detail/'.$p['category_id']) ?>"><?= $p['category'] ?></a> >
<?= $section ?>
</p>
<form class="add" action="<?= miniMVC\site_url("section/add_data") ?>" method="post" onsubmit="window.edit_wysiwyg.toggle()">
<form class="add" action="<?= \Meta\Base\site_url("section/add_data") ?>" method="post" onsubmit="window.edit_wysiwyg.toggle()">
<fieldset>
<legend>Add Data</legend>
<dl>
@ -13,7 +13,7 @@
<input type="text" name="name[]" id="section" /></dd>
<dt><label for="val">Value:</label></dt><dd>
<textarea id="val" name="val[]" rows="5" cols="40"></textarea></dd>
<textarea id="val2" name="val[]" rows="5" cols="40"></textarea></dd>
<dt><input type="hidden" name="section_id" value="<?= $section_id ?>" /></dt><dd>
<button type="submit" class="save">Save Data</button></dd>

View File

View File

@ -0,0 +1,6 @@
<script type="text/javascript">
var APP_URL = '<?= \Meta\Base\site_url(''); ?>';
var ASSET_URL = APP_URL.replace('index.php/', '') + '/assets/';
</script>
<h1><a href="<?= \Meta\Base\site_url('') ?>">Meta</a></h1>
<span id="outline">[<a href="<?= \Meta\Base\site_url('outline')?>">Data Outline</a>]</span>

View File

@ -1,37 +0,0 @@
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @package miniMVC
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/aviat4ion/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Database config file
*
* @package miniMVC
* @subpackage App
*/
// --------------------------------------------------------------------------
$db_conf = array(
'default' => array(
'type' => 'sqlite',
'host' => '',
'user' => '',
'pass' => '',
'port' => '',
'database' => '',
'file' => MM_SYS_PATH . 'meta.sqlite',
)
);
// End of db.php

View File

@ -1,6 +0,0 @@
<script type="text/javascript">
var APP_URL = '<?= \miniMVC\site_url(''); ?>';
var ASSET_URL = APP_URL.replace('index.php/', '') + '/assets/';
</script>
<h1><a href="<?= miniMVC\site_url('') ?>">Meta</a></h1>
<span id="outline">[<a href="<?= miniMVC\site_url('outline')?>">Data Outline</a>]</span>

View File

@ -226,5 +226,6 @@ $_.ext('center', function (sel){
if (document.getElementsByTagName('textarea').length > 0)
{
meta.initTINY('val');
meta.initTINY('val2');
}
}(window, $_));

View File

@ -2,6 +2,7 @@
"require": {
"filp/whoops": "1.1.*",
"aura/router": "2.2.*",
"aviat4ion/query": "2.0.*"
"aura/web": "2.0.*",
"aviat4ion/query": "*"
}
}

View File

@ -1,28 +1,22 @@
<?php
/**
* MiniMVC
* meta
*
* Convention-based micro-framework for PHP
* Simple hierarchial data management
*
* @package miniMVC
* @package meta
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/aviat4ion/miniMVC
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/meta
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* miniMVC bootstrap file
*
* @package miniMVC
* @subpackage App
*/
namespace Meta\Base;
// --------------------------------------------------------------------------
namespace miniMVC;
use \Whoops\Handler\PrettyPageHandler;
use \Whoops\Handler\JsonResponseHandler;
@ -31,8 +25,8 @@ error_reporting(-1);
// Set the default paths
define('MM_BASE_PATH', __DIR__);
define('MM_SYS_PATH', __DIR__.'/sys/');
define('MM_APP_PATH', __DIR__.'/app/');
define('MM_SYS_PATH', __DIR__.'/Meta/Base/');
define('MM_APP_PATH', __DIR__.'/Meta/');
// Autoload vendors
require(MM_BASE_PATH . '/vendor/autoload.php');
@ -46,13 +40,24 @@ $whoops->register();
// Require the basic configuration file
require(MM_APP_PATH . 'config/config.php');
// Start the autoloader
spl_autoload_register(function($name) {
if ($name == '') return;
// load by namespace
$names = explode('\\', trim($name));
$ns_path = MM_BASE_PATH . '/' . implode('/', $names) . '.php';
if (is_file($ns_path))
{
require_once($ns_path);
}
});
// Require the most important files
require(MM_SYS_PATH . 'common.php');
// Start the autoloader
spl_autoload_register('miniMVC\autoload');
// And away we go!
init();
route();
// End of index.php

View File

@ -11,14 +11,8 @@
<template name="responsive" />
</transformations>
<files>
<directory>.</directory>
<directory>app/modules/</directory>
<ignore>tests/*</ignore>
<ignore>assets/*</ignore>
<ignore>vendor/*</ignore>
<ignore>sys/db/*</ignore>
<ignore>app/config/*</ignore>
<ignore>app/views/*</ignore>
<ignore>*/views/*</ignore>
<directory>Meta/*</directory>
<ignore>Meta/views/*</ignore>
<ignore>Meta/config/*</ignore>
</files>
</phpdoc>