[Beeframework-svn] SF.net SVN: beeframework:[279] trunk/framework/Bee
Brought to you by:
b_hartmann,
m_plomer
|
From: <m_p...@us...> - 2015-01-29 11:24:43
|
Revision: 279
http://sourceforge.net/p/beeframework/code/279
Author: m_plomer
Date: 2015-01-29 11:24:41 +0000 (Thu, 29 Jan 2015)
Log Message:
-----------
- Security/UserDetails: refactored UserManagerBase for better extensibility through subclassing
- MVC: moved model and view resolution from Dispatcher to ViewResolver
Modified Paths:
--------------
trunk/framework/Bee/MVC/Dispatcher.php
trunk/framework/Bee/MVC/IViewResolver.php
trunk/framework/Bee/MVC/ModelAndView.php
trunk/framework/Bee/MVC/ViewResolver/BasicViewResolver.php
trunk/framework/Bee/Security/UserDetails/Doctrine2/SimpleUserDetailsService.php
trunk/framework/Bee/Security/UserDetails/UserManagerBase.php
Modified: trunk/framework/Bee/MVC/Dispatcher.php
===================================================================
--- trunk/framework/Bee/MVC/Dispatcher.php 2015-01-16 14:37:32 UTC (rev 278)
+++ trunk/framework/Bee/MVC/Dispatcher.php 2015-01-29 11:24:41 UTC (rev 279)
@@ -1,7 +1,7 @@
<?php
namespace Bee\MVC;
/*
- * Copyright 2008-2014 the original author or authors.
+ * Copyright 2008-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@
use Bee\Context\NoSuchBeanDefinitionException;
use Bee\IContext;
use Bee\MVC\Session\DispatcherAdapter;
-use Bee\MVC\View\AbstractView;
-use Bee\MVC\View\ViewBase;
use Bee\Utils\Assert;
use Exception;
use Logger;
@@ -321,7 +319,7 @@
if ($mav instanceof ModelAndView) {
$mav->addModelValue(Model::CURRENT_REQUEST_KEY, $request);
- $this->resolveModelAndView($mav, $request);
+ $this->viewResolver->resolveModelAndView($mav, $request);
if(!is_null($handlerException) && !count($interceptors)) {
// We were unable to resolve a handler and its interceptors due to an exception being thrown along
@@ -341,36 +339,4 @@
throw $e;
}
}
-
- /**
- * @param ModelAndView $mav
- * @param IHttpRequest $request
- */
- public function resolveModelAndView(ModelAndView $mav, IHttpRequest $request) {
- $resolvedView = $this->viewResolver->resolveViewName($mav->getViewName(), $request);
- $mav->setResolvedView($resolvedView);
- if ($resolvedView instanceof ViewBase) {
- $statics = $resolvedView->getStaticAttributes();
- if (!$statics) {
- $statics = array();
- }
- $model = array_merge($statics, $mav->getModel());
- $mav->setModel($model);
- }
- $this->resolveModelInternals($mav->getModel(), $request);
- }
-
- /**
- * @param array $model
- * @param IHttpRequest $request
- */
- private function resolveModelInternals(array $model, IHttpRequest $request) {
- foreach ($model as $modelElem) {
- if ($modelElem instanceof ModelAndView) {
- $this->resolveModelAndView($modelElem, $request);
- } else if (is_array($modelElem)) {
- $this->resolveModelInternals($modelElem, $request);
- }
- }
- }
}
Modified: trunk/framework/Bee/MVC/IViewResolver.php
===================================================================
--- trunk/framework/Bee/MVC/IViewResolver.php 2015-01-16 14:37:32 UTC (rev 278)
+++ trunk/framework/Bee/MVC/IViewResolver.php 2015-01-29 11:24:41 UTC (rev 279)
@@ -42,4 +42,10 @@
* (optional, to allow for ViewResolver chaining)
*/
public function resolveViewName($viewName, IHttpRequest $request);
+
+ /**
+ * @param ModelAndView $mav
+ * @param IHttpRequest $request
+ */
+ public function resolveModelAndView(ModelAndView $mav, IHttpRequest $request);
}
Modified: trunk/framework/Bee/MVC/ModelAndView.php
===================================================================
--- trunk/framework/Bee/MVC/ModelAndView.php 2015-01-16 14:37:32 UTC (rev 278)
+++ trunk/framework/Bee/MVC/ModelAndView.php 2015-01-29 11:24:41 UTC (rev 279)
@@ -1,7 +1,7 @@
<?php
namespace Bee\MVC;
/*
- * Copyright 2008-2014 the original author or authors.
+ * Copyright 2008-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -155,5 +155,4 @@
// @todo: assert a resolvedView is set
$this->resolvedView->render($this->getModel());
}
-}
-?>
\ No newline at end of file
+}
\ No newline at end of file
Modified: trunk/framework/Bee/MVC/ViewResolver/BasicViewResolver.php
===================================================================
--- trunk/framework/Bee/MVC/ViewResolver/BasicViewResolver.php 2015-01-16 14:37:32 UTC (rev 278)
+++ trunk/framework/Bee/MVC/ViewResolver/BasicViewResolver.php 2015-01-29 11:24:41 UTC (rev 279)
@@ -1,7 +1,7 @@
<?php
namespace Bee\MVC\ViewResolver;
/*
- * Copyright 2008-2014 the original author or authors.
+ * Copyright 2008-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
use Bee\MVC\IHttpRequest;
use Bee\MVC\IView;
use Bee\MVC\IViewResolver;
+use Bee\MVC\ModelAndView;
+use Bee\MVC\View\ViewBase;
use Logger;
/**
@@ -114,4 +116,36 @@
protected function modifyViewName($viewName, IHttpRequest $request) {
return $request->getAjax() ? $viewName . $this->ajaxViewNameSuffix : $viewName;
}
+
+ /**
+ * @param ModelAndView $mav
+ * @param IHttpRequest $request
+ */
+ public function resolveModelAndView(ModelAndView $mav, IHttpRequest $request) {
+ $resolvedView = $this->resolveViewName($mav->getViewName(), $request);
+ $mav->setResolvedView($resolvedView);
+ if ($resolvedView instanceof ViewBase) {
+ $statics = $resolvedView->getStaticAttributes();
+ if (!$statics) {
+ $statics = array();
+ }
+ $model = array_merge($statics, $mav->getModel());
+ $mav->setModel($model);
+ }
+ $this->resolveModelInternals($mav->getModel(), $request);
+ }
+
+ /**
+ * @param array $model
+ * @param IHttpRequest $request
+ */
+ private function resolveModelInternals(array $model, IHttpRequest $request) {
+ foreach ($model as $modelElem) {
+ if ($modelElem instanceof ModelAndView) {
+ $this->resolveModelAndView($modelElem, $request);
+ } else if (is_array($modelElem)) {
+ $this->resolveModelInternals($modelElem, $request);
+ }
+ }
+ }
}
\ No newline at end of file
Modified: trunk/framework/Bee/Security/UserDetails/Doctrine2/SimpleUserDetailsService.php
===================================================================
--- trunk/framework/Bee/Security/UserDetails/Doctrine2/SimpleUserDetailsService.php 2015-01-16 14:37:32 UTC (rev 278)
+++ trunk/framework/Bee/Security/UserDetails/Doctrine2/SimpleUserDetailsService.php 2015-01-29 11:24:41 UTC (rev 279)
@@ -127,7 +127,7 @@
* @return UserBase
*/
public function setRoles(array $frmdata, UserBase $user) {
- /** @var SimpleUser $user */
+ /** @var SimpleUserBase $user */
if ($frmdata['admin']) {
$user->addRole('ROLE_ADMINISTRATOR');
} else {
Modified: trunk/framework/Bee/Security/UserDetails/UserManagerBase.php
===================================================================
--- trunk/framework/Bee/Security/UserDetails/UserManagerBase.php 2015-01-16 14:37:32 UTC (rev 278)
+++ trunk/framework/Bee/Security/UserDetails/UserManagerBase.php 2015-01-29 11:24:41 UTC (rev 279)
@@ -76,12 +76,29 @@
* @throws Exception
*/
public function createOrUpdateUser(array $frmdata) {
- $user = is_numeric($frmdata['id']) ? $this->loadById($frmdata['id']) : $this->createUserInstance();
+ return $this->updateUser($this->findOrCreateUser($frmdata), $frmdata);
+ }
+
+ /**
+ * @param array $frmdata
+ * @return UserBase
+ */
+ protected function findOrCreateUser(array $frmdata) {
+ return is_numeric($frmdata['id']) ? $this->loadById($frmdata['id']) : $this->createUserInstance();
+ }
+
+ /**
+ * @param UserBase $user
+ * @param array $frmdata
+ * @return UserBase
+ * @throws PasswordConfirmationMismatchException
+ */
+ protected function updateUser(UserBase $user, array $frmdata) {
$user->setUsername($frmdata['username']);
$user->setName($frmdata['fullname']);
if (Strings::hasText($frmdata['password'])) {
if ($frmdata['password'] !== $frmdata['password2']) {
- throw new Exception("Passwords do not match!");
+ throw new PasswordConfirmationMismatchException("Passwords do not match!");
}
$this->setPassword($user, $frmdata['password']);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|