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()); }
public function actionSaveField() { $input = $this->_input->filter(array('class' => XenForo_Input::STRING, 'table' => XenForo_Input::STRING, 'name' => XenForo_Input::STRING, 'data_type' => XenForo_Input::STRING, 'default' => XenForo_Input::STRING, 'auto_increment' => XenForo_Input::BOOLEAN)); $dataWriter = XenForo_DataWriter::create($input['class']); if (empty($dataWriter) || !$dataWriter instanceof XenForo_DataWriter) { return $this->responseNoPermission(); } $reflectionClass = new ThemeHouse_Reflection_Class($input['class']); if ($reflectionClass->hasMethod('_getFields')) { /* @var $reflectionMethod ThemeHouse_DataWriters_Reflection_Method_DataWriter_GetFields */ $reflectionMethod = $reflectionClass->getMethod('_getFields', 'ThemeHouse_DataWriters_Reflection_Method_DataWriter_GetFields'); $reflectionMethod->addField($input['table'], $input['name'], $input['data_type'], $input['default'], $input['auto_increment']); } else { // TODO add _getFields method } $addOnId = ThemeHouse_DataWriters_Helper_DataWriter::getAddOnIdFromDataWriterClass($input['class']); $installControllerClass = $addOnId . '_Install_Controller'; /* @var $reflectionClass ThemeHouse_DataWriters_Reflection_Class_InstallController */ $reflectionClass = new ThemeHouse_DataWriters_Reflection_Class_InstallController($installControllerClass); if ($reflectionClass->hasOveridden('_getTables')) { /* @var $reflectionMethod ThemeHouse_DataWriters_Reflection_Method_InstallController_GetTables */ $reflectionMethod = $reflectionClass->getMethod('_getTables', 'ThemeHouse_DataWriters_Reflection_Method_InstallController_GetTables'); $reflectionMethod->addColumn($input['table'], $input['name'], $input['data_type'], $input['default'], $input['auto_increment']); } else { $reflectionClass->addGetTablesMethod($input['table'], $input['name'], $input['data_type'], $input['default'], $input['auto_increment']); } // TODO add column to database? $dataWriter = array('class' => $input['class']); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CREATED, XenForo_Link::buildAdminLink('data-writers/edit-method', $dataWriter, array('method' => '_getFields'))); }
public function actionSave() { $options = $this->_input->filter(array('datawriter' => XenForo_Input::STRING, 'fields' => XenForo_Input::ARRAY_SIMPLE, 'actions' => XenForo_Input::ARRAY_SIMPLE, 'addon_id' => XenForo_Input::STRING, 'class' => XenForo_Input::STRING, 'method' => XenForo_Input::STRING, 'route_prefix' => XenForo_Input::STRING, 'title_field' => XenForo_Input::STRING, 'subtitle_field' => XenForo_Input::STRING)); try { $dataWriter = XenForo_DataWriter::create($options['datawriter']); } catch (Exception $e) { } if (empty($dataWriter) || !$dataWriter instanceof XenForo_DataWriter) { return $this->responseNoPermission(); } $options['primary_key_id'] = ThemeHouse_Controllers_Helper_DataWriter::getPrimaryKey($dataWriter); $name = substr(strrchr($options['class'], '_'), 1); $dataWriterReflectionClass = new ThemeHouse_Reflection_Class(get_class($dataWriter)); $getModelMethod = '_get' . $name . 'Model'; /* @var $reflectionMethod ThemeHouse_Reflection_Method */ $dataWriterReflectionMethod = $dataWriterReflectionClass->getMethod($getModelMethod, 'ThemeHouse_Reflection_Method'); $options['model'] = $dataWriterReflectionMethod->getReturnTag(); $camelCaseRoutePrefix = ThemeHouse_Controllers_Helper_RoutePrefix::hyphenCaseToCamelCase($options['route_prefix']); $routePrefixClass = $options['addon_id'] . '_Route_PrefixAdmin_' . $camelCaseRoutePrefix; /* @var $routePrefixModel XenForo_Model_RoutePrefix */ $routePrefixModel = $this->getModelFromCache('XenForo_Model_RoutePrefix'); $routePrefix = $routePrefixModel->getPrefixByOriginal($options['route_prefix'], 'admin'); if (!$routePrefix) { /* @var $routePrefixDw XenForo_DataWriter_RoutePrefix */ $routePrefixDw = XenForo_DataWriter::create('XenForo_DataWriter_RoutePrefix'); $routePrefixDw->bulkSet(array('route_type' => 'admin', 'original_prefix' => $options['route_prefix'], 'route_class' => $routePrefixClass, 'build_link' => 'data_only', 'addon_id' => $options['addon_id'])); $routePrefixDw->setOption(ThemeHouse_Controllers_Extend_XenForo_DataWriter_RoutePrefix::OPTION_PRIMARY_KEY_ID, $options['primary_key_id']); $routePrefixDw->save(); } $phpFile = new ThemeHouse_Controllers_PhpFile_ControllerAdmin($options['class'], $options); $phpFile->export(); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CREATED, XenForo_Link::buildAdminLink('admin-controllers')); }