1

I am working on Magento 2.3.3. I am getting an error on my instance

Fatal error: Uncaught Error: Class 'Magento\Framework\Profiler' not found in vendor/magento/framework/App/ObjectManagerFactory.php:144

I have found Magento Commands are also not executing on the instance. Please guide to resolve this error. Thanks!!!

PRABHAT MISHRA
  • 72
  • 1
  • 11

1 Answers1

1

Replace your ObjectManagerFactory.php code with below code

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Framework\App;

use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; use Magento\Framework\Interception\ObjectManager\ConfigInterface; use Magento\Framework\Profiler; use Magento\Framework\App\ObjectManager\Environment; use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Code\GeneratedFiles;

/**

  • Initialization of object manager is a complex operation.
  • To abstract away this complexity, this class was introduced.
  • Objects of this class create fully initialized instance of object manager with "global" configuration loaded.
  • @api
  • @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  • @since 100.0.2

/ class ObjectManagerFactory { /* * Initialization parameter for a custom deployment configuration file */ const INIT_PARAM_DEPLOYMENT_CONFIG_FILE = 'MAGE_CONFIG_FILE';

/**
 * Initialization parameter for custom deployment configuration data
 */
const INIT_PARAM_DEPLOYMENT_CONFIG = 'MAGE_CONFIG';

/**
 * Locator class name
 *
 * @var string
 */
protected $_locatorClassName = \Magento\Framework\App\ObjectManager::class;

/**
 * Config class name
 *
 * @var string
 */
protected $_configClassName = \Magento\Framework\Interception\ObjectManager\ConfigInterface::class;

/**
 * Environment factory class name
 *
 * @var string
 */
protected $envFactoryClassName = \Magento\Framework\App\EnvironmentFactory::class;

/**
 * Filesystem directory list
 *
 * @var DirectoryList
 */
protected $directoryList;

/**
 * Filesystem driver pool
 *
 * @var DriverPool
 */
protected $driverPool;

/**
 * Configuration file pool
 *
 * @var ConfigFilePool
 */
protected $configFilePool;

/**
 * Factory
 *
 * @var \Magento\Framework\ObjectManager\FactoryInterface
 */
protected $factory;

/**
 * Constructor
 *
 * @param DirectoryList $directoryList
 * @param DriverPool $driverPool
 * @param ConfigFilePool $configFilePool
 */
public function __construct(DirectoryList $directoryList, DriverPool $driverPool, ConfigFilePool $configFilePool)
{
    $this-&gt;directoryList = $directoryList;
    $this-&gt;driverPool = $driverPool;
    $this-&gt;configFilePool = $configFilePool;
}

/**
 * Create ObjectManager
 *
 * @param array $arguments
 * @return \Magento\Framework\ObjectManagerInterface
 *
 * @SuppressWarnings(PHPMD.NPathComplexity)
 */
