b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / a / home / dev2.destoffenstraat.com / app / code / Swissup / Rtl / Plugin /
Filename/home/a/home/dev2.destoffenstraat.com/app/code/Swissup/Rtl/Plugin/AssetPublisher.php
Size4.05 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time21-Aug-2025 12:26
Last modified13-Mar-2023 12:28
Last accessed23-Aug-2025 01:34
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

namespace Swissup\Rtl\Plugin;

use Swissup\Rtl\Model\MixinsRenderer;
use Swissup\Rtl\Model\MixinsRendererFactory;
use Magento\Framework\App\Filesystem\DirectoryList;

class AssetPublisher
{
/**
* @var MixinsRendererFactory
*/
private $mixinsRendererFactory;

/**
* @var \Magento\Framework\Filesystem\Driver\File
*/
private $fileDriver;

/**
* @var \Magento\Framework\Filesystem
*/
private $filesystem;

/**
* @var \Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
*/
private $copyFile;

/**
* @var \Magento\Framework\Filesystem\Directory\WriteFactory
*/
private $writeFactory;

/**
* @param MixinsRendererFactory $mixinsRendererFactory
* @param \Magento\Framework\Filesystem\Driver\File $fileDriver
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\Framework\App\View\Asset\MaterializationStrategy\Copy $copyFile
* @param \Magento\Framework\Filesystem\Directory\WriteFactory $writeFactory
*/
public function __construct(
MixinsRendererFactory $mixinsRendererFactory,
\Magento\Framework\Filesystem\Driver\File $fileDriver,
\Magento\Framework\Filesystem $filesystem,
\Magento\Framework\App\View\Asset\MaterializationStrategy\Copy $copyFile,
\Magento\Framework\Filesystem\Directory\WriteFactory $writeFactory
) {
$this->mixinsRendererFactory = $mixinsRendererFactory;
$this->fileDriver = $fileDriver;
$this->filesystem = $filesystem;
$this->copyFile = $copyFile;
$this->writeFactory = $writeFactory;
}

/**
* Grunt tasks compatibility. Inject modrtl mixins into '_modrtl.less' files.
*
* @param \Magento\Framework\App\View\Asset\Publisher $subject
* @param bool $result
* @param \Magento\Framework\View\Asset\LocalInterface $asset
* @return bool
*/
public function afterPublish(
\Magento\Framework\App\View\Asset\Publisher $subject,
$result,
\Magento\Framework\View\Asset\LocalInterface $asset
) {
if (!$result) {
return $result;
}

try {
$filepath = $asset->getSourceFile();
$filename = basename($filepath);
} catch (\Exception $e) {
return $result;
}

if (strpos($filename, MixinsRenderer::FILENAME) === false) {
return $result;
}

$dirname = dirname($filepath);
$assetPath = $asset->getPath();
$contents = $this->getFileContents($filepath);
$staticDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);

if ($contents &&
strpos($contents, MixinsRenderer::PLACEHOLDER) !== false &&
$staticDir->isExist($assetPath) // check if asset succesfully deployed
) {
$contents = str_replace(
MixinsRenderer::PLACEHOLDER,
$this->mixinsRendererFactory->create()->render($asset->getContext()),
$contents
);

$assetAbsolutePath = $staticDir->getAbsolutePath($assetPath);
if (is_link($assetAbsolutePath)) {
// delete link to empty _modrtl.less file
$staticDir->delete($assetPath);

// redeploy same file using copy strategy
$this->copyFile->publishFile(
$this->writeFactory->create($dirname),
$staticDir,
$filename,
$assetPath
);
}

// update content of deployed asset
$this->fileDriver->filePutContents($assetAbsolutePath, $contents);
}

return $result;
}

/**
* Get contents of the source file
*
* @param string $filepath
* @return string
*/
private function getFileContents($filepath)
{
try {
$contents = $this->fileDriver->fileGetContents($filepath);
} catch (\Exception $e) {
$contents = false;
}
return $contents;
}
}