public function getArguments(Request $request, $controller) { if (is_array($controller) && $controller[0] instanceof TransactionalControllerWrapper) { $controller[0] = $controller[0]->getController(); } return parent::getArguments($request, $controller); }
/** * @{inheritdoc} */ public function getArguments(Request $request, $controller) { $e = $this->stopwatch->start('controller.get_arguments'); $ret = parent::getArguments($request, $controller); $e->stop(); return $ret; }
/** * @param FilterControllerEvent $event * @DI\Observe("kernel.controller") */ public function onControllerRequest(FilterControllerEvent $event) { $controller = $event->getController(); $request = $event->getRequest(); $session = $request->getSession(); if (!is_array($controller) && !$this->authorizationChecker->isGranted("IS_AUTHENTICATED_FULLY")) { return; } if ($request->attributes->get('_route') == 'site_url' || $request->attributes->get('_route') == 'startpage') { if ($this->authorizationChecker->isGranted("IS_AUTHENTICATED_FULLY") && !$request->get("skipIframe")) { $controller = "BigfishCoreBundle:Base:iframe"; $request->attributes->set('_controller', $controller); $uri = $request->getPathInfo(); $request->attributes->set("slug", ltrim($uri, "/")); $event->setController($this->controllerResolver->getController($request)); } } }
/** * Run a module function. * * @param string $modname The name of the module. * @param string $type The type of function to run. * @param string $func The specific function to run. * @param array $args The arguments to pass to the function. * @param boolean $api Whether or not to execute an API (or regular) function. * @param string $instanceof Perform instanceof checking of target class. * * @throws Zikula_Exception_NotFound If method was not found. * @throws InvalidArgumentException If the controller is not an instance of the class specified in $instanceof. * * @return mixed. */ public static function exec($modname, $type = 'user', $func = 'main', $args = array(), $api = false, $instanceof = null) { // define input, all numbers and booleans to strings $modname = isset($modname) ? (string) $modname : ''; $modname = static::convertModuleName($modname); // validate if (!System::varValidate($modname, 'mod')) { return null; } // Remove from 1.4 if (System::isLegacyMode('1.4.0') && $modname == 'Modules') { LogUtil::log(__('Warning! "Modules" module has been renamed to "ZikulaExtensionsModule". Please update your ModUtil::func() and ModUtil::apiFunc() calls.')); $modname = 'ZikulaExtensionsModule'; } $modinfo = self::getInfo(self::getIDFromName($modname)); $controller = null; $modfunc = null; $loaded = call_user_func_array($api ? 'ModUtil::loadApi' : 'ModUtil::load', array($modname, $type)); if (self::isOO($modname)) { $result = self::getCallable($modname, $type, $func, $api); if ($result) { $modfunc = $result['callable']; $controller = $modfunc[0]; if (!is_null($instanceof)) { if (!$controller instanceof $instanceof) { throw new InvalidArgumentException(__f('%1$s must be an instance of $2$s', array(get_class($controller), $instanceof))); } } } } $eventManager = EventUtil::getManager(); $sm = ServiceUtil::getManager(); if ($loaded) { $preExecuteEvent = new \Zikula\Core\Event\GenericEvent($controller, array('modname' => $modname, 'modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api)); $postExecuteEvent = new \Zikula\Core\Event\GenericEvent($controller, array('modname' => $modname, 'modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api)); if (is_callable($modfunc)) { $eventManager->dispatch('module_dispatch.preexecute', $preExecuteEvent); // Check $modfunc is an object instance (OO) or a function (old) if (is_array($modfunc)) { try { self::getModule($modname); $newType = true; } catch (\Exception $e) { $newType = false; } if ($args) { $newType = false; } if (!$api && $newType) { // resolve request args. $resolver = new ControllerResolver($sm, new ControllerNameParser(ServiceUtil::get('kernel'))); try { $r = new \ReflectionClass($modfunc[0]); if (!$r->hasMethod($modfunc[1])) { // Method doesn't exist. Do some BC handling. // First try to remove the 'Action' suffix. $modfunc[1] = preg_replace('/(\\w+)Action$/', '$1', $modfunc[1]); if (!$r->hasMethod($modfunc[1])) { // Method still not found. Try to use the old 'main' method name. if ($modfunc[1] == 'index') { $modfunc[1] = $r->hasMethod('mainAction') ? 'mainAction' : 'main'; } } } if ($r->hasMethod($modfunc[1])) { // Did we get a valid method? If so, resolve arguments! $methodArgs = $resolver->getArguments($sm->get('request'), $modfunc); } else { // We still didn't get a valid method. Do not use argument resolving. $newType = false; } } catch (\RuntimeException $e) { // Something went wrong. Check if the method still uses the old non-Symfony $args array. if ($modfunc[0] instanceof \Zikula_AbstractBase) { $r = new \ReflectionMethod($modfunc[0], $modfunc[1]); $parameters = $r->getParameters(); if (count($parameters) == 1) { $firstParameter = $parameters[0]; if ($firstParameter->getName() == 'args') { // The method really uses the old $args parameter. In this case we can continue // using the old Controller call and don't have to throw an exception. $newType = false; } } } if ($newType !== false) { throw $e; } } } if ($modfunc[0] instanceof Zikula_AbstractController) { $reflection = call_user_func(array($modfunc[0], 'getReflection')); $subclassOfReflection = new ReflectionClass($reflection->getParentClass()); if ($subclassOfReflection->hasMethod($modfunc[1])) { // Don't allow front controller to access any public methods inside the controller's parents throw new Zikula_Exception_NotFound(); } $modfunc[0]->preDispatch(); } if (!$api && $newType && isset($methodArgs)) { $postExecuteEvent->setData(call_user_func_array($modfunc, $methodArgs)); } else { $postExecuteEvent->setData(call_user_func($modfunc, $args)); } if ($modfunc[0] instanceof Zikula_AbstractController) { $modfunc[0]->postDispatch(); } } else { $postExecuteEvent->setData($modfunc($args)); } return $eventManager->dispatch('module_dispatch.postexecute', $postExecuteEvent)->getData(); } // try to load plugin // This kind of eventhandler should // 1. Check $event['modfunc'] to see if it should run else exit silently. // 2. Do something like $result = {$event['modfunc']}({$event['args'}); // 3. Save the result $event->setData($result). // 4. $event->setNotify(). // return void // This event means that no $type was found $event = new \Zikula\Core\Event\GenericEvent(null, array('modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api), false); $eventManager->dispatch('module_dispatch.type_not_found', $event); if ($preExecuteEvent->isPropagationStopped()) { return $preExecuteEvent->getData(); } return false; } // Issue not found exception for controller requests if (!System::isLegacyMode() && !$api) { throw new Zikula_Exception_NotFound(__f('The requested controller action %s_Controller_%s::%s() could not be found', array($modname, $type, $func))); } }
/** * load a controller by mapping. this can only be done at this point, * during DI the controller might not yet be available. * * @param string $name the controller name in the format service:actionMethod * * @return array of controller class and method name suitable for call_user_func */ protected function resolveController($name) { // Search for the mapped controller/action $parser = new ControllerNameParser($this->container->get('kernel')); $resolver = new ControllerResolver($this->container, $parser); return $resolver->getController(new Request(array(), array(), array('_controller' => $name))); }