Skip to content
This repository has been archived by the owner on Feb 20, 2020. It is now read-only.

Start of a new, more "vendor-friendly" version. #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ Desktop.ini
*.log
Uploads
Storage
Config
!Config/Sample.*.php
45 changes: 11 additions & 34 deletions Bootstrap.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
<?php
/**
* Bootstrap
*
* This file contains initialization code run immediately after system startup.
* Setup i18n and l10n handling, configure system, prepare event hooks.
*
* @package MicroMVC
* @author David Pennington
* @copyright (c) 2010 MicroMVC Framework
* @license http://micromvc.com/license
********************************** 80 Columns *********************************
*/

// System Start Time
define('START_TIME', microtime(true));
Expand All @@ -22,10 +10,10 @@
define('EXT', '.php');

// Directory separator (Unix-Style works on all OS)
define('DS', '/');
//define('DS', '/');

// Absolute path to the system folder
define('SP', realpath(__DIR__). DS);
define('SP', realpath(__DIR__). '/');

// Is this an AJAX request?
define('AJAX_REQUEST', strtolower(getenv('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest');
Expand All @@ -34,29 +22,20 @@
define('DOMAIN', (strtolower(getenv('HTTPS')) == 'on' ? 'https' : 'http') . '://'
. getenv('HTTP_HOST') . (($p = getenv('SERVER_PORT')) != 80 AND $p != 443 ? ":$p" : ''));

// The current site path
define('PATH', parse_url(getenv('REQUEST_URI'), PHP_URL_PATH));

// Include common system functions
require(SP . 'Common' . EXT);
// Get the current URL path (only)
define('PATH', rawurldecode(trim(parse_url(getenv('REQUEST_URI'), PHP_URL_PATH), '/')));

// Register events
foreach(config()->events as $event => $class)
{
event($event, NULL, $class);
}
// Load the common functions (used next)
require(SP . 'MicroMVC.php');

/*
if(preg_match_all('/[\-a-z]{2,}/i', getenv('HTTP_ACCEPT_LANGUAGE'), $locales))
{
$locales = $locales[0];
}
*/
* Default Locale Settings
*/

// Get locale from user agent
if(isset($_COOKIE['lang']))
{
$preference = $_COOKIE['lang'];
$preference = (string) $_COOKIE['lang'];
}
else
{
Expand All @@ -80,7 +59,5 @@
// multibyte encoding
mb_internal_encoding('UTF-8');

// Enable global error handling
set_error_handler(array('\Core\Error', 'handler'));
register_shutdown_function(array('\Core\Error', 'fatal'));

// Disable SimpleXML/DOM error output
libxml_use_internal_errors(true);
2 changes: 1 addition & 1 deletion CLI
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ try
}
catch (Exception $e)
{
\Core\Error::exception($e);
\Micro\Error::exception($e);
}

// End
32 changes: 20 additions & 12 deletions Class/MyController.php → Class/Example/Controller.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* MyController
* Controller
*
* Basic DEMO outline for standard controllers
*
Expand All @@ -10,19 +10,27 @@
* @license http://micromvc.com/license
********************************** 80 Columns *********************************
*/
abstract class MyController extends \Core\Controller
namespace Example;

abstract class Controller extends \Controller
{
// Global view template
public $template = 'Layout';
public $template = 'Example/Layout';

/**
* Called after the controller is loaded, before the method
*
* @param string $method name
*/
public function initialize($method)
public function before($method)
{
\Core\Session::start();
\View::$path = SP . 'View/';

// Enable global error handling
set_error_handler(array('\Micro\Error', 'handler'));
register_shutdown_function(array('\Micro\Error', 'fatal'));

\Micro\Session::start();
}


Expand All @@ -32,12 +40,12 @@ public function initialize($method)
public function load_database($name = 'database')
{
// Load database
$db = new \Core\Database(config()->$name);
$db = new \Micro\Database(config()->$name);

// Set default ORM database connection
if(empty(\Core\ORM::$db))
if(empty(\Micro\ORM::$db))
{
\Core\ORM::$db = $db;
\Micro\ORM::$db = $db;
}

return $db;
Expand All @@ -50,7 +58,7 @@ public function load_database($name = 'database')
public function show_404()
{
headers_sent() OR header('HTTP/1.0 404 Page Not Found');
$this->content = new \Core\View('404');
print new \View('Example/404');
}


Expand All @@ -59,19 +67,19 @@ public function show_404()
*/
public function send()
{
\Core\Session::save();
\Micro\Session::save();

headers_sent() OR header('Content-Type: text/html; charset=utf-8');

$layout = new \Core\View($this->template);
$layout = new \Micro\View($this->template);
$layout->set((array) $this);
print $layout;

$layout = NULL;

if(config()->debug_mode)
{
print new \Core\View('System/Debug');
print new \Micro\View('System/Debug');
}
}

Expand Down
14 changes: 4 additions & 10 deletions Class/Controller/Index.php → Class/Example/Controller/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@
* @license http://micromvc.com/license
********************************** 80 Columns *********************************
*/
namespace Controller;
namespace Example\Controller;

class Index extends \MyController
class Index extends \Example\Controller
{
public function run()
{
// Load database
//$this->db = new DB(config('database'));

// Set ORM database connection
//ORM::$db = $this->db;

// Load the theme sidebar since we don't need the full page
$this->sidebar = new \Core\View('Sidebar');
$this->sidebar = new \Micro\View('Example/Sidebar');

// Load the welcome view
$this->content = new \Core\View('Index/Index');
$this->content = new \Micro\View('Example/Index');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* @license http://micromvc.com/license
********************************** 80 Columns *********************************
*/
namespace Controller;
namespace Example\Controller;

class Page404 extends \MyController
class Page404 extends \Example\Controller
{
public function run()
public function index()
{
$this->show_404();
}
Expand Down
26 changes: 13 additions & 13 deletions Class/Controller/School.php → Class/Example/Controller/School.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
* @license http://micromvc.com/license
********************************** 80 Columns *********************************
*/
namespace Controller;
namespace Example\Controller;

class School extends \MyController
class School extends \Example\Controller
{

public function run()
Expand All @@ -24,24 +24,24 @@ public function run()
// Model_Name::$db = new DB(config('other_database'));

// New Dorm
$d = new \Model\Dorm();
$d = new \Example\Model\Dorm();
$d->name = 'Dorm 1';
$d->save();

// New Student in Dorm
$s1 = new \Model\Student();
$s1 = new \Example\Model\Student();
$s1->name = 'Mary';
$s1->dorm_id = $d->id;
$s1->save();

// New Student in Dorm
$s2 = new \Model\Student();
$s2 = new \Example\Model\Student();
$s2->name = 'Jane';
$s2->dorm_id = $d->id;
$s2->save();

// New Car for student
$c = new \Model\Car();
$c = new \Example\Model\Car();
$c->name = 'Truck';
$c->student_id = $s1->id;
$c->save(); // Insert
Expand All @@ -50,25 +50,25 @@ public function run()
$c->save(); // Update

// New Softball club
$c = new \Model\Club();
$c = new \Example\Model\Club();
$c->name = 'Softball';
$c->save();

// Mary is in softball
$m = new \Model\Membership();
$m = new \Example\Model\Membership();
$m->club_id = $c->id;
$m->student_id = $s1->id;
$m->save();

// Jane is in softball
$m = new \Model\Membership();
$m = new \Example\Model\Membership();
$m->club_id = $c->id;
$m->student_id = $s2->id;
$m->save();

$this->content = dump('Created school objects');

$clubs = \Model\Club::fetch();
$clubs = \Example\Model\Club::fetch();
foreach($clubs as $club)
{
$club->load();
Expand All @@ -88,7 +88,7 @@ public function run()
$club->delete();
}

foreach(\Model\Dorm::fetch() as $dorm)
foreach(\Example\Model\Dorm::fetch() as $dorm)
{
$this->content .= dump('Removing the '. $dorm->name. ' dorm');
$dorm->delete(); // Delete the dorm
Expand All @@ -97,10 +97,10 @@ public function run()
$this->content .= dump('Removed school objects');

// Load the view file
$this->content .= new \Core\View('School/Index');
$this->content .= new \Micro\View('Example/School');

// Load global theme sidebar
$this->sidebar = new \Core\View('Sidebar');
$this->sidebar = new \Micro\View('Example/Sidebar');

}
}
Expand Down
6 changes: 3 additions & 3 deletions Class/Model/Car.php → Class/Example/Model/Car.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
* @license http://micromvc.com/license
********************************** 80 Columns *********************************
*/
namespace Model;
namespace Example\Model;

class Car extends \Core\ORM
class Car extends \Micro\ORM
{
public static $table = 'car';
public static $foreign_key = 'car_id';

public static $belongs_to = array(
'student' => '\Model\Student',
'student' => '\Example\Model\Student',
);

}
10 changes: 5 additions & 5 deletions Class/Model/Club.php → Class/Example/Model/Club.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
* @license http://micromvc.com/license
********************************** 80 Columns *********************************
*/
namespace Model;
namespace Example\Model;

class Club extends \Core\ORM
class Club extends \Micro\ORM
{
public static $table = 'club';
public static $foreign_key = 'club_id';

public static $has = array(
'memberships' => '\Model\Membership'
'memberships' => '\Example\Model\Membership'
);

public static $has_many_through = array(
'students' => array(
'club_id' => '\Model\Membership',
'student_id' => '\Model\Student'
'club_id' => '\Example\Model\Membership',
'student_id' => '\Example\Model\Student'
),
);
}
6 changes: 3 additions & 3 deletions Class/Model/Dorm.php → Class/Example/Model/Dorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
* @license http://micromvc.com/license
********************************** 80 Columns *********************************
*/
namespace Model;
namespace Example\Model;

class Dorm extends \Core\ORM
class Dorm extends \Micro\ORM
{
public static $table = 'dorm';
public static $foreign_key = 'dorm_id';

public static $has = array(
'students' => '\Model\Student',
'students' => '\Example\Model\Student',
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
* @license http://micromvc.com/license
********************************** 80 Columns *********************************
*/
namespace Model;
namespace Example\Model;

class Membership extends \Core\ORM
class Membership extends \Micro\ORM
{
public static $table = 'membership';
public static $foreign_key = 'membership_id';

public static $belongs_to = array(
'student' => '\Model\Student',
'club' => '\Model\Club',
'student' => '\Example\Model\Student',
'club' => '\Example\Model\Club',
);
}
Loading