@@ -25,52 +25,52 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | trait HooksTrait |
| 27 | 27 | { |
| 28 | - /** |
|
| 28 | + /** |
|
| 29 | 29 | * L'emplacement où la sortie doit être envoyée. |
| 30 | 30 | */ |
| 31 | 31 | public ?string $location = null; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Code de sortie de la tache |
|
| 35 | - */ |
|
| 36 | - protected ?int $exitCode = null; |
|
| 33 | + /** |
|
| 34 | + * Code de sortie de la tache |
|
| 35 | + */ |
|
| 36 | + protected ?int $exitCode = null; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | + /** |
|
| 39 | 39 | * Exception levée lors de l'exécution de la tâche. |
| 40 | 40 | */ |
| 41 | - protected ?Throwable $exception = null; |
|
| 41 | + protected ?Throwable $exception = null; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | + /** |
|
| 44 | 44 | * Indique si la sortie doit être ajoutée. |
| 45 | 45 | */ |
| 46 | 46 | public bool $shouldAppendOutput = false; |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * Tableau de rappels à exécuter avant l'execution de la tâche. |
| 50 | - * |
|
| 51 | - * @var list<Closure> |
|
| 50 | + * |
|
| 51 | + * @var list<Closure> |
|
| 52 | 52 | */ |
| 53 | 53 | protected array $beforeCallbacks = []; |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Tableau de rappels à exécuter après l'execution de la tâche. |
| 57 | - * |
|
| 58 | - * @var list<Closure> |
|
| 57 | + * |
|
| 58 | + * @var list<Closure> |
|
| 59 | 59 | */ |
| 60 | 60 | protected $afterCallbacks = []; |
| 61 | 61 | |
| 62 | - /** |
|
| 62 | + /** |
|
| 63 | 63 | * Met la sortie de la tâche dans un fichier donné. |
| 64 | 64 | */ |
| 65 | 65 | public function sendOutputTo(string $location, bool $append = false): self |
| 66 | 66 | { |
| 67 | - $this->location = $location; |
|
| 68 | - $this->shouldAppendOutput = $append; |
|
| 67 | + $this->location = $location; |
|
| 68 | + $this->shouldAppendOutput = $append; |
|
| 69 | 69 | |
| 70 | 70 | return $this; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - /** |
|
| 73 | + /** |
|
| 74 | 74 | * Ajoute la sortie de la tâche à la fin d'un fichier donné. |
| 75 | 75 | */ |
| 76 | 76 | public function appendOutputTo(string $location): self |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | return $this->sendOutputTo($location, true); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - /** |
|
| 81 | + /** |
|
| 82 | 82 | * Envoi le resultat de l'execution de la tache par mail. |
| 83 | 83 | * |
| 84 | 84 | * @param array|mixed $addresses |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | }); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - /** |
|
| 127 | + /** |
|
| 128 | 128 | * Enregistre un callback à appeler avant l'opération. |
| 129 | 129 | */ |
| 130 | 130 | public function before(Closure $callback): self |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | return $this; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - /** |
|
| 155 | + /** |
|
| 156 | 156 | * Enregistre un callback à appeler si l'opération se deroulle avec succes. |
| 157 | 157 | */ |
| 158 | 158 | public function onSuccess(Closure $callback): self |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | }); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - /** |
|
| 167 | + /** |
|
| 168 | 168 | * Enregistre un callback à appeler si l'opération ne se deroulle pas correctement. |
| 169 | 169 | */ |
| 170 | 170 | public function onFailure(Closure $callback): self |
@@ -176,28 +176,28 @@ discard block |
||
| 176 | 176 | }); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * Procede a l'execution de la tache |
|
| 181 | - */ |
|
| 182 | - protected function process(ContainerInterface $container, $method): mixed |
|
| 183 | - { |
|
| 184 | - ob_start(); |
|
| 179 | + /** |
|
| 180 | + * Procede a l'execution de la tache |
|
| 181 | + */ |
|
| 182 | + protected function process(ContainerInterface $container, $method): mixed |
|
| 183 | + { |
|
| 184 | + ob_start(); |
|
| 185 | 185 | |
| 186 | - $result = $this->start($this->container, $method); |
|
| 186 | + $result = $this->start($this->container, $method); |
|
| 187 | 187 | |
| 188 | - // if (! $this->runInBackground) { |
|
| 189 | - $result = $this->finish($this->container, $result); |
|
| 188 | + // if (! $this->runInBackground) { |
|
| 189 | + $result = $this->finish($this->container, $result); |
|
| 190 | 190 | |
| 191 | - ob_end_flush(); |
|
| 191 | + ob_end_flush(); |
|
| 192 | 192 | |
| 193 | - return $result; |
|
| 193 | + return $result; |
|
| 194 | 194 | // } |
| 195 | - } |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 197 | + /** |
|
| 198 | 198 | * Demarre l'execution de la tache |
| 199 | - * |
|
| 200 | - * @return mixed Le resultat de l'execution de la tache |
|
| 199 | + * |
|
| 200 | + * @return mixed Le resultat de l'execution de la tache |
|
| 201 | 201 | * |
| 202 | 202 | * @throws Throwable |
| 203 | 203 | */ |
@@ -208,30 +208,30 @@ discard block |
||
| 208 | 208 | |
| 209 | 209 | return $this->execute($container, $runMethod); |
| 210 | 210 | } catch (Throwable $e) { |
| 211 | - $this->registerException($e); |
|
| 211 | + $this->registerException($e); |
|
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - /** |
|
| 215 | + /** |
|
| 216 | 216 | * Execute la tache. |
| 217 | - * |
|
| 218 | - * @return mixed Le resultat de l'execution de la tache |
|
| 217 | + * |
|
| 218 | + * @return mixed Le resultat de l'execution de la tache |
|
| 219 | 219 | */ |
| 220 | 220 | protected function execute(ContainerInterface $container, string $runMethod): mixed |
| 221 | 221 | { |
| 222 | - try { |
|
| 223 | - $result = $this->{$runMethod}(); |
|
| 224 | - |
|
| 225 | - if (is_int($result)) { |
|
| 226 | - $this->exitCode = $result; |
|
| 227 | - } else { |
|
| 228 | - $this->exitCode = EXIT_SUCCESS; |
|
| 229 | - } |
|
| 230 | - } catch (Throwable $e) { |
|
| 231 | - $this->registerException($e); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - return $result ?? null; |
|
| 222 | + try { |
|
| 223 | + $result = $this->{$runMethod}(); |
|
| 224 | + |
|
| 225 | + if (is_int($result)) { |
|
| 226 | + $this->exitCode = $result; |
|
| 227 | + } else { |
|
| 228 | + $this->exitCode = EXIT_SUCCESS; |
|
| 229 | + } |
|
| 230 | + } catch (Throwable $e) { |
|
| 231 | + $this->registerException($e); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + return $result ?? null; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -242,12 +242,12 @@ discard block |
||
| 242 | 242 | try { |
| 243 | 243 | $output = $this->callAfterCallbacks($container, $result); |
| 244 | 244 | } finally { |
| 245 | - if (isset($output) && $output !== '' && $this->location !== null) { |
|
| 246 | - @file_put_contents($this->location, $output, $this->shouldAppendOutput ? FILE_APPEND : 0); |
|
| 247 | - } |
|
| 245 | + if (isset($output) && $output !== '' && $this->location !== null) { |
|
| 246 | + @file_put_contents($this->location, $output, $this->shouldAppendOutput ? FILE_APPEND : 0); |
|
| 247 | + } |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - return $result; |
|
| 250 | + return $result; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | return; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - $mailer->to($addresses)->subject($this->getEmailSubject())->text($text)->send(); |
|
| 276 | + $mailer->to($addresses)->subject($this->getEmailSubject())->text($text)->send(); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | return "Sortie de la tâche planifiée pour [{$this->command}]"; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - /** |
|
| 287 | + /** |
|
| 288 | 288 | * Appelle tous les callbacks qui doivent être lancer "avant" l'exécution de la tâche. |
| 289 | 289 | */ |
| 290 | 290 | protected function callBeforeCallbacks(ContainerInterface $container): void |
@@ -294,27 +294,27 @@ discard block |
||
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - /** |
|
| 297 | + /** |
|
| 298 | 298 | * Appelle tous les callbacks qui doivent être lancer "apres" l'exécution de la tâche. |
| 299 | 299 | */ |
| 300 | 300 | protected function callAfterCallbacks(ContainerInterface $container, mixed $result = null): string |
| 301 | 301 | { |
| 302 | - $parameters = ['result' => $result]; |
|
| 302 | + $parameters = ['result' => $result]; |
|
| 303 | 303 | |
| 304 | - if ('' !== $output = ob_get_contents() ?: '') { |
|
| 305 | - $parameters['output'] = new Stringable($output); |
|
| 306 | - } |
|
| 304 | + if ('' !== $output = ob_get_contents() ?: '') { |
|
| 305 | + $parameters['output'] = new Stringable($output); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | 308 | foreach ($this->afterCallbacks as $callback) { |
| 309 | 309 | $container->call($callback, $parameters); |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - return $output; |
|
| 312 | + return $output; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - protected function registerException(Throwable $e) |
|
| 316 | - { |
|
| 317 | - $this->exception = $e; |
|
| 318 | - $this->exitCode = EXIT_ERROR; |
|
| 319 | - } |
|
| 315 | + protected function registerException(Throwable $e) |
|
| 316 | + { |
|
| 317 | + $this->exception = $e; |
|
| 318 | + $this->exitCode = EXIT_ERROR; |
|
| 319 | + } |
|
| 320 | 320 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | $addresses = Arr::wrap($addresses); |
| 93 | 93 | |
| 94 | - return $this->then(function (MailerInterface $mailer) use ($addresses, $onlyIfOutputExists) { |
|
| 94 | + return $this->then(function(MailerInterface $mailer) use ($addresses, $onlyIfOutputExists) { |
|
| 95 | 95 | $this->emailOutput($mailer, $addresses, $onlyIfOutputExists); |
| 96 | 96 | }); |
| 97 | 97 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | $addresses = Arr::wrap($addresses); |
| 121 | 121 | |
| 122 | - return $this->onFailure(function (MailerInterface $mailer) use ($addresses) { |
|
| 122 | + return $this->onFailure(function(MailerInterface $mailer) use ($addresses) { |
|
| 123 | 123 | $this->emailOutput($mailer, $addresses, false); |
| 124 | 124 | }); |
| 125 | 125 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | public function onSuccess(Closure $callback): self |
| 159 | 159 | { |
| 160 | - return $this->then(function (ContainerInterface $container) use ($callback) { |
|
| 160 | + return $this->then(function(ContainerInterface $container) use ($callback) { |
|
| 161 | 161 | if ($this->exitCode === EXIT_SUCCESS) { |
| 162 | 162 | $container->call($callback); |
| 163 | 163 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | public function onFailure(Closure $callback): self |
| 171 | 171 | { |
| 172 | - return $this->then(function (ContainerInterface $container) use ($callback) { |
|
| 172 | + return $this->then(function(ContainerInterface $container) use ($callback) { |
|
| 173 | 173 | if ($this->exitCode !== EXIT_SUCCESS) { |
| 174 | 174 | $container->call($callback, array_filter([$this->exception])); |
| 175 | 175 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | protected function ensureOutputIsBeingCaptured() |
| 259 | 259 | { |
| 260 | 260 | if (is_null($this->output) || $this->output == $this->getDefaultOutput()) { |
| 261 | - $this->sendOutputTo(storage_path('logs/schedule-'.sha1($this->mutexName()).'.log')); |
|
| 261 | + $this->sendOutputTo(storage_path('logs/schedule-' . sha1($this->mutexName()) . '.log')); |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | class Task |
| 36 | 36 | { |
| 37 | 37 | use FrequenciesTrait; |
| 38 | - use HooksTrait; |
|
| 38 | + use HooksTrait; |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Types d'action supportés |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | protected array $environments = []; |
| 59 | 59 | |
| 60 | - /** |
|
| 60 | + /** |
|
| 61 | 61 | * Timezone dans lequel la tâche doit être traitée. |
| 62 | 62 | */ |
| 63 | 63 | protected ?string $timezone = null; |
@@ -69,11 +69,11 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | protected array $attributes = []; |
| 71 | 71 | |
| 72 | - protected ContainerInterface $container; |
|
| 72 | + protected ContainerInterface $container; |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * @param string $type Type de l'action en cours. |
| 76 | - * @param mixed $action Le contenu actuel qu'on souhaite executer. |
|
| 76 | + * @param mixed $action Le contenu actuel qu'on souhaite executer. |
|
| 77 | 77 | * |
| 78 | 78 | * @throws TasksException |
| 79 | 79 | */ |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | throw TasksException::invalidTaskType($type); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - $this->container = service('container'); |
|
| 86 | + $this->container = service('container'); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | throw TasksException::invalidTaskType($this->type); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - return $this->process($this->container, $method); |
|
| 129 | + return $this->process($this->container, $method); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -159,18 +159,18 @@ discard block |
||
| 159 | 159 | return $this; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Définit le fuseau horaire pour l'exécution de la tâche. |
|
| 164 | - * |
|
| 165 | - * @param string $timezone L'identifiant du fuseau horaire à utiliser pour la tâche. |
|
| 166 | - * Il doit s'agir d'une chaîne de caractères PHP valide (par exemple, 'America/New_York', 'Europe/Paris'). |
|
| 167 | - */ |
|
| 168 | - public function timezone(string $timezone): self |
|
| 169 | - { |
|
| 170 | - $this->timezone = $timezone; |
|
| 171 | - |
|
| 172 | - return $this; |
|
| 173 | - } |
|
| 162 | + /** |
|
| 163 | + * Définit le fuseau horaire pour l'exécution de la tâche. |
|
| 164 | + * |
|
| 165 | + * @param string $timezone L'identifiant du fuseau horaire à utiliser pour la tâche. |
|
| 166 | + * Il doit s'agir d'une chaîne de caractères PHP valide (par exemple, 'America/New_York', 'Europe/Paris'). |
|
| 167 | + */ |
|
| 168 | + public function timezone(string $timezone): self |
|
| 169 | + { |
|
| 170 | + $this->timezone = $timezone; |
|
| 171 | + |
|
| 172 | + return $this; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | 175 | /** |
| 176 | 176 | * Renvoie la date à laquelle cette tâche a été exécutée pour la dernière fois. |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function __construct(protected string $type, protected mixed $action, protected array $parameters = []) |
| 81 | 81 | { |
| 82 | - if (! in_array($type, $this->types, true)) { |
|
| 82 | + if (!in_array($type, $this->types, true)) { |
|
| 83 | 83 | throw TasksException::invalidTaskType($type); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | public function run() |
| 123 | 123 | { |
| 124 | 124 | $method = 'run' . ucfirst($this->type); |
| 125 | - if (! method_exists($this, $method)) { |
|
| 125 | + if (!method_exists($this, $method)) { |
|
| 126 | 126 | throw TasksException::invalidTaskType($this->type); |
| 127 | 127 | } |
| 128 | 128 | |
@@ -137,12 +137,12 @@ discard block |
||
| 137 | 137 | $cron = service('cronExpression')->setTimezone($this->timezone); |
| 138 | 138 | |
| 139 | 139 | // Autoriser le réglage des heures pendant les tests |
| 140 | - if (! empty($testTime)) { |
|
| 140 | + if (!empty($testTime)) { |
|
| 141 | 141 | $cron->testTime($testTime); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // Sommes-nous limités aux environnements? |
| 145 | - if (! $this->runsInEnvironment(environment())) { |
|
| 145 | + if (!$this->runsInEnvironment(environment())) { |
|
| 146 | 146 | return false; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | protected function runEvent(): bool |
| 246 | 246 | { |
| 247 | - return ! (false === service('event')->emit($this->getAction())); |
|
| 247 | + return !(false === service('event')->emit($this->getAction())); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |