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

Public Member Functions

 __construct (\Magento\Framework\Shell $shell, $installDir, $installConfigFile, $globalConfigFile, $globalConfigDir, $appMode, AutoloaderInterface $autoloadWrapper, $loadTestExtensionAttributes=false)
 
 getDbInstance ()
 
 getTempDir ()
 
 getInitParams ()
 
 isInstalled ()
 
 reinitialize (array $overriddenParams=[])
 
 createInstallDir ()
 
 cleanup ()
 
 install ($cleanup)
 
 _customizeParams ($params)
 
 getArea ()
 
 loadArea ($areaCode)
 

Data Fields

const DEFAULT_APP_AREA = 'global'
 

Protected Member Functions

 getInstallConfig ()
 
 _ensureDirExists ($dir)
 
 getCustomDirs ()
 

Protected Attributes

 $_db
 
 $_shell
 
 $installConfig
 
 $_globalConfigDir
 
 $installDir
 
 $_configDir
 
 $_initParams = []
 
 $_appMode
 
 $_appArea = null
 
 $_primaryConfigData = []
 
 $_factory
 
 $dirList
 
 $dumpDb = true
 
 $canLoadArea = true
 
 $canInstallSequence = true
 

Detailed Description

Encapsulates application installation, initialization and uninstall.

@SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.TooManyFields)

Definition at line 21 of file Application.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Shell  $shell,
  $installDir,
  $installConfigFile,
  $globalConfigFile,
  $globalConfigDir,
  $appMode,
AutoloaderInterface  $autoloadWrapper,
  $loadTestExtensionAttributes = false 
)

Constructor.

Parameters
\Magento\Framework\Shell$shell
string$installDir
array$installConfigFile
string$globalConfigFile
string$globalConfigDir
string$appMode
AutoloaderInterface$autoloadWrapper
bool | null$loadTestExtensionAttributes

Definition at line 160 of file Application.php.

169  {
170  if (getcwd() != BP . '/dev/tests/integration') {
171  chdir(BP . '/dev/tests/integration');
172  }
173  $this->_shell = $shell;
174  $this->installConfigFile = $installConfigFile;
175  $this->_globalConfigDir = realpath($globalConfigDir);
176  $this->_appMode = $appMode;
177  $this->installDir = $installDir;
178  $this->loadTestExtensionAttributes = $loadTestExtensionAttributes;
179 
180  $customDirs = $this->getCustomDirs();
181  $this->dirList = new \Magento\Framework\App\Filesystem\DirectoryList(BP, $customDirs);
184  $this->dirList
185  );
186  $this->_initParams = [
189  ];
190  $driverPool = new \Magento\Framework\Filesystem\DriverPool;
191  $configFilePool = new \Magento\Framework\Config\File\ConfigFilePool;
192  $this->_factory = new \Magento\TestFramework\ObjectManagerFactory($this->dirList, $driverPool, $configFilePool);
193 
194  $this->_configDir = $this->dirList->getPath(DirectoryList::CONFIG);
195  $this->globalConfigFile = $globalConfigFile;
196  }
if(!file_exists($installConfigFile)) if(!defined('TESTS_INSTALLATION_DB_CONFIG_FILE')) $shell
Definition: bootstrap.php:46
static populateMappings(AutoloaderInterface $autoloader, DirectoryList $dirList)
Definition: Populator.php:22
$autoloadWrapper
Definition: autoload.php:12
if(!file_exists($installConfigFile)) $globalConfigFile
Definition: bootstrap.php:53
const BP
Definition: autoload.php:14
$installConfigFile
Definition: bootstrap.php:49

Member Function Documentation

◆ _customizeParams()

_customizeParams (   $params)

Sub-routine for merging custom parameters with the ones defined in object state

Parameters
array$params
Returns
array

Definition at line 599 of file Application.php.