public function create(array $arguments)
{
    $writeFactory = new \Magento\Framework\Filesystem\Directory\WriteFactory($this-&gt;driverPool);
    $generatedFiles = new GeneratedFiles($this-&gt;directoryList, $writeFactory);
    $generatedFiles-&gt;cleanGeneratedFiles();

    $deploymentConfig = $this-&gt;createDeploymentConfig($this-&gt;directoryList, $this-&gt;configFilePool, $arguments);
    $arguments = array_merge($deploymentConfig-&gt;get(), $arguments);
    $definitionFactory = new \Magento\Framework\ObjectManager\DefinitionFactory(
        $this-&gt;driverPool-&gt;getDriver(DriverPool::FILE),
        $this-&gt;directoryList-&gt;getPath(DirectoryList::GENERATED_CODE)
    );

    $definitions = $definitionFactory-&gt;createClassDefinition();
    $relations = $definitionFactory-&gt;createRelations();

    /** @var EnvironmentFactory $envFactory */
    $envFactory = new $this-&gt;envFactoryClassName($relations, $definitions);
    /** @var EnvironmentInterface $env */
    $env = $envFactory-&gt;createEnvironment();

    /** @var ConfigInterface $diConfig */
    $diConfig = $env-&gt;getDiConfig();

    $appMode = isset($arguments[State::PARAM_MODE]) ? $arguments[State::PARAM_MODE] : State::MODE_DEFAULT;
    $booleanUtils = new \Magento\Framework\Stdlib\BooleanUtils();
    $argInterpreter = $this-&gt;createArgumentInterpreter($booleanUtils);
    $argumentMapper = new \Magento\Framework\ObjectManager\Config\Mapper\Dom($argInterpreter);

    if ($env-&gt;getMode() != Environment\Compiled::MODE) {
        $configData = $this-&gt;_loadPrimaryConfig($this-&gt;directoryList, $this-&gt;driverPool, $argumentMapper, $appMode);
        if ($configData) {
            $diConfig-&gt;extend($configData);
        }
    }

    // set cache profiler decorator if enabled
    if (\Magento\Framework\Profiler::isEnabled()) {
        $cacheFactoryArguments = $diConfig-&gt;getArguments(\Magento\Framework\App\Cache\Frontend\Factory::class);
        $cacheFactoryArguments['decorators'][] = [
            'class' =&gt; \Magento\Framework\Cache\Frontend\Decorator\Profiler::class,
            'parameters' =&gt; ['backendPrefixes' =&gt; ['Zend_Cache_Backend_', 'Cm_Cache_Backend_']],
        ];
        $cacheFactoryConfig = [
            \Magento\Framework\App\Cache\Frontend\Factory::class =&gt; ['arguments' =&gt; $cacheFactoryArguments]
        ];
        $diConfig-&gt;extend($cacheFactoryConfig);
    }

    $sharedInstances = [
        \Magento\Framework\App\DeploymentConfig::class =&gt; $deploymentConfig,
        \Magento\Framework\App\Filesystem\DirectoryList::class =&gt; $this-&gt;directoryList,
        \Magento\Framework\Filesystem\DirectoryList::class =&gt; $this-&gt;directoryList,
        \Magento\Framework\Filesystem\DriverPool::class =&gt; $this-&gt;driverPool,
        \Magento\Framework\ObjectManager\RelationsInterface::class =&gt; $relations,
        \Magento\Framework\Interception\DefinitionInterface::class =&gt; $definitionFactory-&gt;createPluginDefinition(),
        \Magento\Framework\ObjectManager\ConfigInterface::class =&gt; $diConfig,
        \Magento\Framework\Interception\ObjectManager\ConfigInterface::class =&gt; $diConfig,
        \Magento\Framework\ObjectManager\DefinitionInterface::class =&gt; $definitions,
        \Magento\Framework\Stdlib\BooleanUtils::class =&gt; $booleanUtils,
        \Magento\Framework\ObjectManager\Config\Mapper\Dom::class =&gt; $argumentMapper,
        \Magento\Framework\ObjectManager\ConfigLoaderInterface::class =&gt; $env-&gt;getObjectManagerConfigLoader(),
        $this-&gt;_configClassName =&gt; $diConfig,
    ];
    $arguments['shared_instances'] = &amp;$sharedInstances;
    $this-&gt;factory = $env-&gt;getObjectManagerFactory($arguments);

    /** @var \Magento\Framework\ObjectManagerInterface $objectManager */
    $objectManager = new $this-&gt;_locatorClassName($this-&gt;factory, $diConfig, $sharedInstances);

    $this-&gt;factory-&gt;setObjectManager($objectManager);

    $generatorParams = $diConfig-&gt;getArguments(\Magento\Framework\Code\Generator::class);
    /** Arguments are stored in different format when DI config is compiled, thus require custom processing */
    $generatedEntities = isset($generatorParams['generatedEntities']['_v_'])
        ? $generatorParams['generatedEntities']['_v_']
        : (isset($generatorParams['generatedEntities']) ? $generatorParams['generatedEntities'] : []);
    $definitionFactory-&gt;getCodeGenerator()
        -&gt;setObjectManager($objectManager)
        -&gt;setGeneratedEntities($generatedEntities);

    $env-&gt;configureObjectManager($diConfig, $sharedInstances);

    return $objectManager;
}

/**
 * Creates deployment configuration object
 *
 * @param DirectoryList $directoryList
 * @param ConfigFilePool $configFilePool
 * @param array $arguments
 * @return DeploymentConfig
 */
protected function createDeploymentConfig(
    DirectoryList $directoryList,
    ConfigFilePool $configFilePool,
    array $arguments
) {
    $customFile = isset($arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG_FILE])
        ? $arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG_FILE]
        : null;
    $customData = isset($arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG])
        ? $arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG]
        : [];
    $reader = new DeploymentConfig\Reader($directoryList, $this-&gt;driverPool, $configFilePool, $customFile);
    return new DeploymentConfig($reader, $customData);
}

