public static function createMethod(XenForo_Controller $controller, $method, $body = '', $signature = '') { $class = self::getClass($controller); $reflectionClass = new ThemeHouse_Reflection_Class($class); if ($reflectionClass->hasMethod($method)) { $reflectionMethod = $reflectionClass->getMethod($method); // TODO update signature // $reflectionMethod->setSignature($signature); $reflectionMethod->setMethodBody($body); } else { $reflectionClass->addMethod($method, $body, $signature); } return $method; }
public function actionSaveMethod() { $input = $this->_input->filter(array('class' => XenForo_Input::STRING, 'method' => XenForo_Input::STRING, 'addon_id' => XenForo_Input::STRING, 'signature' => XenForo_Input::STRING, 'body' => XenForo_Input::STRING)); $reflectionClass = new ThemeHouse_Reflection_Class($input['class']); XenForo_Helper_Cookie::setCookie('edit_addon_id', $input['addon_id']); if ($reflectionClass->hasMethod($input['method'])) { /* @var $reflectionMethod ThemeHouse_Reflection_Method */ $reflectionMethod = $reflectionClass->getMethod($input['method'], 'ThemeHouse_Reflection_Method'); $declaringClass = $reflectionMethod->getDeclaringClass(); $declaringClassName = $declaringClass->getName(); if ($declaringClassName == $input['class']) { $reflectionMethod->setMethodBody($input['body']); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_UPDATED, $this->getDynamicRedirect()); } } $reflectionClass->addMethod($input['method'], $input['body'], $input['signature']); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_UPDATED, $this->getDynamicRedirect()); }