Invoke action

@return mixed|null
@throws BaseException
@throws MissingMethodException
181572
final public function invoker()
    {
        $this->getEventManager()->addSubscriber($this);

        $this->dispatchEvent(Action::EVENT_BEFORE_WEB_METHOD, $this, ['request' => $this->getRequest()]);
        $response = call_user_func_array($this, func_get_args());
        $this->dispatchEvent(
            Action::EVENT_AFTER_WEB_METHOD,
            $this,
            ['request' => $this->getRequest(), 'response' => $response]
        );

        if ($response instanceof Response) {
            return $response;
        }

        if ($this->getResponder()) {
            $response = call_user_func_array([$this->getResponder(), 'invoker'], func_get_args());

            if (!$response instanceof Response) {
                throw new BaseException(
                    sprintf('Responder "%s" must be return Response object.', get_class($this->getResponder()))
                );
            }

            return $response;
        }
    }
703281
@Override
  public Object invoke(final ELContext context, final Object base, final Object method,
      Class<?>[] paramTypes, final Object[] params) {
    if ((base == null) || (method == null)) {
      return null;
    }

    final MethodDescriptor[] methodDescriptors = getMethodDescriptors(context, base);

    if (methodDescriptors != null) {
      final Method m =
          findMethodOrThrow(method.toString(), paramTypes, params, false, methodDescriptors);
      paramTypes = m.getParameterTypes();
    }

    return super.invoke(context, base, method, paramTypes, params);
  }
878923
public function execute()
    {
        try {
            if ($action = $this->action) {
                return $action($this);
            } else {
                foreach ($this->parseSteps as $parseStep) {
                    if (is_string($parseStep)) {
                        $parseStep = [$this->controller, $parseStep];
                    }

                    if ($parseStep($this) === false) {
                        return false;
                    }
                }

                $queryStep = $this->queryStep;
                if (is_string($queryStep)) {
                    $queryStep = [$this->controller, $queryStep];
                }

                $result = $queryStep($this);

                foreach ($this->transformSteps as $transformStep) {
                    if (is_string($transformStep)) {
                        $transformStep = [$this->controller, $transformStep];
                    }

                    if ($transformStep($result, $this) === false) {
                        return false;
                    }
                }
            }
        // handle API exceptions
        } catch (Error\Base $ex) {
            if (method_exists($this->controller, 'handleError')) {
                $this->controller->handleError($ex, $this);
            }
        }

        return true;
    }
1095847
protected function runCallable()
    {
        $callable = $this->action['uses'];

        $parameters = $this->resolveMethodDependencies(
            $this->parametersWithoutNulls(), new ReflectionFunction($callable)
        );

        return call_user_func_array($callable, $parameters);
    }
304246
protected function invokeRegisterAction($arg) {
        list($class, $action) = explode('@', $arg);
        if (!class_exists($class)) {
            return $this->invokeController('Service\\'.app('app.module').'\\'.$class, $action);
        }
        $reflectionClass = new ReflectionClass( $class );
        $method = $reflectionClass->getMethod($action);

        $parameters = $method->getParameters();
        $arguments = array();
        foreach ($parameters as $param) {
            $arguments[] = app('request')->get($param->getName());
        }
        return call_user_func_array(array(new $class, $action), $arguments);
    }
697808
function invoke() {
        parent::invoke();

        $result = true;

        // Set own core attributes
        $this->does_generate = ACTION_NONE;
        //$this->does_generate = ACTION_GENERATE_HTML;

        // These are always here
        global $CFG, $XMLDB;

        // Do the job, setting $result as needed

        // Get the dir containing the file
        $dirpath = required_param('dir', PARAM_PATH);
        $dirpath = $CFG->dirroot . $dirpath;

        // Get the correct dir
        if (!empty($XMLDB->dbdirs)) {
            $dbdir = $XMLDB->dbdirs[$dirpath];
            if ($dbdir) {
                // Set some defaults
                $dbdir->xml_exists = false;
                $dbdir->xml_writeable = false;
                $dbdir->xml_loaded  = false;
                // Only if the directory exists
                if (!$dbdir->path_exists) {
                    return false;
                }
                $xmldb_file = new xmldb_file($dbdir->path . '/install.xml');
                // Set the XML DTD and schema
                $xmldb_file->setDTD($CFG->dirroot . '/lib/xmldb/xmldb.dtd');
                $xmldb_file->setSchema($CFG->dirroot . '/lib/xmldb/xmldb.xsd');
                // Set dbdir as necessary
                if ($xmldb_file->fileExists()) {
                    $dbdir->xml_exists = true;
                }
                if ($xmldb_file->fileWriteable()) {
                    $dbdir->xml_writeable = true;
                }
                // Load the XML contents to structure
                $loaded = $xmldb_file->loadXMLStructure();
                if ($loaded && $xmldb_file->isLoaded()) {
                    $dbdir->xml_loaded = true;
                    $dbdir->filemtime = filemtime($dbdir->path . '/install.xml');
                }
                $dbdir->xml_file = $xmldb_file;
            } else {
                $this->errormsg = 'Wrong directory (' . $dirpath . ')';
                $result = false;
            }
        } else {
            $this->errormsg = 'XMLDB structure not found';
            $result = false;
        }
        // Launch postaction if exists
        if ($this->getPostAction() && $result) {
            return $this->launch($this->getPostAction());
        }

        return $result;
    }
990629
function invoke() {
        parent::invoke();

        $result = true;

        // Set own core attributes
        $this->does_generate = ACTION_GENERATE_HTML;

        // These are always here
        global $CFG, $XMLDB, $OUTPUT;

        // Do the job, setting result as needed
        // Get the dir containing the file
        $dirpath = required_param('dir', PARAM_PATH);
        $dirpath = $CFG->dirroot . $dirpath;

        // Get the correct dirs
        if (!empty($XMLDB->dbdirs)) {
            $dbdir = $XMLDB->dbdirs[$dirpath];
        } else {
            return false;
        }
        if (!empty($XMLDB->editeddirs)) {
            $editeddir = $XMLDB->editeddirs[$dirpath];
            $structure = $editeddir->xml_file->getStructure();
        }

        $tables = $structure->getTables();
        $table = reset($tables);
        $defaulttable = null;
        if ($table) {
            $defaulttable = $table->getName();
        }

        // Get parameters
        $commandparam = optional_param('command', 'create_table', PARAM_PATH);
        $tableparam = optional_param('table', $defaulttable, PARAM_PATH);

        // The back to edit xml button
        $b = ' <p class="centerpara buttons">';
        $b .= '<a href="index.php?action=edit_xml_file&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
        $b .= '</p>';
        $o = $b;

        // Calculate the popup of commands
        $commands = array('create_table',
                         'drop_table',
                         'rename_table');
        foreach ($commands as $command) {
            $popcommands[$command] = str_replace('_', ' ', $command);
        }
        // Calculate the popup of tables
        foreach ($tables as $table) {
            $poptables[$table->getName()] = $table->getName();
        }
        // Now build the form
        $o.= '<form id="form" action="index.php" method="post">';
        $o.='<div>';
        $o.= '    <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
        $o.= '    <input type="hidden" name ="action" value="view_structure_php" />';
        $o.= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
        $o.= '      <tr><td><label for="menucommand" accesskey="c">' . $this->str['selectaction'] .' </label>' . html_writer::select($popcommands, 'command', $commandparam, false) . '&nbsp;<label for="menutable" accesskey="t">' . $this->str['selecttable'] . ' </label>' .html_writer::select($poptables, 'table', $tableparam, false) . '</td></tr>';
        $o.= '      <tr><td colspan="2" align="center"><input type="submit" value="' .$this->str['view'] . '" /></td></tr>';
        $o.= '    </table>';
        $o.= '</div></form>';
        $o.= '    <table id="phpcode" class="boxaligncenter" cellpadding="5">';
        $o .= '      <tr><td><textarea cols="80" rows="32" class="form-control">';
        // Based on current params, call the needed function
        switch ($commandparam) {
            case 'create_table':
                $o.= s($this->create_table_php($structure, $tableparam));
                break;
            case 'drop_table':
                $o.= s($this->drop_table_php($structure, $tableparam));
                break;
            case 'rename_table':
                $o.= s($this->rename_table_php($structure, $tableparam));
                break;
        }
        $o.= '</textarea></td></tr>';
        $o.= '    </table>';

        $this->output = $o;

        // Launch postaction if exists (leave this here!)
        if ($this->getPostAction() && $result) {
            return $this->launch($this->getPostAction());
        }

        // Return ok if arrived here
        return $result;
    }
902863
function invoke() {
        parent::invoke();

        $result = true;

        // Set own core attributes
        $this->does_generate = ACTION_GENERATE_HTML;

        // These are always here
        global $CFG, $XMLDB, $DB;

        // Calculate list of available SQL generators
        require_once("$CFG->libdir/ddl/sql_generator.php");
        $reserved_words = sql_generator::getAllReservedWords();

        // Now, calculate, looking into current DB (with AdoDB Metadata), which fields are
        // in the list of reserved words
        $wronguses = array();
        $dbtables = $DB->get_tables();
        if ($dbtables) {
            foreach ($dbtables as $table) {
                if (array_key_exists($table, $reserved_words)) {
                    $wronguses[] = $this->str['table'] . ' - ' . $table . ' (' . implode(', ',$reserved_words[$table]) . ')';

                }
                $dbfields = $DB->get_columns($table);
                if ($dbfields) {
                    foreach ($dbfields as $dbfield) {
                        if (array_key_exists($dbfield->name, $reserved_words)) {
                            $wronguses[] = $this->str['field'] . ' - ' . $table . '->' . $dbfield->name . ' (' . implode(', ',$reserved_words[$dbfield->name]) . ')';
                        }
                    }
                }
            }
        }

        // Sort the wrong uses
        sort($wronguses);

        // The back to edit table button
        $b = ' <p class="centerpara buttons">';
        $b .= '<a href="index.php">[' . $this->str['back'] . ']</a>';
        $b .= '</p>';
        $o = $b;

        // The list of currently wrong field names
        if ($wronguses) {
            $o.= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
            $o.= '      <tr><td align="center"><font color="red">' . $this->str['wrongreservedwords'] . '</font></td></tr>';
            $o.= '      <tr><td>';
            $o.= '        <ul><li>' . implode('</li><li>', $wronguses) . '</li></ul>';
            $o.= '      </td></tr>';
            $o.= '    </table>';
        }

        // The textarea showing all the reserved words
        $o.= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
        $o.= '      <tr><td align="center">' . $this->str['listreservedwords'].'</td></tr>';
        $o .= '      <tr><td><textarea cols="80" rows="32" class="form-control">';
        $o.= s(implode(', ', array_keys($reserved_words)));
        $o.= '</textarea></td></tr>';
        $o.= '    </table>';

        $this->output = $o;

        // Launch postaction if exists (leave this here!)
        if ($this->getPostAction() && $result) {
            return $this->launch($this->getPostAction());
        }

        // Return ok if arrived here
        return $result;
    }
1212054
@Override
    public Object invoke(Object controller, String action) throws Throwable {
        if(action == null) action = this.defaultActionName;
        ActionInvoker handle = actions.get(action);
        if(handle == null) throw new IllegalArgumentException("Invalid action name: " + action);
        return handle.invoke(controller);
    }
864756
function performAction($controller,$action,$queryString = null,$render = 0) {
		$controllerFile = ROOT . '/application/controllers/' . $controller . "controller.php";
		//print "Trying to load $controllerFile<br>";
		if (file_exists($controllerFile)){
			//print "File exists<br>";
			include_once($controllerFile);
		} else {
			throw new Exception("Controller file: $controllerFile does not exists");
		}
		$controllerName = ucfirst($controller).'Controller';
		$actionName= $action . 'Action'; // This is done to avoid clash with reserved function names like list();
		if (class_exists($controllerName)){
			
		} else {
			throw new Exception("ControllerClass: $controllerName does not exists");
		}

		//print "Trying to load $controllerName<br>"; 
		$dispatch = new $controllerName($controller, $action);
		$dispatch->render = $render;
		$dispatch->$actionName($queryString);

		if ($dispatch->render >0) {
				$dispatch->display();
		}

	}
874090
public function invoke(ServerRequestInterface $request, RouteParams $params)
    {
        $callable = $this->callable;

        // Controller Actions are lazy loaded so we need to call the factory to get the callable
        if ($this->isControllerAction()) {
            $callable = call_user_func($this->callable);
        }

        // Call the target action with any provided params
        if ($this->invoker) {
            return $this->invoker->setRequest($request)->call($callable, $params->toArray());
        } else {
            return call_user_func($callable, $params);
        }
    }
922992
function invoke() {
        parent::invoke();

        $result = true;

        // Set own core attributes
        $this->does_generate = ACTION_GENERATE_HTML;

        // These are always here
        global $CFG, $XMLDB;

        // Do the job, setting $result as needed

        // Get the dir containing the file
        $dirpath = required_param('dir', PARAM_PATH);
        $dirpath = $CFG->dirroot . $dirpath;
        $path = $dirpath.'/install.xml';
        if(!file_exists($path) || !is_readable($path)) {
            return false;
        }

        // Add link back to home
        $b = ' <p class="centerpara buttons">';
        $b .= '&nbsp;<a href="index.php?action=main_view#lastused">[' . $this->str['backtomainview'] . ']</a>';
        $b .= '</p>';
        $this->output=$b;

        $c = ' <p class="centerpara">';
        $c .= $this->str['documentationintro'];
        $c .= '</p>';
        $this->output.=$c;

        if(class_exists('XSLTProcessor')) {
            // Transform XML file and display it
            $doc = new DOMDocument();
            $xsl = new XSLTProcessor();

            $doc->load(__DIR__.'/xmldb.xsl');
            $xsl->importStyleSheet($doc);

            $doc->load($path);
            $this->output.=$xsl->transformToXML($doc);
            $this->output.=$b;
        } else {
            $this->output.=get_string('extensionrequired','tool_xmldb','xsl');
        }

        // Launch postaction if exists (leave this unmodified)
        if ($this->getPostAction() && $result) {
            return $this->launch($this->getPostAction());
        }

        return $result;
    }
223574
public function execAction()
    {
        //no action defined
        if(!$this->action) {
            throw new \Exception(sprintf('no action defined for subject %s', $this->name));
        }
        //exec method
        try {
            $this->checkTraitsInjections();
            $this->traitsInit();
            $this->{'exec'.$this->sanitizeAction($this->action)}();
        } catch(Exception $exception) {
        //no method defined
            throw new Exception(sprintf('no method for handling %s %s %s', AREA, $this->name, $this->action));
        }
    }
795541
function invoke() {
        parent::invoke();

        $result = true;

        // Set own core attributes
        $this->does_generate = ACTION_GENERATE_HTML;

        // These are always here
        global $CFG, $XMLDB, $DB, $OUTPUT;

        // Do the job, setting result as needed
        // Get the dir containing the file
        $dirpath = required_param('dir', PARAM_PATH);
        $dirpath = $CFG->dirroot . $dirpath;

        // Get the correct dirs
        if (!empty($XMLDB->dbdirs)) {
            $dbdir = $XMLDB->dbdirs[$dirpath];
        } else {
            return false;
        }
        if (!empty($XMLDB->editeddirs)) {
            $editeddir = $XMLDB->editeddirs[$dirpath];
            $structure = $editeddir->xml_file->getStructure();
        }

        $tableparam = optional_param('table', NULL, PARAM_CLEAN);

        // If no table, show form
        if (!$tableparam) {
            // No postaction here
            $this->postaction = NULL;
            // Get list of tables
            $dbtables = $DB->get_tables();
            $selecttables = array();
            foreach ($dbtables as $dbtable) {
                $i = $structure->findTableInArray($dbtable);
                if ($i === NULL) {
                    $selecttables[$dbtable] = $dbtable;
                }
            }
            // Get list of after tables
            $aftertables = array();
            if ($tables = $structure->getTables()) {
                foreach ($tables as $aftertable) {
                    $aftertables[$aftertable->getName()] = $aftertable->getName();
                }
            }
            if (!$selecttables) {
                $this->errormsg = 'No tables available to be retrofitted';
                return false;
            }
            // Now build the form
            $o = '<form id="form" action="index.php" method="post">';
            $o .= '<div>';
            $o.= '    <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
            $o.= '    <input type="hidden" name ="action" value="new_table_from_mysql" />';
            $o.= '    <input type="hidden" name ="postaction" value="edit_table" />';
            $o.= '    <input type="hidden" name ="sesskey" value="' . sesskey() . '" />';
            $o.= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
            $o.= '      <tr><td><label for="menutable" accesskey="t">' . $this->str['createtable'] .' </label>' . html_writer::select($selecttables, 'table') . '<label for="menuafter" accesskey="a">' . $this->str['aftertable'] . ' </label>' .html_writer::select($aftertables, 'after') . '</td></tr>';
            $o.= '      <tr><td colspan="2" align="center"><input type="submit" value="' .$this->str['create'] . '" /></td></tr>';
            $o.= '      <tr><td colspan="2" align="center"><a href="index.php?action=edit_xml_file&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a></td></tr>';
            $o.= '    </table>';
            $o.= '</div></form>';

            $this->output = $o;


        // If table, retrofit information and, if everything works,
        // go to the table edit action
        } else {
            // Get some params (table is mandatory here)
            $tableparam = required_param('table', PARAM_CLEAN);
            $afterparam = required_param('after', PARAM_CLEAN);

            // Create one new xmldb_table
            $table = new xmldb_table(strtolower(trim($tableparam)));
            $table->setComment($table->getName() . ' table retrofitted from MySQL');
            // Get fields info from ADODb
            $dbfields = $DB->get_columns($tableparam);
            if ($dbfields) {
                foreach ($dbfields as $dbfield) {
                    // Create new XMLDB field
                    $field = new xmldb_field($dbfield->name);
                    // Set field with info retrofitted
                    $field->setFromADOField($dbfield);
                    // Add field to the table
                    $table->addField($field);
                }
            }
            // Get PK, UK and indexes info from ADODb
            $dbindexes = $DB->get_indexes($tableparam);
            if ($dbindexes) {
                $lastkey = NULL; //To temp store the last key processed
                foreach ($dbindexes as $indexname => $dbindex) {
                    // Add the indexname to the array
                    $dbindex['name'] = $indexname;
                    // We are handling one xmldb_key (primaries + uniques)
                    if ($dbindex['unique']) {
                        $key = new xmldb_key(strtolower($dbindex['name']));
                        // Set key with info retrofitted
                        $key->setFromADOKey($dbindex);
                        // Set default comment to PKs
                        if ($key->getType() == XMLDB_KEY_PRIMARY) {
                        }
                        // Add key to the table
                        $table->addKey($key);

                    // We are handling one xmldb_index (non-uniques)
                    } else {
                        $index = new xmldb_index(strtolower($dbindex['name']));
                        // Set index with info retrofitted
                        $index->setFromADOIndex($dbindex);
                        // Add index to the table
                        $table->addIndex($index);
                    }
                }
            }
            // Finally, add the whole retroffited table to the structure
            // in the place specified
            $structure->addTable($table, $afterparam);
        }

        // Launch postaction if exists (leave this here!)
        if ($this->getPostAction() && $result) {
            return $this->launch($this->getPostAction());
        }

        // Return ok if arrived here
        return $result;
    }