/**
 * Return newly created instance on an argument interpreter, suitable for processing DI arguments
 *
 * @param \Magento\Framework\Stdlib\BooleanUtils $booleanUtils
 * @return \Magento\Framework\Data\Argument\InterpreterInterface
 */
protected function createArgumentInterpreter(
    \Magento\Framework\Stdlib\BooleanUtils $booleanUtils
) {
    $constInterpreter = new \Magento\Framework\Data\Argument\Interpreter\Constant();
    $result = new \Magento\Framework\Data\Argument\Interpreter\Composite(
        [
            'boolean' =&gt; new \Magento\Framework\Data\Argument\Interpreter\Boolean($booleanUtils),
            'string' =&gt; new \Magento\Framework\Data\Argument\Interpreter\BaseStringUtils($booleanUtils),
            'number' =&gt; new \Magento\Framework\Data\Argument\Interpreter\Number(),
            'null' =&gt; new \Magento\Framework\Data\Argument\Interpreter\NullType(),
            'object' =&gt; new \Magento\Framework\Data\Argument\Interpreter\DataObject($booleanUtils),
            'const' =&gt; $constInterpreter,
            'init_parameter' =&gt; new \Magento\Framework\App\Arguments\ArgumentInterpreter($constInterpreter),
        ],
        \Magento\Framework\ObjectManager\Config\Reader\Dom::TYPE_ATTRIBUTE
    );
    // Add interpreters that reference the composite
    $result-&gt;addInterpreter('array', new \Magento\Framework\Data\Argument\Interpreter\ArrayType($result));
    return $result;
}

/**
 * Load primary config
 *
 * @param DirectoryList $directoryList
 * @param DriverPool $driverPool
 * @param mixed $argumentMapper
 * @param string $appMode
 * @return array
 * @throws \Magento\Framework\Exception\State\InitException
 */
protected function _loadPrimaryConfig(DirectoryList $directoryList, $driverPool, $argumentMapper, $appMode)
{
    $configData = null;
    try {
        $fileResolver = new \Magento\Framework\App\Arguments\FileResolver\Primary(
            new \Magento\Framework\Filesystem(
                $directoryList,
                new \Magento\Framework\Filesystem\Directory\ReadFactory($driverPool),
                new \Magento\Framework\Filesystem\Directory\WriteFactory($driverPool)
            ),
            new \Magento\Framework\Config\FileIteratorFactory(
                new \Magento\Framework\Filesystem\File\ReadFactory($driverPool)
            )
        );
        $schemaLocator = new \Magento\Framework\ObjectManager\Config\SchemaLocator();
        $validationState = new \Magento\Framework\App\Arguments\ValidationState($appMode);

        $reader = new \Magento\Framework\ObjectManager\Config\Reader\Dom(
            $fileResolver,
            $argumentMapper,
            $schemaLocator,
            $validationState
        );
        $configData = $reader-&gt;read('primary');
    } catch (\Exception $e) {
        throw new \Magento\Framework\Exception\State\InitException(
            new \Magento\Framework\Phrase($e-&gt;getMessage()),
            $e
        );
    }
    return $configData;
}

/**
 * Crete plugin list object
 *
 * @param \Magento\Framework\ObjectManagerInterface $objectManager
 * @param \Magento\Framework\ObjectManager\RelationsInterface $relations
 * @param \Magento\Framework\ObjectManager\DefinitionFactory $definitionFactory
 * @param \Magento\Framework\ObjectManager\Config\Config $diConfig
 * @param \Magento\Framework\ObjectManager\DefinitionInterface $definitions
 * @return \Magento\Framework\Interception\PluginList\PluginList
 * @deprecated 101.0.0
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
protected function _createPluginList(
    \Magento\Framework\ObjectManagerInterface $objectManager,
    \Magento\Framework\ObjectManager\RelationsInterface $relations,
    \Magento\Framework\ObjectManager\DefinitionFactory $definitionFactory,
    \Magento\Framework\ObjectManager\Config\Config $diConfig,
    \Magento\Framework\ObjectManager\DefinitionInterface $definitions
) {
    return $objectManager-&gt;create(
        \Magento\Framework\Interception\PluginList\PluginList::class,
        [
            'relations' =&gt; $relations,
            'definitions' =&gt; $definitionFactory-&gt;createPluginDefinition(),
            'omConfig' =&gt; $diConfig,
            'classDefinitions' =&gt; null
        ]
    );
}

}

hope this works

Pramod
  • 1,464
  • 1
  • 11
  • 38