SessionStartChecker.php 658 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Framework\Session;
  8. /**
  9. * Class to check if session can be started or not.
  10. */
  11. class SessionStartChecker
  12. {
  13. /**
  14. * @var bool
  15. */
  16. private $checkSapi;
  17. /**
  18. * @param bool $checkSapi
  19. */
  20. public function __construct(bool $checkSapi = true)
  21. {
  22. $this->checkSapi = $checkSapi;
  23. }
  24. /**
  25. * Can session be started or not.
  26. *
  27. * @return bool
  28. */
  29. public function check() : bool
  30. {
  31. return !($this->checkSapi && PHP_SAPI === 'cli');
  32. }
  33. }