Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
ZF Class Reference

Public Member Functions

 bootstrap ()
 
 run ()
 

Static Public Member Functions

static main ()
 

Protected Member Functions

 _detectMode ()
 
 _detectHomeDirectory ($mustExist=true, $returnMessages=true)
 
 _detectStorageDirectory ($mustExist=true, $returnMessages=true)
 
 _detectConfigFile ($mustExist=true, $returnMessages=true)
 
 _setupPHPRuntime ()
 
 _setupToolRuntime ()
 
 _tryClientLoad ()
 
 _runError ()
 
 _runInfo ()
 
 _runSetup ()
 
 _runSetupStorageDirectory ()
 
 _runSetupConfigFile ()
 
 _runSetupMoreInfo ()
 
 _runTool ()
 
 _logMessage ($message, $storeMessage=true)
 

Protected Attributes

 $_clientLoaded = false
 
 $_mode = 'runTool'
 
 $_messages = array()
 
 $_homeDirectory = null
 
 $_storageDirectory = null
 
 $_configFile = null
 

Detailed Description

Definition at line 32 of file zf.php.

Member Function Documentation

◆ _detectConfigFile()

_detectConfigFile (   $mustExist = true,
  $returnMessages = true 
)
protected

_detectConfigFile() - Detect config file location from a variety of possibilities

Parameters
bool$mustExistShould the returned value already exist in the file system
bool$returnMessagesShould it log messages for output later
Returns
string

Definition at line 258 of file zf.php.

259  {
260  $configFile = null;
261 
262  $configFile = getenv('ZF_CONFIG_FILE');
263  if ($configFile) {
264  $this->_logMessage('Config file found environment variable ZF_CONFIG_FILE at ' . $configFile, $returnMessages);
265  if (!$mustExist || ($mustExist && file_exists($configFile))) {
266  return $configFile;
267  } else {
268  $this->_logMessage('Config file does not exist at ' . $configFile, $returnMessages);
269  }
270  }
271 
272  $homeDirectory = ($this->_homeDirectory) ? $this->_homeDirectory : $this->_detectHomeDirectory(true, false);
273  if ($homeDirectory) {
274  $configFile = $homeDirectory . '/.zf.ini';
275  $this->_logMessage('Config file assumed in home directory at location ' . $configFile, $returnMessages);
276  if (!$mustExist || ($mustExist && file_exists($configFile))) {
277  return $configFile;
278  } else {
279  $this->_logMessage('Config file does not exist at ' . $configFile, $returnMessages);
280  }
281  }
282 
283  $storageDirectory = ($this->_storageDirectory) ? $this->_storageDirectory : $this->_detectStorageDirectory(true, false);
284  if ($storageDirectory) {
285  $configFile = $storageDirectory . '/zf.ini';
286  $this->_logMessage('Config file assumed in storage directory at location ' . $configFile, $returnMessages);
287  if (!$mustExist || ($mustExist && file_exists($configFile))) {
288  return $configFile;
289  } else {
290  $this->_logMessage('Config file does not exist at ' . $configFile, $returnMessages);
291  }
292  }
293 
294  return false;
295  }
_detectStorageDirectory($mustExist=true, $returnMessages=true)
Definition: zf.php:222
_detectHomeDirectory($mustExist=true, $returnMessages=true)
Definition: zf.php:164
_logMessage($message, $storeMessage=true)
Definition: zf.php:610
$_homeDirectory
Definition: zf.php:53
$_storageDirectory
Definition: zf.php:58

◆ _detectHomeDirectory()

_detectHomeDirectory (   $mustExist = true,
  $returnMessages = true 
)
protected

_detectHomeDirectory() - detect the home directory in a variety of different places

Parameters
bool$mustExistShould the returned value already exist in the file system
bool$returnMessagesShould it log messages for output later
Returns
string

Definition at line 164 of file zf.php.

165  {
166  $homeDirectory = null;
167 
168  $homeDirectory = getenv('ZF_HOME'); // check env var ZF_HOME
169  if ($homeDirectory) {
170  $this->_logMessage('Home directory found in environment variable ZF_HOME with value ' . $homeDirectory, $returnMessages);
171  if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
172  return $homeDirectory;
173  } else {
174  $this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages);
175  }
176  }
177 
178  $homeDirectory = getenv('HOME'); // HOME environment variable
179 
180  if ($homeDirectory) {
181  $this->_logMessage('Home directory found in environment variable HOME with value ' . $homeDirectory, $returnMessages);
182  if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
183  return $homeDirectory;
184  } else {
185  $this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages);
186  }
187 
188  }
189 
190  $homeDirectory = getenv('HOMEPATH');
191 
192  if ($homeDirectory) {
193  $this->_logMessage('Home directory found in environment variable HOMEPATH with value ' . $homeDirectory, $returnMessages);
194  if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
195  return $homeDirectory;
196  } else {
197  $this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages);
198  }
199  }
200 
201  $homeDirectory = getenv('USERPROFILE');
202 
203  if ($homeDirectory) {
204  $this->_logMessage('Home directory found in environment variable USERPROFILE with value ' . $homeDirectory, $returnMessages);
205  if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
206  return $homeDirectory;
207  } else {
208  $this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages);
209  }
210  }
211 
212  return false;
213  }
_logMessage($message, $storeMessage=true)
Definition: zf.php:610

◆ _detectMode()

_detectMode ( )
protected

_detectMode()

Returns
ZF

Definition at line 129 of file zf.php.

