Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
State Class Reference
Inheritance diagram for State:
State

Public Member Functions

 __construct (\Magento\Framework\Config\ScopeInterface $configScope, $mode=self::MODE_DEFAULT)
 
 getMode ()
 
 setIsDownloader ($flag=true)
 
 setAreaCode ($code)
 
 getAreaCode ()
 
 isAreaCodeEmulated ()
 
 emulateAreaCode ($areaCode, $callback, $params=[])
 

Data Fields

const PARAM_MODE = 'MAGE_MODE'
 
const MODE_DEVELOPER = 'developer'
 
const MODE_PRODUCTION = 'production'
 
const MODE_DEFAULT = 'default'
 

Protected Attributes

 $_appMode
 
 $_isDownloader = false
 
 $_updateMode = false
 
 $_configScope
 
 $_areaCode
 
 $_isAreaCodeEmulated = false
 

Detailed Description

Application state flags. Can be used to retrieve current application mode and current area.

Note: Area code communication and emulation will be removed from this class.

@api

Since
100.0.2

Definition at line 17 of file State.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Config\ScopeInterface  $configScope,
  $mode = self::MODE_DEFAULT 
)

#-

Parameters
\Magento\Framework\Config\ScopeInterface$configScope
string$mode
Exceptions

Definition at line 87 of file State.php.

90  {
91  $this->_configScope = $configScope;
92  switch ($mode) {
95  case self::MODE_DEFAULT:
96  $this->_appMode = $mode;
97  break;
98  default:
99  throw new \InvalidArgumentException("Unknown application mode: {$mode}");
100  }
101  }
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15

Member Function Documentation

◆ emulateAreaCode()

emulateAreaCode (   $areaCode,
  $callback,
  $params = [] 
)

Emulate callback inside some area code

Parameters
string$areaCode
callable$callback
array$params
Returns
mixed
Exceptions

Definition at line 179 of file State.php.

180  {
181  $this->checkAreaCode($areaCode);
182 
183  $currentArea = $this->_areaCode;
184  $this->_areaCode = $areaCode;
185  $this->_isAreaCodeEmulated = true;
186  try {
187  $result = call_user_func_array($callback, $params);
188  } catch (\Exception $e) {
189  $this->_areaCode = $currentArea;
190  $this->_isAreaCodeEmulated = false;
191  throw $e;
192  }
193  $this->_areaCode = $currentArea;
194  $this->_isAreaCodeEmulated = false;
195  return $result;
196  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getAreaCode()

getAreaCode ( )

Get area code

Returns
string
Exceptions

Definition at line 150 of file State.php.

151  {
152  if (!isset($this->_areaCode)) {
153  throw new \Magento\Framework\Exception\LocalizedException(
154  new \Magento\Framework\Phrase('Area code is not set')
155  );
156  }
157  return $this->_areaCode;
158  }

◆ getMode()

getMode ( )

Return current app mode

Returns
string

Definition at line 108 of file State.php.

109  {
110  return $this->_appMode;
111  }

◆ isAreaCodeEmulated()

isAreaCodeEmulated ( )

Checks whether area code is being emulated

Returns
bool

Definition at line 165 of file State.php.

166  {
168  }

◆ setAreaCode()

setAreaCode (   $code)

Set area code

Parameters
string$code
Returns
void
Exceptions

Definition at line 131 of file State.php.

132  {
133  $this->checkAreaCode($code);
134 
135  if (isset($this->_areaCode)) {
136  throw new \Magento\Framework\Exception\LocalizedException(
137  new \Magento\Framework\Phrase('Area code is already set')
138  );
139  }
140  $this->_configScope->setCurrentScope($code);
141  $this->_areaCode = $code;
142  }
$code
Definition: info.phtml:12

◆ setIsDownloader()

setIsDownloader (   $flag = true)

Set is downloader flag

Parameters
bool$flag
Returns
void

Definition at line 119 of file State.php.

120  {
121  $this->_isDownloader = $flag;
122  }

Field Documentation

◆ $_appMode

$_appMode
protected

Definition at line 29 of file State.php.

◆ $_areaCode

$_areaCode
protected

Definition at line 57 of file State.php.

◆ $_configScope

$_configScope
protected

Definition at line 50 of file State.php.

◆ $_isAreaCodeEmulated

$_isAreaCodeEmulated = false
protected

Definition at line 64 of file State.php.

◆ $_isDownloader

$_isDownloader = false
protected

Definition at line 36 of file State.php.

◆ $_updateMode

$_updateMode = false
protected

Definition at line 43 of file State.php.

◆ MODE_DEFAULT

const MODE_DEFAULT = 'default'

Definition at line 78 of file State.php.

◆ MODE_DEVELOPER

const MODE_DEVELOPER = 'developer'

#+ Application modes

Definition at line 74 of file State.php.

◆ MODE_PRODUCTION

const MODE_PRODUCTION = 'production'

Definition at line 76 of file State.php.

◆ PARAM_MODE

const PARAM_MODE = 'MAGE_MODE'

Application run code

Definition at line 22 of file State.php.


The documentation for this class was generated from the following file: