Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Component / Utility / Environment.php
1 <?php
2
3 namespace Drupal\Component\Utility;
4
5 /**
6  * Provides PHP environment helper methods.
7  */
8 class Environment {
9
10   /**
11    * Compares the memory required for an operation to the available memory.
12    *
13    * @param string $required
14    *   The memory required for the operation, expressed as a number of bytes with
15    *   optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G, 6GiB, 8bytes,
16    *   9mbytes).
17    * @param $memory_limit
18    *   (optional) The memory limit for the operation, expressed as a number of
19    *   bytes with optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G,
20    *   6GiB, 8bytes, 9mbytes). If no value is passed, the current PHP
21    *   memory_limit will be used. Defaults to NULL.
22    *
23    * @return bool
24    *   TRUE if there is sufficient memory to allow the operation, or FALSE
25    *   otherwise.
26    */
27   public static function checkMemoryLimit($required, $memory_limit = NULL) {
28     if (!isset($memory_limit)) {
29       $memory_limit = ini_get('memory_limit');
30     }
31
32     // There is sufficient memory if:
33     // - No memory limit is set.
34     // - The memory limit is set to unlimited (-1).
35     // - The memory limit is greater than or equal to the memory required for
36     //   the operation.
37     return ((!$memory_limit) || ($memory_limit == -1) || (Bytes::toInt($memory_limit) >= Bytes::toInt($required)));
38   }
39
40 }