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

Public Member Functions

 __construct (\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDatabase, \Magento\Framework\Filesystem $filesystem)
 
 getFaviconFile ()
 
 getDefaultFavicon ()
 

Protected Member Functions

 prepareFaviconFile ()
 
 checkIsFile ($filename)
 

Protected Attributes

 $faviconFile
 
 $storeManager
 
 $scopeConfig
 
 $fileStorageDatabase
 
 $mediaDirectory
 

Detailed Description

Favicon implementation

Definition at line 13 of file Favicon.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig
\Magento\MediaStorage\Helper\File\Storage\Database$fileStorageDatabase
\Magento\Framework\Filesystem$filesystem

Definition at line 46 of file Favicon.php.

51  {
52  $this->storeManager = $storeManager;
53  $this->scopeConfig = $scopeConfig;
54  $this->fileStorageDatabase = $fileStorageDatabase;
55  $this->mediaDirectory = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
56  }
$filesystem

Member Function Documentation

◆ checkIsFile()

checkIsFile (   $filename)
protected

If DB file storage is on - find there, otherwise - just file_exists

Parameters
string$filenamerelative file path
Returns
bool

Definition at line 104 of file Favicon.php.

105  {
106  if ($this->fileStorageDatabase->checkDbUsage() && !$this->mediaDirectory->isFile($filename)) {
107  $this->fileStorageDatabase->saveFileToFilesystem($filename);
108  }
109  return $this->mediaDirectory->isFile($filename);
110  }

◆ getDefaultFavicon()

getDefaultFavicon ( )
Returns
string

Implements FaviconInterface.

Definition at line 72 of file Favicon.php.

73  {
74  return 'Magento_Theme::favicon.ico';
75  }

◆ getFaviconFile()

getFaviconFile ( )
Returns
string

Implements FaviconInterface.

Definition at line 61 of file Favicon.php.

62  {
63  if (null === $this->faviconFile) {
64  $this->faviconFile = $this->prepareFaviconFile();
65  }
66  return $this->faviconFile;
67  }

◆ prepareFaviconFile()

prepareFaviconFile ( )
protected
Returns
string

Definition at line 80 of file Favicon.php.

81  {
82  $folderName = \Magento\Config\Model\Config\Backend\Image\Favicon::UPLOAD_DIR;
83  $scopeConfig = $this->scopeConfig->getValue(
84  'design/head/shortcut_icon',
86  );
87  $path = $folderName . '/' . $scopeConfig;
88  $faviconUrl = $this->storeManager->getStore()
89  ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $path;
90 
91  if ($scopeConfig !== null && $this->checkIsFile($path)) {
92  return $faviconUrl;
93  }
94 
95  return false;
96  }

Field Documentation

◆ $faviconFile

$faviconFile
protected

Definition at line 18 of file Favicon.php.

◆ $fileStorageDatabase

$fileStorageDatabase
protected

Definition at line 33 of file Favicon.php.

◆ $mediaDirectory

$mediaDirectory
protected

Definition at line 38 of file Favicon.php.

◆ $scopeConfig

$scopeConfig
protected

Definition at line 28 of file Favicon.php.

◆ $storeManager

$storeManager
protected

Definition at line 23 of file Favicon.php.


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