4

guys i want proper way to fix Deprecated Functionality: pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated in vendor/magento/framework/View/Asset/PreProcessor/FileNameResolver.phpline 44

things to be in mind:

  1. cant change in magento core files. 2)logo/preview image files already added in custom theme.

Thanks in advance

1

4 Answers 4

1

I have written preference for this in custom module: create di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Framework\View\Asset\PreProcessor\FileNameResolver" type="Custom\CorePatch\View\Asset\PreProcessor\FileNameResolver" />
    
</config>

create FileNameResolver in respective folder as mentioned:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Custom\CorePatch\View\Asset\PreProcessor;

/**
 * Class FileNameResolver
 *
 * @package Magento\Framework\View\Asset\PreProcessor
 */
class FileNameResolver extends \Magento\Framework\View\Asset\PreProcessor\FileNameResolver
{
    /**
     * @var AlternativeSource[]
     */
    private $alternativeSources;

    /**
     * FileNameResolver constructor.
     * @param array $alternativeSources
     * @internal param AlternativeSource $alternativeSource
     */
    public function __construct(array $alternativeSources = [])
    {
        $this->alternativeSources = array_map(
            function (\Magento\Framework\View\Asset\PreProcessor\AlternativeSourceInterface $alternativeSource) {
                return $alternativeSource;
            },
            $alternativeSources
        );
    }

    /**
     * Resolve filename
     *
     * @param string $fileName
     * @return string
     */
    public function resolve($fileName)
    {
        $compiledFile = $fileName;
        $extension = pathinfo((string)$fileName, PATHINFO_EXTENSION);
        foreach ($this->alternativeSources as $name => $alternative) {
            if ($alternative->isExtensionSupported($extension)
                && strpos(basename($fileName), '_') !== 0
            ) {
                $compiledFile = substr($fileName, 0, strlen($fileName) - strlen($extension) - 1);
                $compiledFile = $compiledFile . '.' . $name;
            }
        }
        return $compiledFile;
    }
}
0

This is the bug in Magento 2.4.4 & 2.4.5

So you need to apply below patch to fix the issue

Create a folder name patches in root of your Magento then create a file name CustomThemeLogo.patch in that folder

patches/CustomThemeLogo.patch

Add below code and save the file:

diff --git a/App/Utility/Files.php b/App/Utility/Files.php
index 00c1e89..b872c08 100644
--- a/App/Utility/Files.php
+++ b/App/Utility/Files.php
@@ -959,10 +959,10 @@
                     $result[] = [
                         $themeArea,
                         $themePackage->getVendor() . '/' . $themePackage->getName(),
-                        null,
-                        null,
-                        null,
-                        null
+                        '',
+                        '',
+                        '',
+                        ''
                     ];
                 }
             }

Now open your composer.json file and add patch file location:

Add below code in extra

 "extra": {
    "magento-force": "override",
    "composer-exit-on-patch-failure": true,
    "patches": { 
        "magento/framework": { 
            "Patch for Magento issue with custom theme logo": "patches/CustomThemeLogo.patch" 
        }
    }
}

Now run composer install or composer update command as required

And other commands

It will resolve your issue

Thanks

1
  • i dont think so this is better way to do this, creating a patch and force magento to override utility files is not success for me Oct 26, 2022 at 13:32
0

Backtrace the error

Add the following code in /vendor/magento/framework/View/Asset/PreProcessor/FileNameResolver.php above line 45

if ($fileName === null) { 
    debug_print_backtrace(2); 
    die;
}

For me, the backtrace putout was something like this:

#0 vendor/magento/module-deploy/Collector/Collector.php(97): Magento\Framework\View\Asset\PreProcessor\FileNameResolver->resolve(NULL)
#1 vendor/magento/module-deploy/Package/PackagePool.php(183): Magento\Deploy\Collector\Collector->collect()
#2 vendor/magento/module-deploy/Package/PackagePool.php(117): Magento\Deploy\Package\PackagePool->collect()
#3 vendor/magento/module-deploy/Strategy/QuickDeploy.php(54): Magento\Deploy\Package\PackagePool->getPackagesForDeployment(Array)

I had to create the following patch to fix the error:

--- a/vendor/magento/module-deploy/Collector/Collector.php
+++ b/vendor/magento/module-deploy/Collector/Collector.php
@@ -90,7 +90,7 @@
         foreach ($this->sourcePool->getAll() as $source) {
             $files = $source->get();
             foreach ($files as $file) {
-                if ($file->getModule() && !$this->moduleManager->isEnabled($file->getModule())) {
+                if ($file->getModule() && !$this->moduleManager->isEnabled($file->getModule()) || is_null($file->getFileName())) {
                     continue;
                 }
                 $file->setDeployedFileName($this->fileNameResolver->resolve($file->getFileName()));
-2

If the theme is Porto, the following may help:

rm -R ./app/design/frontend/Smartwave/porto_child

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.