create slim app and add hook for setting up routes

This commit is contained in:
Uwe Steinmann 2018-09-29 15:59:11 +02:00
parent 6b11e9cb87
commit ca84e27e47
2 changed files with 72 additions and 0 deletions

View File

@ -43,6 +43,7 @@ class SeedDMS_ExtExample extends SeedDMS_ExtBase {
* $GLOBALS['SEEDDMS_HOOKS'] : all hooks added so far
*/
function init() { /* {{{ */
$GLOBALS['SEEDDMS_HOOKS']['initDMS'][] = new SeedDMS_ExtExample_InitDMS;
$GLOBALS['SEEDDMS_HOOKS']['view']['addDocument'][] = new SeedDMS_ExtExample_AddDocument;
$GLOBALS['SEEDDMS_HOOKS']['view']['viewFolder'][] = new SeedDMS_ExtExample_ViewFolder;
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['example']['example'] = new SeedDMS_ExtExample_Task;
@ -52,6 +53,35 @@ class SeedDMS_ExtExample extends SeedDMS_ExtBase {
} /* }}} */
}
/**
* Class containing methods for hooks when the dms is initialized
*
* @author Uwe Steinmann <uwe@steinmann.cx>
* @package SeedDMS
* @subpackage example
*/
class SeedDMS_ExtExample_InitDMS { /* {{{ */
/**
* Hook after initializing the application
*
* This method sets the callback 'onAttributeValidate' in SeedDMS_Core
*/
public function addRoute($arr) { /* {{{ */
$dms = $arr['dms'];
$settings = $arr['settings'];
$app = $arr['app'];
$app->get('/ext/example/echo',
function ($request, $response) use ($app) {
echo "Output of route /ext/example/echo";
}
);
return null;
} /* }}} */
} /* }}} */
/**
* Class containing methods for hooks when a document is added
*

View File

@ -18,6 +18,48 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include("inc/inc.Settings.php");
include("inc/inc.LogInit.php");
include("inc/inc.Utils.php");
include("inc/inc.Language.php");
include("inc/inc.Init.php");
include("inc/inc.Extension.php");
include("inc/inc.DBInit.php");
include("inc/inc.Authentication.php");
require "vendor/autoload.php";
$c = new \Slim\Container(); //Create Your container
$c['notFoundHandler'] = function ($c) use ($settings) {
return function ($request, $response) use ($c, $settings) {
return $c['response']
->withStatus(302)
->withHeader('Location', isset($settings->_siteDefaultPage) && strlen($settings->_siteDefaultPage)>0 ? $settings->_siteDefaultPage : "out/out.ViewFolder.php");
};
};
$app = new \Slim\App($c);
if(isset($GLOBALS['SEEDDMS_HOOKS']['initDMS'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['initDMS'] as $hookObj) {
if (method_exists($hookObj, 'addRoute')) {
$hookObj->addRoute(array('dms'=>$dms, 'app'=>$app, 'settings'=>$settings));
}
}
}
/*
$app->any('/echo',
function ($request, $response) use ($app) {
echo "lasjf".$request->getBody();
}
);
$app->any('/[{path:.*}]', function($request, $response, $path = null) {
return $response->write($path ? 'subroute' : 'index');
});
*/
$app->run();
exit;
header("Location: ". (isset($settings->_siteDefaultPage) && strlen($settings->_siteDefaultPage)>0 ? $settings->_siteDefaultPage : "out/out.ViewFolder.php"));
?>