ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 SETTINGS = 'delivery_method';
32  public const XSENDFILE = 'xsendfile';
33  public const XACCEL = 'xaccel';
34  public const PHP = 'php';
35 
36  public function getArtifactName(): string
37  {
38  return "delivery_method";
39  }
40 
41 
42 
43  public function build(): Setup\Artifact
44  {
45  // check if mod_xsendfile is loaded
46  if ($this->isModXSendFileLoaded()) {
47  return new Setup\Artifact\ArrayArtifact([
48  self::SETTINGS => self::XSENDFILE
49  ]);
50  }
51 
52  return new Setup\Artifact\ArrayArtifact([
53  self::SETTINGS => self::PHP
54  ]);
55  }
56 
57  private function isModXSendFileLoaded(): bool
58  {
59  if (function_exists('apache_get_modules') && in_array('mod_xsendfile', apache_get_modules(), true)) {
60  return true;
61  }
62 
63  try {
64  $command_exists = shell_exec("which apache2ctl");
65  if ($command_exists === null || empty($command_exists)) {
66  return false;
67  }
68 
69  $loaded_modules = array_map(static function ($module) {
70  return explode(" ", trim($module))[0] ?? "";
71  }, explode("\n", shell_exec("apache2ctl -M 2>/dev/null") ?? ''));
72  } catch (\Throwable $e) {
73  $loaded_modules = [];
74  }
75  if (in_array('xsendfile_module', $loaded_modules, true)) {
76  return true;
77  }
78  return false;
79  }
80 
81  public function isApplicable(Setup\Environment $environment): bool
82  {
83  return !file_exists(BuildArtifactObjective::PATH());
84  }
85 
86 }
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