public function actionIndex($callback, $id) { $model = NavItemPageBlockItem::findOne($id); $block = Block::objectId($model->block_id, $model->id, 'callback'); $method = 'callback' . Inflector::id2camel($callback); return ObjectHelper::callMethodSanitizeArguments($block, $method, Yii::$app->request->get()); }
public function render() { $activeWindowHash = Yii::$app->request->get('activeWindowHash'); $activeWindowCallback = Yii::$app->request->get('activeWindowCallback'); $activeWindows = $this->config->getPointer('aw'); $obj = $activeWindows[$activeWindowHash]['object']; $function = 'callback' . ucfirst($activeWindowCallback); $args = Yii::$app->request->post(); return ObjectHelper::callMethodSanitizeArguments($obj, $function, Yii::$app->request->post()); /* $reflection = new \ReflectionMethod($obj, $function); $methodArgs = []; if ($reflection->getNumberOfRequiredParameters() > 0) { foreach ($reflection->getParameters() as $param) { if (!array_key_exists($param->name, $args)) { throw new \Exception("the provided argument '".$param->name."' does not exists in the provided arguments list."); } $methodArgs[] = $args[$param->name]; } } $response = call_user_func_array(array($obj, $function), $methodArgs); return $response; */ }
public function actionIndex($callback, $id) { $model = NavItemPageBlockItem::findOne($id); if (!$model) { throw new Exception("Unable to find item id."); } $block = Block::objectId($model->block_id, $model->id, 'callback'); if (!$block) { throw new Exception("Unable to find block object."); } return ObjectHelper::callMethodSanitizeArguments($block, 'callback' . Inflector::id2camel($callback), Yii::$app->request->get()); }
public function render() { $activeWindowHash = Yii::$app->request->get('activeWindowHash'); $activeWindowCallback = Yii::$app->request->get('activeWindowCallback'); $activeWindows = $this->config->getPointer('aw'); if (!isset($activeWindows[$activeWindowHash])) { throw new Exception("Unable to find ActiveWindow " . $activeWindowHash); } $obj = Yii::createObject($activeWindows[$activeWindowHash]['objectConfig']); $obj->setItemId(Yii::$app->session->get($activeWindowHash)); $obj->setConfigHash($this->config->getHash()); $obj->setActiveWindowHash($activeWindowHash); $function = 'callback' . Inflector::id2camel($activeWindowCallback); return ObjectHelper::callMethodSanitizeArguments($obj, $function, Yii::$app->request->post()); }
/** * @expectedException Exception * @expectedExceptionMessage The argument 'foo' is required for method 'm3' in class 'luyatests\core\helpers\TestObject'. */ public function testException() { ObjectHelper::callMethodSanitizeArguments(new TestObject(), 'm3'); }
/** * Helper method to call callable methods. * * Call a method of a the current object which is prefix with call and sanitize its variables to match action variables. * * @param string $method The method to call without the `call` prefix. * @param array $vars Options to pass to the method. */ public function call($method, array $vars = []) { return ObjectHelper::callMethodSanitizeArguments($this, 'call' . Inflector::id2camel($method), $vars); }