600  {
601  return array_replace_recursive($this->_initParams, $params);
602  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ _ensureDirExists()

_ensureDirExists (   $dir)
protected

Create a directory with write permissions or don't touch existing one

Parameters
string$dir
Returns
void
Exceptions

Definition at line 625 of file Application.php.

626  {
627  if (!file_exists($dir)) {
628  $old = umask(0);
629  mkdir($dir, 0777, true);
630  umask($old);
631  } elseif (!is_dir($dir)) {
632  throw new \Magento\Framework\Exception\LocalizedException(__("'%1' is not a directory.", $dir));
633  }
634  }
$old
Definition: website.php:27
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
mkdir($pathname, $mode=0777, $recursive=false, $context=null)
Definition: ioMock.php:25

◆ cleanup()

cleanup ( )

Cleanup both the database and the file system

Returns
void
See also
\Magento\Setup\Mvc\Bootstrap\InitParamListener::BOOTSTRAP_PARAM

Definition at line 471 of file Application.php.

472  {
473  $this->createInstallDir();
477  $this->_shell->execute(
478  PHP_BINARY . ' -f %s setup:uninstall -vvv -n --magento-init-params=%s',
479  [BP . '/bin/magento', $this->getInitParamsQuery()]
480  );
481  }
const BP
Definition: autoload.php:14

◆ createInstallDir()

createInstallDir ( )

Create install dir for integration framework

Returns
void

Definition at line 458 of file Application.php.

459  {
460  $this->_ensureDirExists($this->installDir);
461  $this->_ensureDirExists($this->_configDir);
462 
463  $this->copyAppConfigFiles();
464  }

◆ getArea()

getArea ( )

Ge current application area

Returns
string

Definition at line 641 of file Application.php.

642  {
643  return $this->_appArea;
644  }

◆ getCustomDirs()

getCustomDirs ( )
protected

Gets customized directory paths

Returns
array

Definition at line 687 of file Application.php.

688  {
690  $var = "{$this->installDir}/var";
691  $generated = "{$this->installDir}/generated";
692  $customDirs = [
693  DirectoryList::CONFIG => [$path => "{$this->installDir}/etc"],
694  DirectoryList::VAR_DIR => [$path => $var],
695  DirectoryList::MEDIA => [$path => "{$this->installDir}/pub/media"],
696  DirectoryList::STATIC_VIEW => [$path => "{$this->installDir}/pub/static"],
697  DirectoryList::TMP_MATERIALIZATION_DIR => [$path => "{$var}/view_preprocessed/pub/static"],
698  DirectoryList::GENERATED_CODE => [$path => "{$generated}/code"],
699  DirectoryList::CACHE => [$path => "{$var}/cache"],
700  DirectoryList::LOG => [$path => "{$var}/log"],
701  DirectoryList::SESSION => [$path => "{$var}/session"],
702  DirectoryList::TMP => [$path => "{$var}/tmp"],
703  DirectoryList::UPLOAD => [$path => "{$var}/upload"],
704  DirectoryList::PUB => [$path => "{$this->installDir}/pub"],
705  ];
706  return $customDirs;
707  }

◆ getDbInstance()

getDbInstance ( )

Retrieve the database adapter instance.

Returns
\Magento\TestFramework\Db\AbstractDb

Definition at line 203 of file Application.php.

204  {
205  if (null === $this->_db) {
206  if ($this->isInstalled()) {
207  $configPool = new \Magento\Framework\Config\File\ConfigFilePool();
208  $driverPool = new \Magento\Framework\Filesystem\DriverPool();
209  $reader = new Reader($this->dirList, $driverPool, $configPool);
210  $deploymentConfig = new DeploymentConfig($reader, []);
211  $host = $deploymentConfig->get(
214  );
215  $user = $deploymentConfig->get(
218  );
219  $password = $deploymentConfig->get(
222  );
223  $dbName = $deploymentConfig->get(
226  );
227  } else {
228  $installConfig = $this->getInstallConfig();
229  $host = $installConfig['db-host'];
230  $user = $installConfig['db-user'];
231  $password = $installConfig['db-password'];
232  $dbName = $installConfig['db-name'];
233  }
234  $this->_db = new Db\Mysql(
235  $host,
236  $user,
237  $password,
238  $dbName,
239  $this->getTempDir(),
240  $this->_shell
241  );
242  }
243  return $this->_db;
244  }
$deploymentConfig
$user
Definition: dummy_user.php:13

◆ getInitParams()

getInitParams ( )

Retrieve application initialization parameters.

Returns
array

Definition at line 284 of file Application.php.

285  {
286  return $this->_initParams;
287  }

◆ getInstallConfig()

getInstallConfig ( )
protected

Gets installation parameters.

Returns
array

Definition at line 251 of file Application.php.

252  {
253  if (null === $this->installConfig) {
254  $this->installConfig = include $this->installConfigFile;
255  }
256  return $this->installConfig;
257  }
$installConfigFile
Definition: bootstrap.php:49

◆ getTempDir()

getTempDir ( )

Get path to temporary directory.

Returns
string

Definition at line 274 of file Application.php.

275  {
276  return $this->installDir;
277  }

◆ install()

install (   $cleanup)

Install an application

Parameters
bool$cleanup
Returns
void
Exceptions

Definition at line 490 of file Application.php.

491  {
493  $this->_ensureDirExists($this->installDir);
494  $this->_ensureDirExists($this->_configDir);
495  $this->_ensureDirExists($this->_initParams[$dirs][DirectoryList::PUB][DirectoryList::PATH]);
496  $this->_ensureDirExists($this->_initParams[$dirs][DirectoryList::MEDIA][DirectoryList::PATH]);
497  $this->_ensureDirExists($this->_initParams[$dirs][DirectoryList::STATIC_VIEW][DirectoryList::PATH]);
498  $this->_ensureDirExists($this->_initParams[$dirs][DirectoryList::VAR_DIR][DirectoryList::PATH]);
499 
500  $this->copyAppConfigFiles();
501 
502  $installParams = $this->getInstallCliParams();
503 
504  // performance optimization: restore DB from last good dump to make installation on top of it (much faster)
505  // do not restore from the database if the cleanup option is set to ensure we have a clean DB to test on
506  $db = $this->getDbInstance();
507  if ($db->isDbDumpExists() && !$cleanup) {
508  $db->restoreFromDbDump();
509  }
510 
511  // run install script
512  $this->_shell->execute(
513  PHP_BINARY . ' -f %s setup:install -vvv ' . implode(' ', array_keys($installParams)),
514  array_merge([BP . '/bin/magento'], array_values($installParams))
515  );
516 
517  // enable only specified list of caches
518  $initParamsQuery = $this->getInitParamsQuery();
519  $this->_shell->execute(
520  PHP_BINARY . ' -f %s cache:disable -vvv --bootstrap=%s',
521  [BP . '/bin/magento', $initParamsQuery]
522  );
523  $this->_shell->execute(
524  PHP_BINARY . ' -f %s cache:enable -vvv %s %s %s %s --bootstrap=%s',
525  [
526  BP . '/bin/magento',
527  \Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER,
528  \Magento\Framework\App\Cache\Type\Layout::TYPE_IDENTIFIER,
529  \Magento\Framework\App\Cache\Type\Translate::TYPE_IDENTIFIER,
530  \Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER,
531  $initParamsQuery,
532  ]
533  );
534 
535  // right after a clean installation, store DB dump for future reuse in tests or running the test suite again
536  if (!$db->isDbDumpExists() && $this->dumpDb) {
537  $this->getDbInstance()->storeDbDump();
538  }
539  }
const BP
Definition: autoload.php:14

◆ isInstalled()

isInstalled ( )

Weather the application is installed or not.

Returns
bool

Definition at line 294 of file Application.php.

295  {
296  return is_file($this->getLocalConfig());
297  }

◆ loadArea()

loadArea (   $areaCode)

Load application area

Parameters
string$areaCode
Returns
void
Exceptions

Definition at line 653 of file Application.php.

654  {
655  $this->_appArea = $areaCode;
657  \Magento\Framework\Config\Scope::class
658  );
659  $scope->setCurrentScope($areaCode);
661  \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
662  \Magento\Framework\App\ObjectManager\ConfigLoader::class
663  )->load(
664  $areaCode
665  )
666  );
667  $app = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\AreaList::class);
668  $areasForPartialLoading = [
674  ];
675  if (in_array($areaCode, $areasForPartialLoading, true)) {
676  $app->getArea($areaCode)->load(\Magento\Framework\App\Area::PART_CONFIG);
677  } else {
679  }
680  }
$app
Definition: index.php:38

