ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
DeliveryMethodObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\FileDelivery\Setup;
22 
24 use ILIAS\Setup;
25 
30 {
31  public const ARTIFACT = './src/FileDelivery/artifacts/delivery_method.php';
32  public const SETTINGS = 'delivery_method';
33  public const XSENDFILE = 'xsendfile';
34  public const XACCEL = 'xaccel';
35  public const PHP = 'php';
36 
37  public function getArtifactPath(): string
38  {
39  return self::ARTIFACT;
40  }
41 
42  public function build(): Setup\Artifact
43  {
44  // check if mod_xsendfile is loaded
45  if ($this->isModXSendFileLoaded()) {
46  return new Setup\Artifact\ArrayArtifact([
47  self::SETTINGS => self::XSENDFILE
48  ]);
49  }
50 
51  return new Setup\Artifact\ArrayArtifact([
52  self::SETTINGS => self::PHP
53  ]);
54  }
55 
56  private function isModXSendFileLoaded(): bool
57  {
58  if (function_exists('apache_get_modules') && in_array('mod_xsendfile', apache_get_modules(), true)) {
59  return true;
60  }
61 
62  try {
63  $command_exists = shell_exec("which apache2ctl");
64  if ($command_exists === null || empty($command_exists)) {
65  return false;
66  }
67 
68  $loaded_modules = array_map(static function ($module) {
69  return explode(" ", trim($module))[0] ?? "";
70  }, explode("\n", shell_exec("apache2ctl -M 2>/dev/null") ?? ''));
71  } catch (\Throwable $e) {
72  $loaded_modules = [];
73  }
74  if (in_array('xsendfile_module', $loaded_modules, true)) {
75  return true;
76  }
77  return false;
78  }
79 
80  public function isApplicable(Setup\Environment $environment): bool
81  {
82  return !file_exists(self::ARTIFACT);
83  }
84 
85 }
This is an objective to build some artifact.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:27