IniHelper.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Util;
  12. use Composer\XdebugHandler\XdebugHandler;
  13. /**
  14. * Provides ini file location functions that work with and without a restart.
  15. * When the process has restarted it uses a tmp ini and stores the original
  16. * ini locations in an environment variable.
  17. *
  18. * @author John Stevenson <john-stevenson@blueyonder.co.uk>
  19. */
  20. class IniHelper
  21. {
  22. /**
  23. * Returns an array of php.ini locations with at least one entry
  24. *
  25. * The equivalent of calling php_ini_loaded_file then php_ini_scanned_files.
  26. * The loaded ini location is the first entry and may be empty.
  27. *
  28. * @return array
  29. */
  30. public static function getAll()
  31. {
  32. return XdebugHandler::getAllIniFiles();
  33. }
  34. /**
  35. * Describes the location of the loaded php.ini file(s)
  36. *
  37. * @return string
  38. */
  39. public static function getMessage()
  40. {
  41. $paths = self::getAll();
  42. if (empty($paths[0])) {
  43. array_shift($paths);
  44. }
  45. $ini = array_shift($paths);
  46. if (empty($ini)) {
  47. return 'A php.ini file does not exist. You will have to create one.';
  48. }
  49. if (!empty($paths)) {
  50. return 'Your command-line PHP is using multiple ini files. Run `php --ini` to show them.';
  51. }
  52. return 'The php.ini used by your command-line PHP is: '.$ini;
  53. }
  54. }