Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  
   3  # required: PHP 5.3+ and zlib extension
   4  
   5  // ini option check
   6  if (ini_get('phar.readonly')) {
   7      echo "php.ini: set the 'phar.readonly' option to 0 to enable phar creation\n";
   8      exit(1);
   9  }
  10  
  11  // output name
  12  $pharName = 'Matrix.phar';
  13  
  14  // target folder
  15  $sourceDir = __DIR__ . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR;
  16  
  17  // default meta information
  18  $metaData = array(
  19      'Author'      => 'Mark Baker <mark@lange.demon.co.uk>',
  20      'Description' => 'PHP Class for working with Matrix numbers',
  21      'Copyright'   => 'Mark Baker (c) 2013-' . date('Y'),
  22      'Timestamp'   => time(),
  23      'Version'     => '0.1.0',
  24      'Date'        => date('Y-m-d')
  25  );
  26  
  27  // cleanup
  28  if (file_exists($pharName)) {
  29      echo "Removed: {$pharName}\n";
  30      unlink($pharName);
  31  }
  32  
  33  echo "Building phar file...\n";
  34  
  35  // the phar object
  36  $phar = new Phar($pharName, null, 'Matrix');
  37  $phar->buildFromDirectory($sourceDir);
  38  $phar->setStub(
  39  <<<'EOT'
  40  <?php
  41      spl_autoload_register(function ($className) {
  42          include 'phar://' . $className . '.php';
  43      });
  44  
  45      try {
  46          Phar::mapPhar();
  47      } catch (PharException $e) {
  48          error_log($e->getMessage());
  49          exit(1);
  50      }
  51  
  52      include 'phar://functions/sqrt.php';
  53  
  54      __HALT_COMPILER();
  55  EOT
  56  );
  57  $phar->setMetadata($metaData);
  58  $phar->compressFiles(Phar::GZ);
  59  
  60  echo "Complete.\n";
  61  
  62  exit();