711598
private function invokeMethod()
    {
        if ($this->located_controller === NULL)
        {
            throw new Exception('404 Not Found.');
        }

        $class = "App\\Controller\\" . $this->located_controller;

        if (!class_exists($class))
        {
            throw new Exception("$class class not found.");
        }

        $controller = new $class;
        if (method_exists($controller, $this->located_method))
        {
            $reflection = new ReflectionMethod($controller, $this->located_method);

            # Perpareing method parameter from remaining url.
            $parameter = array();
            $index = 0;
            foreach ($reflection->getParameters() as $param)
            {
                if (array_key_exists($index, $this->remaining_uri))
                {
                    $parameter[$index] = $this->remaining_uri[$index];
                }
                else if ($param->isOptional())
                {
                    $parameter[$index] = $param->getDefaultValue();
                }
                else
                {
                    throw new Exception('Not found.');
                }
                $index++;
            }

            $reflection->invokeArgs($controller, $parameter);
        }
    }
1096929
function invoke() {
        parent::invoke();

        $result = true;

        // Set own core attributes
        $this->does_generate = ACTION_GENERATE_HTML;

        // These are always here
        global $CFG, $XMLDB, $DB;
        $dbman = $DB->get_manager();

        // Do the job, setting result as needed
        // Get the dir containing the file
        $dirpath = required_param('dir', PARAM_PATH);
        $dirpath = $CFG->dirroot . $dirpath;

        // Get the correct dirs
        if (!empty($XMLDB->dbdirs)) {
            $dbdir = $XMLDB->dbdirs[$dirpath];
        } else {
            return false;
        }
        if (!empty($XMLDB->editeddirs)) {
            $editeddir = $XMLDB->editeddirs[$dirpath];
            $structure = $editeddir->xml_file->getStructure();
        }

        // Get parameters
        $tableparam = required_param('table', PARAM_PATH);
        if (!$table = $structure->getTable($tableparam)) {
            $this->errormsg = 'Wrong table specified: ' . $tableparam;
            return false;
        }

        // The back to edit table button
        $b = ' <p class="centerpara buttons">';
        $b .= '<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
        $b .= '</p>';
        $o = $b;

        $o.= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
        $o .= '      <tr><td><textarea cols="80" rows="32" class="form-control">';

        // Get an array of statements
        if ($starr = $DB->get_manager()->generator->getCreateTableSQL($table)) {
            $starr = $dbman->generator->getEndedStatements($starr);
            $sqltext = '';
            foreach ($starr as $st) {
                $sqltext .= s($st) . "\n\n";
            }
            $sqltext = trim($sqltext);
            $o.= $sqltext;
        }
        $o.= '</textarea></td></tr>';
        $o.= '    </table>';

        $this->output = $o;

        // Launch postaction if exists (leave this here!)
        if ($this->getPostAction() && $result) {
            return $this->launch($this->getPostAction());
        }

        // Return ok if arrived here
        return $result;
    }
1117686
public function invoke($method, $_ = null)
	{
		$params = func_get_args();
		array_shift($params);

		return $this->invokeArgs($method, $params);
	}