refactored the the URI class into separate router and request classes

parent 1fd7cc2f
This diff is collapsed.
...@@ -46,31 +46,40 @@ class Breadcrumb ...@@ -46,31 +46,40 @@ class Breadcrumb
* @var Lang * @var Lang
*/ */
protected $lang; protected $lang;
/** /**
* @var URI * @var Request
*/ */
protected $uri; protected $request;
/**
* @var Router
*/
protected $router;
/** /**
* @var View * @var View
*/ */
protected $view; protected $view;
public function __construct(\Doctrine\DBAL\Connection $db, Lang $lang, URI $uri, View $view) public function __construct(
\Doctrine\DBAL\Connection $db,
Lang $lang,
Request $request,
Router $router,
View $view
)
{ {
$this->lang = $lang; $this->lang = $lang;
$this->uri = $uri; $this->request = $request;
$this->router = $router;
$this->view = $view; $this->view = $view;
// Frontendbereich // Frontendbereich
if ($uri->area !== 'admin') { if ($request->area !== 'admin') {
$in = array( $in = array(
$uri->query, $request->query,
$uri->getUriWithoutPages(), $request->getUriWithoutPages(),
$uri->mod . '/' . $uri->controller . '/' . $uri->file . '/', $request->mod . '/' . $request->controller . '/' . $request->file . '/',
$uri->mod . '/' . $uri->controller . '/', $request->mod . '/' . $request->controller . '/',
$uri->mod $request->mod
); );
$items = $db->executeQuery('SELECT p.title, p.uri, p.left_id, p.right_id FROM ' . DB_PRE . 'menu_items AS c, ' . DB_PRE . 'menu_items AS p WHERE c.left_id BETWEEN p.left_id AND p.right_id AND c.uri IN(?) GROUP BY p.uri ORDER BY p.left_id ASC', array($in), array(\Doctrine\DBAL\Connection::PARAM_STR_ARRAY))->fetchAll(); $items = $db->executeQuery('SELECT p.title, p.uri, p.left_id, p.right_id FROM ' . DB_PRE . 'menu_items AS c, ' . DB_PRE . 'menu_items AS p WHERE c.left_id BETWEEN p.left_id AND p.right_id AND c.uri IN(?) GROUP BY p.uri ORDER BY p.left_id ASC', array($in), array(\Doctrine\DBAL\Connection::PARAM_STR_ARRAY))->fetchAll();
$c_items = count($items); $c_items = count($items);
...@@ -131,7 +140,7 @@ class Breadcrumb ...@@ -131,7 +140,7 @@ class Breadcrumb
{ {
$this->stepsFromDb[] = array( $this->stepsFromDb[] = array(
'title' => $title, 'title' => $title,
'uri' => !empty($path) ? $this->uri->route($path) : '' 'uri' => !empty($path) ? $this->router->route($path) : ''
); );
return $this; return $this;
...@@ -150,7 +159,7 @@ class Breadcrumb ...@@ -150,7 +159,7 @@ class Breadcrumb
{ {
$this->stepsFromModules[] = array( $this->stepsFromModules[] = array(
'title' => $title, 'title' => $title,
'uri' => !empty($path) ? $this->uri->route($path) : '' 'uri' => !empty($path) ? $this->router->route($path) : ''
); );
return $this; return $this;
...@@ -169,7 +178,7 @@ class Breadcrumb ...@@ -169,7 +178,7 @@ class Breadcrumb
{ {
$step = array( $step = array(
'title' => $title, 'title' => $title,
'uri' => $this->uri->route($path) 'uri' => $this->router->route($path)
); );
array_unshift($this->stepsFromModules, $step); array_unshift($this->stepsFromModules, $step);
return $this; return $this;
...@@ -190,11 +199,11 @@ class Breadcrumb ...@@ -190,11 +199,11 @@ class Breadcrumb
if ($dbSteps === true) { if ($dbSteps === true) {
$index = count($this->stepsFromDb) - (!empty($this->stepsFromDb) ? 1 : 0); $index = count($this->stepsFromDb) - (!empty($this->stepsFromDb) ? 1 : 0);
$this->stepsFromDb[$index]['title'] = $title; $this->stepsFromDb[$index]['title'] = $title;
$this->stepsFromDb[$index]['uri'] = !empty($path) ? $this->uri->route($path) : ''; $this->stepsFromDb[$index]['uri'] = !empty($path) ? $this->router->route($path) : '';
} else { } else {
$index = count($this->stepsFromModules) - (!empty($this->stepsFromModules) ? 1 : 0); $index = count($this->stepsFromModules) - (!empty($this->stepsFromModules) ? 1 : 0);
$this->stepsFromModules[$index]['title'] = $title; $this->stepsFromModules[$index]['title'] = $title;
$this->stepsFromModules[$index]['uri'] = !empty($path) ? $this->uri->route($path) : ''; $this->stepsFromModules[$index]['uri'] = !empty($path) ? $this->router->route($path) : '';
} }
return $this; return $this;
...@@ -206,7 +215,7 @@ class Breadcrumb ...@@ -206,7 +215,7 @@ class Breadcrumb
private function _setBreadcrumbCache() private function _setBreadcrumbCache()
{ {
// Brotkrümelspur für das Admin-Panel // Brotkrümelspur für das Admin-Panel
if ($this->uri->area === 'admin') { if ($this->request->area === 'admin') {
$this->_setBreadcrumbCacheForAdmin(); $this->_setBreadcrumbCacheForAdmin();
} else { // Breadcrumb for frontend requests } else { // Breadcrumb for frontend requests
$this->_setBreadcrumbCacheForFrontend(); $this->_setBreadcrumbCacheForFrontend();
...@@ -221,7 +230,7 @@ class Breadcrumb ...@@ -221,7 +230,7 @@ class Breadcrumb
*/ */
private function _setBreadcrumbCacheForAdmin() private function _setBreadcrumbCacheForAdmin()
{ {
$module = $this->uri->mod; $module = $this->request->mod;
if ($module !== 'acp') { if ($module !== 'acp') {
$this->setTitlePostfix($this->lang->t('system', 'acp')); $this->setTitlePostfix($this->lang->t('system', 'acp'));
...@@ -229,10 +238,10 @@ class Breadcrumb ...@@ -229,10 +238,10 @@ class Breadcrumb
// No breadcrumb is set yet // No breadcrumb is set yet
if (empty($this->stepsFromModules)) { if (empty($this->stepsFromModules)) {
$controller = $this->uri->controller; $controller = $this->request->controller;
$file = $this->uri->file; $file = $this->request->file;
$languageKey = $this->uri->area . '_' . $controller . '_' . $file; $languageKey = $this->request->area . '_' . $controller . '_' . $file;
$languageKeyIndex = $this->uri->area . '_' . $controller . '_index'; $languageKeyIndex = $this->request->area . '_' . $controller . '_index';
$this->append($this->lang->t('system', 'acp'), 'acp/acp'); $this->append($this->lang->t('system', 'acp'), 'acp/acp');
...@@ -264,11 +273,11 @@ class Breadcrumb ...@@ -264,11 +273,11 @@ class Breadcrumb
{ {
// No breadcrumb has been set yet // No breadcrumb has been set yet
if (empty($this->stepsFromModules)) { if (empty($this->stepsFromModules)) {
$module = $this->uri->mod; $module = $this->request->mod;
$controller = $this->uri->controller; $controller = $this->request->controller;
$file = $this->uri->file; $file = $this->request->file;
$languageKey = $this->uri->area . '_' . $controller . '_' . $file; $languageKey = $this->request->area . '_' . $controller . '_' . $file;
$languageKeyIndex = $this->uri->area . '_' . $controller . '_index'; $languageKeyIndex = $this->request->area . '_' . $controller . '_index';
if ($module !== 'errors') { if ($module !== 'errors') {
$this->append($this->lang->t($module, $module), $module); $this->append($this->lang->t($module, $module), $module);
......
...@@ -20,9 +20,13 @@ class Context ...@@ -20,9 +20,13 @@ class Context
*/ */
protected $modules; protected $modules;
/** /**
* @var URI * @var Request
*/ */
protected $uri; protected $request;
/**
* @var Router
*/
protected $router;
/** /**
* @var View * @var View
*/ */
...@@ -32,13 +36,15 @@ class Context ...@@ -32,13 +36,15 @@ class Context
Auth $auth, Auth $auth,
Lang $lang, Lang $lang,
Modules $modules, Modules $modules,
URI $uri, Request $request,
Router $router,
View $view) View $view)
{ {
$this->auth = $auth; $this->auth = $auth;
$this->lang = $lang; $this->lang = $lang;
$this->modules = $modules; $this->modules = $modules;
$this->uri = $uri; $this->request = $request;
$this->router = $router;
$this->view = $view; $this->view = $view;
} }
...@@ -67,11 +73,19 @@ class Context ...@@ -67,11 +73,19 @@ class Context
} }
/** /**
* @return \ACP3\Core\URI * @return \ACP3\Core\Request
*/
public function getRequest()
{
return $this->request;
}
/**
* @return \ACP3\Core\Router
*/ */
public function getUri() public function getRouter()
{ {
return $this->uri; return $this->router;
} }
/** /**
...@@ -82,4 +96,4 @@ class Context ...@@ -82,4 +96,4 @@ class Context
return $this->view; return $this->view;
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -22,14 +22,15 @@ class Admin extends Frontend ...@@ -22,14 +22,15 @@ class Admin extends Frontend
Core\Auth $auth, Core\Auth $auth,
Core\Lang $lang, Core\Lang $lang,
Core\Modules $modules, Core\Modules $modules,
Core\URI $uri, Core\Request $request,
Core\Router $router,
Core\View $view, Core\View $view,
Core\Breadcrumb $breadcrumb, Core\Breadcrumb $breadcrumb,
Core\SEO $seo, Core\SEO $seo,
Core\Validate $validate, Core\Validate $validate,
Core\Session $session) Core\Session $session)
{ {
parent::__construct($auth, $lang, $modules, $uri, $view, $breadcrumb, $seo); parent::__construct($auth, $lang, $modules, $request, $router, $view, $breadcrumb, $seo);
$this->validate = $validate; $this->validate = $validate;
$this->session = $session; $this->session = $session;
......
...@@ -22,12 +22,13 @@ class Frontend extends Core\Context ...@@ -22,12 +22,13 @@ class Frontend extends Core\Context
Core\Auth $auth, Core\Auth $auth,
Core\Lang $lang, Core\Lang $lang,
Core\Modules $modules, Core\Modules $modules,
Core\URI $uri, Core\Request $request,
Core\Router $router,
Core\View $view, Core\View $view,
Core\Breadcrumb $breadcrumb, Core\Breadcrumb $breadcrumb,
Core\SEO $seo) Core\SEO $seo)
{ {
parent::__construct($auth, $lang, $modules, $uri, $view); parent::__construct($auth, $lang, $modules, $request, $router, $view);
$this->breadcrumb = $breadcrumb; $this->breadcrumb = $breadcrumb;
$this->seo = $seo; $this->seo = $seo;
......
...@@ -9,19 +9,24 @@ use ACP3\Core; ...@@ -9,19 +9,24 @@ use ACP3\Core;
*/ */
class Alerts class Alerts
{ {
/**
* @var \ACP3\Core\Functions
*/
private $functions;
/** /**
* @var Core\View * @var Core\View
*/ */
private $view; private $view;
/** /**
* @var Core\URI * @var Core\Request
*/ */
private $uri; private $request;
public function __construct(Core\URI $uri, Core\View $view) public function __construct(Core\Request $request, Core\View $view, Core\Functions $functions)
{ {
$this->uri = $uri; $this->request = $request;
$this->view = $view; $this->view = $view;
$this->functions = $functions;
} }
/** /**
...@@ -96,7 +101,7 @@ class Alerts ...@@ -96,7 +101,7 @@ class Alerts
if (is_array($errors) === true) { if (is_array($errors) === true) {
foreach (array_keys($errors) as $key) { foreach (array_keys($errors) as $key) {
if (Core\Validate::isNumber($key) === false) { if (is_numeric($key) === false) {
$hasNonIntegerKeys = true; $hasNonIntegerKeys = true;
break; break;
} }
...@@ -107,13 +112,13 @@ class Alerts ...@@ -107,13 +112,13 @@ class Alerts
$this->view->assign('error_box', array('non_integer_keys' => $hasNonIntegerKeys, 'errors' => $errors)); $this->view->assign('error_box', array('non_integer_keys' => $hasNonIntegerKeys, 'errors' => $errors));
$content = $this->view->fetchTemplate('system/error_box.tpl'); $content = $this->view->fetchTemplate('system/error_box.tpl');
if ($this->uri->getIsAjax() === true) { if ($this->request->getIsAjax() === true) {
$return = array( $return = array(
'success' => false, 'success' => false,
'content' => $content, 'content' => $content,
); );
Core\Functions::outputJson($return); $this->functions->outputJson($return);
} }
return $content; return $content;
} }
......
...@@ -10,17 +10,26 @@ use ACP3\Core; ...@@ -10,17 +10,26 @@ use ACP3\Core;
class RedirectMessages class RedirectMessages
{ {
/** /**
* @var Core\URI * @var Core\Request
*/ */
private $uri; private $request;
/**
* @var Core\Redirect
*/
private $redirect;
/** /**
* @var Core\View * @var Core\View
*/ */
private $view; private $view;
public function __construct(Core\URI $uri, Core\View $view) public function __construct(
Core\Redirect $redirect,
Core\Request $request,
Core\View $view
)
{ {
$this->uri = $uri; $this->redirect = $redirect;
$this->request = $request;
$this->view = $view; $this->view = $view;
} }
...@@ -50,7 +59,12 @@ class RedirectMessages ...@@ -50,7 +59,12 @@ class RedirectMessages
'success' => is_int($success) ? true : (bool)$success, 'success' => is_int($success) ? true : (bool)$success,
'text' => $text 'text' => $text
); );
$this->uri->redirect($path);
if ($this->request->getIsAjax()) {
$this->redirect->ajax($path);
} else {
$this->redirect->temporary($path);
}
} }
} }
} }
\ No newline at end of file
...@@ -16,18 +16,18 @@ class StringFormatter ...@@ -16,18 +16,18 @@ class StringFormatter
protected $modules; protected $modules;
/** /**
* @var Core\URI * @var Core\Router
*/ */
protected $uri; protected $router;
/** /**
* @var Core\Validate * @var Core\Validate
*/ */
protected $validate; protected $validate;
public function __construct(Core\Modules $modules, Core\URI $uri, Core\Validate $validate) public function __construct(Core\Modules $modules, Core\Router $router, Core\Validate $validate)
{ {
$this->modules = $modules; $this->modules = $modules;
$this->uri = $uri; $this->router = $router;
$this->validate = $validate; $this->validate = $validate;
} }
...@@ -115,7 +115,7 @@ class StringFormatter ...@@ -115,7 +115,7 @@ class StringFormatter
} }
if ($this->modules->actionExists($path)) { if ($this->modules->actionExists($path)) {
return '<a href="' . $this->uri->route($matches[6]) . '"'; return '<a href="' . $this->router->route($matches[6]) . '"';
} else { } else {
return $matches[0]; return $matches[0];
} }
......
...@@ -22,9 +22,17 @@ class TableOfContents ...@@ -22,9 +22,17 @@ class TableOfContents
*/ */
protected $seo; protected $seo;
/** /**
* @var \ACP3\Core\URI * @var \ACP3\Core\Request
*/ */
protected $uri; protected $request;
/**
* @var \ACP3\Core\Router
*/
protected $router;
/**
* @var \ACP3\Core\Validate
*/
protected $validate;
/** /**
* @var \ACP3\Core\View * @var \ACP3\Core\View
*/ */
...@@ -33,15 +41,19 @@ class TableOfContents ...@@ -33,15 +41,19 @@ class TableOfContents
public function __construct( public function __construct(
Core\Breadcrumb $breadcrumb, Core\Breadcrumb $breadcrumb,
Core\Lang $lang, Core\Lang $lang,
Core\SEO $seo, Core\SEO $seo,
Core\URI $uri, Core\Request $request,
Core\Router $router,
Core\Validate $validate,
Core\View $view Core\View $view
) )
{ {
$this->breadcrumb = $breadcrumb; $this->breadcrumb = $breadcrumb;
$this->lang = $lang; $this->lang = $lang;
$this->seo = $seo; $this->seo = $seo;
$this->uri = $uri; $this->request = $request;
$this->router = $router;
$this->validate = $validate;
$this->view = $view; $this->view = $view;
} }
...@@ -57,8 +69,8 @@ class TableOfContents ...@@ -57,8 +69,8 @@ class TableOfContents
public function generateTOC(array $pages, $path = '', $titlesFromDb = false, $customUris = false) public function generateTOC(array $pages, $path = '', $titlesFromDb = false, $customUris = false)
{ {
if (!empty($pages)) { if (!empty($pages)) {
$uri = $this->uri; $request = $this->request;
$path = empty($path) ? $uri->getUriWithoutPages() : $path; $path = empty($path) ? $request->getUriWithoutPages() : $path;
$toc = array(); $toc = array();
$i = 0; $i = 0;
foreach ($pages as $page) { foreach ($pages as $page) {
...@@ -70,18 +82,18 @@ class TableOfContents ...@@ -70,18 +82,18 @@ class TableOfContents
$toc[$i]['title'] = !empty($page['title']) ? $page['title'] : sprintf($this->lang->t('system', 'toc_page'), $pageNumber); $toc[$i]['title'] = !empty($page['title']) ? $page['title'] : sprintf($this->lang->t('system', 'toc_page'), $pageNumber);
} }
$toc[$i]['uri'] = $customUris === true ? $page['uri'] : $uri->route($path) . ($pageNumber > 1 ? 'page_' . $pageNumber . '/' : ''); $toc[$i]['uri'] = $customUris === true ? $page['uri'] : $this->router->route($path) . ($pageNumber > 1 ? 'page_' . $pageNumber . '/' : '');
$toc[$i]['selected'] = false; $toc[$i]['selected'] = false;
if ($customUris === true) { if ($customUris === true) {
if ($page['uri'] === $uri->route($uri->query) || if ($page['uri'] === $this->router->route($request->query) ||
$uri->route($uri->query) === $uri->route($uri->mod . '/' . $uri->controller . '/' . $uri->file) && $i == 0 $this->router->route($request->query) === $this->router->route($request->mod . '/' . $request->controller . '/' . $request->file) && $i == 0
) { ) {
$toc[$i]['selected'] = true; $toc[$i]['selected'] = true;
$this->breadcrumb->setTitlePostfix($toc[$i]['title']); $this->breadcrumb->setTitlePostfix($toc[$i]['title']);
} }
} else { } else {
if ((Core\Validate::isNumber($uri->page) === false && $i === 0) || $uri->page === $pageNumber) { if (($this->validate->isNumber($request->page) === false && $i === 0) || $request->page === $pageNumber) {
$toc[$i]['selected'] = true; $toc[$i]['selected'] = true;
$this->breadcrumb->setTitlePostfix($toc[$i]['title']); $this->breadcrumb->setTitlePostfix($toc[$i]['title']);
} }
...@@ -145,9 +157,9 @@ class TableOfContents ...@@ -145,9 +157,9 @@ class TableOfContents
$matches = array(); $matches = array();
preg_match_all($regex, $text, $matches); preg_match_all($regex, $text, $matches);
$currentPage = Core\Validate::isNumber($this->uri->page) === true && $this->uri->page <= $c_pages ? $this->uri->page : 1; $currentPage = $this->validate->isNumber($this->request->page) === true && $this->request->page <= $c_pages ? $this->request->page : 1;
$nextPage = !empty($pages[$currentPage]) ? $this->uri->route($path) . 'page_' . ($currentPage + 1) . '/' : ''; $nextPage = !empty($pages[$currentPage]) ? $this->router->route($path) . 'page_' . ($currentPage + 1) . '/' : '';
$previousPage = $currentPage > 1 ? $this->uri->route($path) . ($currentPage - 1 > 1 ? 'page_' . ($currentPage - 1) . '/' : '') : ''; $previousPage = $currentPage > 1 ? $this->router->route($path) . ($currentPage - 1 > 1 ? 'page_' . ($currentPage - 1) . '/' : '') : '';
if (!empty($nextPage)) { if (!empty($nextPage)) {
$this->seo->setNextPage($nextPage); $this->seo->setNextPage($nextPage);
......
...@@ -27,9 +27,13 @@ abstract class Controller ...@@ -27,9 +27,13 @@ abstract class Controller
*/ */
protected $modules; protected $modules;
/** /**
* @var \ACP3\Core\URI * @var \ACP3\Core\Request
*/ */
protected $uri; protected $request;
/**
* @var \ACP3\Core\Router
*/
protected $router;
/** /**
* @var \ACP3\Core\View * @var \ACP3\Core\View
*/ */
...@@ -71,7 +75,8 @@ abstract class Controller ...@@ -71,7 +75,8 @@ abstract class Controller
{ {
$this->auth = $context->getAuth(); $this->auth = $context->getAuth();
$this->lang = $context->getLang(); $this->lang = $context->getLang();
$this->uri = $context->getUri(); $this->request = $context->getRequest();
$this->router = $context->getRouter();
$this->view = $context->getView(); $this->view = $context->getView();
$this->modules = $context->getModules(); $this->modules = $context->getModules();
} }
......
...@@ -34,8 +34,8 @@ abstract class Admin extends Core\Modules\Controller\Frontend ...@@ -34,8 +34,8 @@ abstract class Admin extends Core\Modules\Controller\Frontend
public function preDispatch() public function preDispatch()
{