initial commit
This commit is contained in:
commit
f2ff442d8a
21 changed files with 1559 additions and 0 deletions
105
library/Katharsis/Controller/Abstract.php
Normal file
105
library/Katharsis/Controller/Abstract.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/**
|
||||
* Abstract Controller
|
||||
* All controllers must extend this class.
|
||||
*
|
||||
* @author Karl Pannek <info@katharsis.in>
|
||||
* @version 0.5.2
|
||||
* @package Katharsis
|
||||
*/
|
||||
abstract class Katharsis_Controller_Abstract
|
||||
{
|
||||
/**
|
||||
* @var Katharsis_Db5
|
||||
*/
|
||||
protected $_con;
|
||||
|
||||
/**
|
||||
* @var Katharsis_View
|
||||
*/
|
||||
protected $_view;
|
||||
|
||||
/**
|
||||
* Instances class attributes, calles init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public final function __construct()
|
||||
{
|
||||
$this->_con = Katharsis_DatabaseConnector::getConnection();
|
||||
$this->_view = Katharsis_View::getInstance();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite this method instead of using a constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* If subclass hasn't got a __call method, this exception will be thrown
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __call($action, $params)
|
||||
{
|
||||
throw new Katharsis_Exception('Action "' . $action . '" doesn\'t exist.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specific request parameter
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _getParam($key)
|
||||
{
|
||||
$params = Katharsis_Request::getParams();
|
||||
if(array_key_exists($key,$params))
|
||||
{
|
||||
return $params[$key];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all request parameters
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _getAllParams()
|
||||
{
|
||||
return Katharsis_Request::getParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward to an other action
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $controller
|
||||
* @param array $getParams
|
||||
* @return void
|
||||
*/
|
||||
protected function _location($action, $controller = null, $getParams = null)
|
||||
{
|
||||
if($controller === null)
|
||||
{
|
||||
$controller = Katharsis_Request::getControllerName();
|
||||
}
|
||||
|
||||
$paramstring = "";
|
||||
if($getParams !== null)
|
||||
{
|
||||
foreach($getParams as $key => $value)
|
||||
{
|
||||
$paramstring .= "/" . (string) $key . "/" . (string) $value;
|
||||
}
|
||||
}
|
||||
|
||||
header("location: " . $this->_view->base . "/" . $controller . "/" . $action . $paramstring);
|
||||
}
|
||||
}
|
53
library/Katharsis/Controller/Plugin.php
Normal file
53
library/Katharsis/Controller/Plugin.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* Central Plugin Class
|
||||
*
|
||||
* @author Karl Pannek <info@katharsis.in>
|
||||
* @version 0.5.2
|
||||
* @package Katharsis
|
||||
*/
|
||||
class Katharsis_Controller_Plugin
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $_plugins;
|
||||
|
||||
/**
|
||||
* Register all plugins with this method
|
||||
* Plugins will be called in the same order as they have been registered
|
||||
*
|
||||
* @param object $object - an instance of your plugin
|
||||
* @return void
|
||||
*/
|
||||
public static function registerPlugin($object)
|
||||
{
|
||||
self::$_plugins[] = $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes preController methods of all plugins
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function preControllerHook()
|
||||
{
|
||||
foreach(self::$_plugins as $plugin)
|
||||
{
|
||||
$plugin->preController();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes postController methods of all plugins
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function postControllerHook()
|
||||
{
|
||||
foreach(self::$_plugins as $plugin)
|
||||
{
|
||||
$plugin->postController();
|
||||
}
|
||||
}
|
||||
}
|
31
library/Katharsis/Controller/Plugin/Abstract.php
Normal file
31
library/Katharsis/Controller/Plugin/Abstract.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* Abstract Controller Plugin
|
||||
* All controller plugins must extend this class.
|
||||
*
|
||||
* @author Karl Pannek <info@katharsis.in>
|
||||
* @version 0.5.2
|
||||
* @package Katharsis
|
||||
*/
|
||||
abstract class Katharsis_Controller_Plugin_Abstract
|
||||
{
|
||||
/**
|
||||
* Overwrite this method, if you want something to be processed
|
||||
* _before_ the controller is called
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preController()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite this method, if you want something to be processed
|
||||
* _after_ the controller was called
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postController()
|
||||
{
|
||||
}
|
||||
}
|
32
library/Katharsis/Controller/Plugin/Autorender.php
Normal file
32
library/Katharsis/Controller/Plugin/Autorender.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* Autorender Controller Plugin
|
||||
*
|
||||
* @author Karl Pannek <info@katharsis.in>
|
||||
* @version 0.5.2
|
||||
* @package Katharsis
|
||||
*/
|
||||
class Katharsis_Controller_Plugin_Autorender extends Katharsis_Controller_Plugin_Abstract
|
||||
{
|
||||
/**
|
||||
* Renders a controller/action.phtml template automaticly after processing controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postController()
|
||||
{
|
||||
$view = Katharsis_View::getInstance();
|
||||
|
||||
$view->controllerAction = false;
|
||||
|
||||
$templateName = strtolower(Katharsis_Request::getControllerName()) . DIRECTORY_SEPARATOR . strtolower(Katharsis_Request::getActionName());
|
||||
|
||||
if(file_exists('application/view' . DIRECTORY_SEPARATOR . $templateName . '.phtml'))
|
||||
{
|
||||
$view->controllerAction = $templateName;
|
||||
}
|
||||
|
||||
$view = Katharsis_View::getInstance();
|
||||
echo $view->render('main');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue