Yaf_Application::execute

(Yaf >=1.0.0)

Yaf_Application::executeExecute a callback

Description

public function Yaf_Application::execute(callable $callback, mixed ...$args): mixed

Execute a callback. This method is typically used to run Yaf in a cron job or other CLI script, so that the script can reuse the autoloader and the bootstrap mechanism.

Parameters

callback

A valid callback to execute.

args

Optional parameters passed to the callback.

Return Values

Returns whatever the callback returns, or false if calling the callback failed.

Examples

Example #1 Yaf_Application::execute() example

<?php
function main($argc, $argv) {
    var_dump($argc);
    var_dump($argv);
}

$config = array(
    "application" => array(
        "directory" => realpath(dirname(__FILE__)) . "/application",
    ),
);

/** Yaf_Application */
$application = new Yaf_Application($config);
$application->execute("main", $argc, $argv);
?>

The above example will output something similar to:

int(2)
array(2) {
  [0]=>
  string(11) "execute.php"
  [1]=>
  string(3) "arg"
}

See Also

add a note

User Contributed Notes

There are no user contributed notes for this page.