[Beeframework-svn] SF.net SVN: beeframework:[277] trunk/framework/Bee/MVC
Brought to you by:
b_hartmann,
m_plomer
|
From: <m_p...@us...> - 2015-01-16 08:39:36
|
Revision: 277
http://sourceforge.net/p/beeframework/code/277
Author: m_plomer
Date: 2015-01-16 08:39:28 +0000 (Fri, 16 Jan 2015)
Log Message:
-----------
- MVC: added IWidgetController and proper handling of its handleDefault() invocation
Modified Paths:
--------------
trunk/framework/Bee/MVC/Controller/MultiActionController.php
trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php
trunk/framework/Bee/MVC/Controller/Multiaction/IHandlerMethodInvocator.php
Added Paths:
-----------
trunk/framework/Bee/MVC/IWidgetController.php
Modified: trunk/framework/Bee/MVC/Controller/MultiActionController.php
===================================================================
--- trunk/framework/Bee/MVC/Controller/MultiActionController.php 2014-12-19 23:21:30 UTC (rev 276)
+++ trunk/framework/Bee/MVC/Controller/MultiActionController.php 2015-01-16 08:39:28 UTC (rev 277)
@@ -20,6 +20,7 @@
use Bee\MVC\Controller\Multiaction\NoHandlerMethodFoundException;
use Bee\MVC\IDelegatingHandler;
use Bee\MVC\IHttpRequest;
+use Bee\MVC\IWidgetController;
use Bee\MVC\ModelAndView;
use Bee\Utils\Assert;
use Bee\Utils\Reflection;
@@ -39,7 +40,7 @@
* @author Michael Plomer <mic...@it...>
* @author Benjamin Hartmann
*/
-class MultiActionController extends AbstractController implements IDelegatingHandler {
+class MultiActionController extends AbstractController implements IDelegatingHandler, IWidgetController {
/**
* Enter description here...
@@ -94,12 +95,7 @@
if (!Strings::hasText($methodName)) {
$methodName = $this->getDefaultMethodName();
}
-
- // @todo: this might pose a security risk. introduce a set of allowed method names
- $method = new ReflectionMethod($this->delegate, $methodName);
- if (!$this->isHandlerMethod($method)) {
- throw new NoHandlerMethodFoundException('No request handling method with name ' . $methodName . ' in class [' . Types::getType($this->delegate) . ']');
- }
+ $method = $this->getReflectionMethodForName($methodName);
}
return $method->invokeArgs($this->delegate, array($request));
}
@@ -203,4 +199,30 @@
public function getMethodNameResolver() {
return $this->methodNameResolver;
}
+
+ /**
+ * @param IHttpRequest $request
+ * @return mixed
+ * @throws NoHandlerMethodFoundException
+ */
+ public function handleDefault(IHttpRequest $request) {
+ if(!is_null($this->methodInvocator)) {
+ return $this->methodInvocator->invokeDefaultHandlerMethod($request);
+ }
+ return $this->getReflectionMethodForName($this->getDefaultMethodName())->invokeArgs($this->delegate, array($request));
+ }
+
+ /**
+ * @param string $methodName
+ * @return ReflectionMethod
+ * @throws NoHandlerMethodFoundException
+ */
+ protected function getReflectionMethodForName($methodName) {
+ // @todo: this might pose a security risk. introduce a set of allowed method names
+ $method = new ReflectionMethod($this->delegate, $methodName);
+ if (!$this->isHandlerMethod($method)) {
+ throw new NoHandlerMethodFoundException('No request handling method with name ' . $methodName . ' in class [' . Types::getType($this->delegate) . ']');
+ }
+ return $method;
+ }
}
\ No newline at end of file
Modified: trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php
===================================================================
--- trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php 2014-12-19 23:21:30 UTC (rev 276)
+++ trunk/framework/Bee/MVC/Controller/Multiaction/HandlerMethodInvocator/AnnotationBasedInvocator.php 2015-01-16 08:39:28 UTC (rev 277)
@@ -20,7 +20,6 @@
use Bee\IContext;
use Bee\MVC\Controller\Multiaction\AbstractAnnotationBasedResolver;
use Bee\MVC\Controller\Multiaction\IHandlerMethodInvocator;
-use Bee\MVC\IController;
use Bee\MVC\IHttpRequest;
use Bee\MVC\ModelAndView;
@@ -93,6 +92,16 @@
}
// todo:
+ return $this->invokeResolvedMethod($resolvedMethod, $request, $fixedParams);
+ }
+
+ /**
+ * @param MethodInvocation $resolvedMethod
+ * @param IHttpRequest $request
+ * @param array $fixedParams
+ * @return mixed
+ */
+ protected function invokeResolvedMethod(MethodInvocation $resolvedMethod, IHttpRequest $request, array $fixedParams = array()) {
$methodMeta = $resolvedMethod->getMethodMeta();
$method = $methodMeta->getMethod();
$args = array();
@@ -107,7 +116,7 @@
$propEditor = $this->propertyEditorRegistry->getEditor($type);
$posMap = $resolvedMethod->getUrlParameterPositions();
$value = array_key_exists($pos, $posMap) ? $resolvedMethod->getParamValue($posMap[$pos]) :
- (array_key_exists($parameter->getName(), $_REQUEST) ? $_REQUEST[$parameter->getName()] : null);
+ (array_key_exists($parameter->getName(), $_REQUEST) ? $_REQUEST[$parameter->getName()] : null);
if (!is_null($value) || !$parameter->isOptional()) {
$args[$pos] = $propEditor->fromString($value);
} else {
@@ -162,4 +171,12 @@
public function setDefaultMethodName($defaultMethodName) {
$this->defaultMethodName = $defaultMethodName;
}
+
+ /**
+ * @param IHttpRequest $request
+ * @return mixed
+ */
+ public function invokeDefaultHandlerMethod(IHttpRequest $request) {
+ return $this->invokeResolvedMethod($this->getDefaultMethodInvocation(), $request);
+ }
}
\ No newline at end of file
Modified: trunk/framework/Bee/MVC/Controller/Multiaction/IHandlerMethodInvocator.php
===================================================================
--- trunk/framework/Bee/MVC/Controller/Multiaction/IHandlerMethodInvocator.php 2014-12-19 23:21:30 UTC (rev 276)
+++ trunk/framework/Bee/MVC/Controller/Multiaction/IHandlerMethodInvocator.php 2015-01-16 08:39:28 UTC (rev 277)
@@ -37,4 +37,6 @@
* @return ModelAndView
*/
public function invokeHandlerMethod(IHttpRequest $request, array $fixedParams = array());
+
+ public function invokeDefaultHandlerMethod(IHttpRequest $request);
}
\ No newline at end of file
Added: trunk/framework/Bee/MVC/IWidgetController.php
===================================================================
--- trunk/framework/Bee/MVC/IWidgetController.php (rev 0)
+++ trunk/framework/Bee/MVC/IWidgetController.php 2015-01-16 08:39:28 UTC (rev 277)
@@ -0,0 +1,25 @@
+<?php
+namespace Bee\MVC;
+/*
+ * Copyright 2008-2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Interface IWidgetController - IController instance that has a default handler method.
+ * @package Bee\MVC
+ */
+interface IWidgetController extends IController {
+ function handleDefault(IHttpRequest $request);
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|