◆ reinitialize()

reinitialize ( array  $overriddenParams = [])

Reset and initialize again an already installed application

Parameters
array$overriddenParams
Returns
void

Definition at line 433 of file Application.php.

434  {
435  $this->_resetApp();
436  $this->initialize($overriddenParams);
437  }

Field Documentation

◆ $_appArea

$_appArea = null
protected

Definition at line 96 of file Application.php.

◆ $_appMode

$_appMode
protected

Definition at line 89 of file Application.php.

◆ $_configDir

$_configDir
protected

Definition at line 75 of file Application.php.

◆ $_db

$_db
protected

Definition at line 33 of file Application.php.

◆ $_factory

$_factory
protected

Definition at line 110 of file Application.php.

◆ $_globalConfigDir

$_globalConfigDir
protected

Definition at line 61 of file Application.php.

◆ $_initParams

$_initParams = []
protected

Definition at line 82 of file Application.php.

◆ $_primaryConfigData

$_primaryConfigData = []
protected

Definition at line 103 of file Application.php.

◆ $_shell

$_shell
protected

Definition at line 40 of file Application.php.

◆ $canInstallSequence

$canInstallSequence = true
protected

Definition at line 146 of file Application.php.

◆ $canLoadArea

$canLoadArea = true
protected

Definition at line 141 of file Application.php.

◆ $dirList

$dirList
protected

Definition at line 117 of file Application.php.

◆ $dumpDb

$dumpDb = true
protected

Definition at line 136 of file Application.php.

◆ $installConfig

$installConfig
protected

Definition at line 54 of file Application.php.

◆ $installDir

$installDir
protected

Definition at line 68 of file Application.php.

◆ DEFAULT_APP_AREA

const DEFAULT_APP_AREA = 'global'

Default application area.

Definition at line 26 of file Application.php.


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