130  {
131  $arguments = $_SERVER['argv'];
132 
133  $mode = 'runTool';
134 
135  if (!isset($arguments[0])) {
136  return $mode;
137  }
138 
139  if ($arguments[0] == $_SERVER['PHP_SELF']) {
140  $this->_executable = array_shift($arguments);
141  }
142 
143  if (!isset($arguments[0])) {
144  return $mode;
145  }
146 
147  if ($arguments[0] == '--setup') {
148  $mode = 'runSetup';
149  } elseif ($arguments[0] == '--info') {
150  $mode = 'runInfo';
151  }
152 
153  return $mode;
154  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
$arguments

◆ _detectStorageDirectory()

_detectStorageDirectory (   $mustExist = true,
  $returnMessages = true 
)
protected

_detectStorageDirectory() - Detect where the storage directory is from a variaty of possiblities

Parameters
bool$mustExistShould the returned value already exist in the file system
bool$returnMessagesShould it log messages for output later
Returns
string

Definition at line 222 of file zf.php.

223  {
224  $storageDirectory = false;
225 
226  $storageDirectory = getenv('ZF_STORAGE_DIR');
227  if ($storageDirectory) {
228  $this->_logMessage('Storage directory path found in environment variable ZF_STORAGE_DIR with value ' . $storageDirectory, $returnMessages);
229  if (!$mustExist || ($mustExist && file_exists($storageDirectory))) {
230  return $storageDirectory;
231  } else {
232  $this->_logMessage('Storage directory does not exist at ' . $storageDirectory, $returnMessages);
233  }
234  }
235 
236  $homeDirectory = ($this->_homeDirectory) ? $this->_homeDirectory : $this->_detectHomeDirectory(true, false);
237 
238  if ($homeDirectory) {
239  $storageDirectory = $homeDirectory . '/.zf/';
240  $this->_logMessage('Storage directory assumed in home directory at location ' . $storageDirectory, $returnMessages);
241  if (!$mustExist || ($mustExist && file_exists($storageDirectory))) {
242  return $storageDirectory;
243  } else {
244  $this->_logMessage('Storage directory does not exist at ' . $storageDirectory, $returnMessages);
245  }
246  }
247 
248  return false;
249  }
_detectHomeDirectory($mustExist=true, $returnMessages=true)
Definition: zf.php:164
_logMessage($message, $storeMessage=true)
Definition: zf.php:610
$_homeDirectory
Definition: zf.php:53

◆ _logMessage()

_logMessage (   $message,
  $storeMessage = true 
)
protected

_logMessage() - Internal method used to log setup and information messages.

Parameters
string$message
bool$storeMessage
Returns
void

Definition at line 610 of file zf.php.

611  {
612  if (!$storeMessage) {
613  return;
614  }
615 
616  $this->_messages[] = $message;
617  }
$message

◆ _runError()

_runError ( )
protected

_runError() - Output the error screen that tells the user that the tool was not setup in a sane way

Returns
void

Definition at line 402 of file zf.php.

403  {
404 
405  echo <<<EOS
406 
407 ***************************** ZF ERROR ********************************
408 In order to run the zf command, you need to ensure that Zend Framework
409 is inside your include_path. There are a variety of ways that you can
410 ensure that this zf command line tool knows where the Zend Framework
411 library is on your system, but not all of them can be described here.
412 
413 The easiest way to get the zf command running is to give it the include
414 path via an environment variable ZEND_TOOL_INCLUDE_PATH or
415 ZEND_TOOL_INCLUDE_PATH_PREPEND with the proper include path to use,
416 then run the command "zf --setup". This command is designed to create
417 a storage location for your user, as well as create the zf.ini file
418 that the zf command will consult in order to run properly on your
419 system.
420 
421 Example you would run:
422 
423 $ ZEND_TOOL_INCLUDE_PATH=/path/to/library zf --setup
424 
425 Your are encourged to read more in the link that follows.
426 
427 EOS;
428 
429  }
run()
Definition: zf.php:100
taxRateField this edit on("click.mselect-delete", ".mselect-delete", function() { if(!confirm('<?=/*@escapeNotVerified */__( 'Do you really want to delete this tax rate?') ?>')) { return;} var that=$(this), select=that.closest('.mselect-list').prev(), rateValue=that.parent().find( 'input[type="checkbox"]').val();$( 'body').trigger( 'processStart');var ajaxOptions={ type:'POST', data:{ tax_calculation_rate_id:rateValue, form_key:$( 'input[name="form_key"]').val() }, dataType:'json', url:'<?=/*@escapeNotVerified */$block->getTaxRateDeleteUrl() ?>', success:function(result, status) { $( 'body').trigger( 'processStop');if(result.success) { that.parent().remove();select.find( 'option').each(function() { if(this.value===rateValue) { $(this).remove();} });select.trigger( 'change.hiddenSelect');} else { if(result.error_message) alert({ content:result.error_message });else alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} }, error:function() { $( 'body').trigger( 'processStop');alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} };$.ajax(ajaxOptions);}) .on( 'click.mselectAdd'
Definition: edit.phtml:164
Definition: zf.php:32

◆ _runInfo()

_runInfo ( )
protected

_runInfo() - this command will produce information about the setup of this script and Zend_Tool

Returns
void

Definition at line 437 of file zf.php.

438  {
439  echo 'Zend_Tool & CLI Setup Information' . PHP_EOL
440  . '(available via the command line "zf --info")'
441  . PHP_EOL;
442 
443  echo ' * ' . implode(PHP_EOL . ' * ', $this->_messages) . PHP_EOL;
444 
445  echo PHP_EOL;
446 
447  echo 'To change the setup of this tool, run: "zf --setup"';
448 
449  echo PHP_EOL;
450 
451  }

◆ _runSetup()

_runSetup ( )
protected

_runSetup() - parse the request to see which setup command to run

Returns
void

Definition at line 458 of file zf.php.

459  {
460  $setupCommand = (isset($_SERVER['argv'][2])) ? $_SERVER['argv'][2] : null;
461 
462  switch ($setupCommand) {
463  case 'storage-directory':
464  $this->_runSetupStorageDirectory();
465  break;
466  case 'config-file':
467  $this->_runSetupConfigFile();
468  break;
469  default:
470  $this->_runSetupMoreInfo();
471  break;
472  }
473  }
_runSetupStorageDirectory()
Definition: zf.php:480
_runSetupMoreInfo()
Definition: zf.php:531
_runSetupConfigFile()
Definition: zf.php:500

◆ _runSetupConfigFile()

_runSetupConfigFile ( )
protected

_runSetupConfigFile()

Returns
void

Definition at line 500 of file zf.php.

501  {
502  $configFile = $this->_detectConfigFile(false, false);
503 
504  if (file_exists($configFile)) {
505  echo 'File already exists at ' . $configFile . PHP_EOL
506  . 'Cannot write new config file.';
507  return;
508  }
509 
510  $includePath = get_include_path();
511 
512  $contents = 'php.include_path = "' . $includePath . '"';
513 
514  file_put_contents($configFile, $contents);
515 
516  $iniValues = ini_get_all();
517  if ($iniValues['include_path']['global_value'] != $iniValues['include_path']['local_value']) {
518  echo 'NOTE: the php include_path to be used with the tool has been written' . PHP_EOL
519  . 'to the config file, using ZEND_TOOL_INCLUDE_PATH (or other include_path setters)' . PHP_EOL
520  . 'is no longer necessary.' . PHP_EOL . PHP_EOL;
521  }
522 
523  echo 'Config file written to ' . $configFile . PHP_EOL;
524  }
$contents
Definition: website.php:14
_detectConfigFile($mustExist=true, $returnMessages=true)
Definition: zf.php:258

◆ _runSetupMoreInfo()

_runSetupMoreInfo ( )
protected

_runSetupMoreInfo() - return more information about what can be setup, and what is setup

Returns
void

Definition at line 531 of file zf.php.

532  {
533  $homeDirectory = $this->_detectHomeDirectory(false, false);
534  $storageDirectory = $this->_detectStorageDirectory(false, false);
535  $configFile = $this->_detectConfigFile(false, false);
536 
537  echo <<<EOS
538 
539 ZF Command Line Tool - Setup
540 ----------------------------
541 
542 Current Paths (Existing or not):
543  Home Directory: {$homeDirectory}
544  Storage Directory: {$storageDirectory}
545  Config File: {$configFile}
546 
547 Important Environment Variables:
548  ZF_HOME
549  - the directory this tool will look for a home directory
550  - directory must exist
551  ZF_STORAGE_DIR
552  - where this tool will look for a storage directory
553  - directory must exist
554  ZF_CONFIG_FILE
555  - where this tool will look for a configuration file
556  ZF_TOOL_INCLUDE_PATH
557  - set the include_path for this tool to use this value
558  ZF_TOOL_INCLUDE_PATH_PREPEND
559  - prepend the current php.ini include_path with this value
560 
561 Search Order:
562  Home Directory:
563  - ZF_HOME, then HOME (*nix), then HOMEPATH (windows)
564  Storage Directory:
565  - ZF_STORAGE_DIR, then {home}/.zf/
566  Config File:
567  - ZF_CONFIG_FILE, then {home}/.zf.ini, then {home}/zf.ini,
568  then {storage}/zf.ini
569 
570 Commands:
571  zf --setup storage-directory
572  - setup the storage directory, directory will be created
573  zf --setup config-file
574  - create the config file with some default values
575 
576 
577 EOS;
578  }
_detectStorageDirectory($mustExist=true, $returnMessages=true)
Definition: zf.php:222
_detectHomeDirectory($mustExist=true, $returnMessages=true)
Definition: zf.php:164
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
_detectConfigFile($mustExist=true, $returnMessages=true)
Definition: zf.php:258
Definition: zf.php:32

◆ _runSetupStorageDirectory()

_runSetupStorageDirectory ( )
protected

_runSetupStorageDirectory() - if the storage directory does not exist, create it

Returns
void

Definition at line 480 of file zf.php.

481  {
482  $storageDirectory = $this->_detectStorageDirectory(false, false);
483 
484  if (file_exists($storageDirectory)) {
485  echo 'Directory already exists at ' . $storageDirectory . PHP_EOL
486  . 'Cannot create storage directory.';
487  return;
488  }
489 
490  mkdir($storageDirectory);
491 
492  echo 'Storage directory created at ' . $storageDirectory . PHP_EOL;
493  }
_detectStorageDirectory($mustExist=true, $returnMessages=true)
Definition: zf.php:222
mkdir($pathname, $mode=0777, $recursive=false, $context=null)
Definition: ioMock.php:25

◆ _runTool()

_runTool ( )
protected

_runTool() - This is where the magic happens, dispatch Zend_Tool

Returns
void

Definition at line 585 of file zf.php.

586  {
587 
588  $configOptions = array();
589  if (isset($this->_configFile) && $this->_configFile) {
590  $configOptions['configOptions']['configFilepath'] = $this->_configFile;
591  }
592  if (isset($this->_storageDirectory) && $this->_storageDirectory) {
593  $configOptions['storageOptions']['directory'] = $this->_storageDirectory;
594  }
595 
596  // ensure that zf.php loads the Zend_Tool_Project features
597  $configOptions['classesToLoad'] = 'Zend_Tool_Project_Provider_Manifest';
598 
599  $console = new Zend_Tool_Framework_Client_Console($configOptions);
600  $console->dispatch();
601  }
$_storageDirectory
Definition: zf.php:58
$_configFile
Definition: zf.php:63

◆ _setupPHPRuntime()

_setupPHPRuntime ( )
protected

_setupPHPRuntime() - parse the config file if it exists for php ini values to set

Returns
void

Definition at line 303 of file zf.php.

304  {
305  // set php runtime settings
306  ini_set('display_errors', true);
307 
308  // support the changing of the current working directory, necessary for some providers
309  $cwd = getenv('ZEND_TOOL_CURRENT_WORKING_DIRECTORY');
310  if ($cwd != '' && realpath($cwd)) {
311  chdir($cwd);
312  }
313 
314  if (!$this->_configFile) {
315  return;
316  }
317  $zfINISettings = parse_ini_file($this->_configFile);
318  $phpINISettings = ini_get_all();
319  foreach ($zfINISettings as $zfINIKey => $zfINIValue) {
320  if (substr($zfINIKey, 0, 4) === 'php.') {
321  $phpINIKey = substr($zfINIKey, 4);
322  if (array_key_exists($phpINIKey, $phpINISettings)) {
323  ini_set($phpINIKey, $zfINIValue);
324  }
325  }
326  }
327  }
ini_set($varName, $newValue)

◆ _setupToolRuntime()

_setupToolRuntime ( )
protected

_setupToolRuntime() - setup the tools include_path and load the proper framwork parts that enable Zend_Tool to work.

Returns
void

Definition at line 335 of file zf.php.

336  {
337 
338  $includePathPrepend = getenv('ZEND_TOOL_INCLUDE_PATH_PREPEND');
339  $includePathFull = getenv('ZEND_TOOL_INCLUDE_PATH');
340 
341  // check if the user has not provided anything
342  if (!($includePathPrepend || $includePathFull)) {
343  if ($this->_tryClientLoad()) {
344  return;
345  }
346  }
347 
348  // if ZF is not in the include_path, but relative to this file, put it in the include_path
349  if ($includePathPrepend || $includePathFull) {
350  if (isset($includePathPrepend) && ($includePathPrepend !== false)) {
351  set_include_path($includePathPrepend . PATH_SEPARATOR . get_include_path());
352  } elseif (isset($includePathFull) && ($includePathFull !== false)) {
353  set_include_path($includePathFull);
354  }
355  }
356 
357  if ($this->_tryClientLoad()) {
358  return;
359  }
360 
361  $zfIncludePath['relativePath'] = dirname(__FILE__) . '/../library/';
362  if (file_exists($zfIncludePath['relativePath'] . 'Zend/Tool/Framework/Client/Console.php')) {
363  set_include_path(realpath($zfIncludePath['relativePath']) . PATH_SEPARATOR . get_include_path());
364  }
365 
366  if (!$this->_tryClientLoad()) {
367  $this->_mode = 'runError';
368  return;
369  }
370  }
_tryClientLoad()
Definition: zf.php:380
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
defined('MTF_BOOT_FILE')||define('MTF_BOOT_FILE' __FILE__
Definition: bootstrap.php:7

◆ _tryClientLoad()

_tryClientLoad ( )
protected

_tryClientLoad() - Attempt to load the Zend_Tool_Framework_Client_Console to enable the tool to run.

This method will return false if its not loaded to allow the consumer to alter the environment in such a way that it can be called again to try loading the proper file/class.

Returns
bool if the client is actuall loaded or not

Definition at line 380 of file zf.php.

381  {
382  $this->_clientLoaded = false;
383  $fh = @fopen('Zend/Tool/Framework/Client/Console.php', 'r', true);
384  if (!$fh) {
385  return $this->_clientLoaded; // false
386  } else {
387  fclose($fh);
388  unset($fh);
389  include 'Zend/Tool/Framework/Client/Console.php';
390  $this->_clientLoaded = class_exists('Zend_Tool_Framework_Client_Console');
391  }
392 
393  return $this->_clientLoaded;
394  }
$_clientLoaded
Definition: zf.php:38

◆ bootstrap()

bootstrap ( )

bootstrap()

Returns
ZF

Definition at line 82 of file zf.php.

83  {
84  // detect settings
85  $this->_mode = $this->_detectMode();
86  $this->_homeDirectory = $this->_detectHomeDirectory();
87  $this->_storageDirectory = $this->_detectStorageDirectory();
88  $this->_configFile = $this->_detectConfigFile();
89 
90  // setup
91  $this->_setupPHPRuntime();
92  $this->_setupToolRuntime();
93  }
_detectStorageDirectory($mustExist=true, $returnMessages=true)
Definition: zf.php:222
_detectHomeDirectory($mustExist=true, $returnMessages=true)
Definition: zf.php:164
_detectMode()
Definition: zf.php:129
_setupPHPRuntime()
Definition: zf.php:303
_setupToolRuntime()
Definition: zf.php:335
_detectConfigFile($mustExist=true, $returnMessages=true)
Definition: zf.php:258

◆ main()

static main ( )
static

main()

Returns
void

Definition at line 70 of file zf.php.

71  {
72  $zf = new self();
73  $zf->bootstrap();
74  $zf->run();
75  }

◆ run()

run ( )

run()

Returns
ZF

Definition at line 100 of file zf.php.

101  {
102  switch ($this->_mode) {
103  case 'runError':
104  $this->_runError();
105  $this->_runInfo();
106  break;
107  case 'runSetup':
108  if ($this->_runSetup() === false) {
109  $this->_runInfo();
110  }
111  break;
112  case 'runInfo':
113  $this->_runInfo();
114  break;
115  case 'runTool':
116  default:
117  $this->_runTool();
118  break;
119  }
120 
121  return $this;
122  }
_runInfo()
Definition: zf.php:437
_runSetup()
Definition: zf.php:458
_runError()
Definition: zf.php:402
_runTool()
Definition: zf.php:585

Field Documentation

◆ $_clientLoaded

$_clientLoaded = false
protected

Definition at line 38 of file zf.php.

◆ $_configFile

$_configFile = null
protected

Definition at line 63 of file zf.php.

◆ $_homeDirectory

$_homeDirectory = null
protected

Definition at line 53 of file zf.php.

◆ $_messages

$_messages = array()
protected

Definition at line 48 of file zf.php.

◆ $_mode

$_mode = 'runTool'
protected

Definition at line 43 of file zf.php.

◆ $_storageDirectory

$_storageDirectory = null
protected

Definition at line 58 of file zf.php.


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