#!/usr/bin/php "lancer un script en tâche de fond", "usage" => "ApplicationClass args...", ["-i", "--infos", "name" => "action", "value" => self::ACTION_INFOS, "help" => "Afficher des informations sur la tâche", ], ["-s", "--start", "name" => "action", "value" => self::ACTION_START, "help" => "Démarrer la tâche", ], ["-k", "--stop", "name" => "action", "value" => self::ACTION_STOP, "help" => "Arrêter la tâche", ], ]; protected int $action = self::ACTION_START; protected ?array $args = null; function main() { $appClass = $this->args[0] ?? null; if ($appClass === null) { self::die("Vous devez spécifier la classe de l'application"); } $appClass = str_replace("/", "\\", $appClass); if (!class_exists($appClass)) { self::die("$appClass: classe non trouvée"); } $args = array_slice($this->args, 1); $useRunfile = constant("$appClass::USE_RUNFILE"); if (!$useRunfile) { self::die("Cette application ne supporte le lancement en tâche de fond"); } $runfile = app2::with($appClass)->getRunfile(); switch ($this->action) { case self::ACTION_START: bg_launcher::_start($args, $runfile); break; case self::ACTION_STOP: bg_launcher::_stop($runfile); break; case self::ACTION_INFOS: yaml::dump($runfile->read()); break; } } } $params = app2::params_getenv(); if ($params !== null) app2::init($params); BgLauncherApp::run();