You are here

class Environment in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Component/Utility/Environment.php \Drupal\Component\Utility\Environment

Provides PHP environment helper methods.

Hierarchy

Expanded class hierarchy of Environment

5 files declare their use of Environment
color.module in core/modules/color/color.module
Allows users to change the color scheme of themes.
EnvironmentTest.php in core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php
Contains \Drupal\Tests\Component\Utility\EnvironmentTest.
LargeQueryTest.php in core/modules/system/src/Tests/Database/LargeQueryTest.php
Contains \Drupal\system\Tests\Database\LargeQueryTest.
simpletest.install in core/modules/simpletest/simpletest.install
Install, update and uninstall functions for the simpletest module.
system.install in core/modules/system/system.install
Install, update and uninstall functions for the system module.

File

core/lib/Drupal/Component/Utility/Environment.php, line 13
Contains \Drupal\Component\Utility\Environment.

Namespace

Drupal\Component\Utility
View source
class Environment {

  /**
   * Compares the memory required for an operation to the available memory.
   *
   * @param string $required
   *   The memory required for the operation, expressed as a number of bytes with
   *   optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G, 6GiB, 8bytes,
   *   9mbytes).
   * @param $memory_limit
   *   (optional) The memory limit for the operation, expressed as a number of
   *   bytes with optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G,
   *   6GiB, 8bytes, 9mbytes). If no value is passed, the current PHP
   *   memory_limit will be used. Defaults to NULL.
   *
   * @return bool
   *   TRUE if there is sufficient memory to allow the operation, or FALSE
   *   otherwise.
   */
  public static function checkMemoryLimit($required, $memory_limit = NULL) {
    if (!isset($memory_limit)) {
      $memory_limit = ini_get('memory_limit');
    }

    // There is sufficient memory if:
    // - No memory limit is set.
    // - The memory limit is set to unlimited (-1).
    // - The memory limit is greater than or equal to the memory required for
    //   the operation.
    return !$memory_limit || $memory_limit == -1 || Bytes::toInt($memory_limit) >= Bytes::toInt($required);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Environment::checkMemoryLimit public static function Compares the memory required for an operation to the available memory.