I manually downloaded mpdf 8 files to the application\third-party
..Also Psr\log downloaded in application\psr\log .
I modified the path in Mpdf.php and i got this.
An uncaught Exception was encountered Type: TypeError
Message: Mpdf\ServiceFactory::getServices(): Argument #2 ($logger) must be of type psr\log\Psr\Log\LoggerInterface, Psr\Log\NullLogger given, called in D:\wamp\www\test\application\third_party\Mpdf\Mpdf.php on line 1092
Filename: D:\wamp\www\test\application\third_party\Mpdf\ServiceFactory.php
Line Number: 44
Mpdf.php file portion i got error
$this->logger = new NullLogger();
$originalConfig = $config;
$config = $this->initConfig($originalConfig);
$serviceFactory = new ServiceFactory($container);
$services = $serviceFactory->getServices(
$this,
$this->logger,
$config,
$this->languageToFont,
$this->scriptToLanguage,
$this->fontDescriptor,
$this->bmp,
$this->directWrite,
$this->wmf
);
NullLogger.php
<?php
namespace Psr\Log;
/**
* This Logger can be used to avoid conditional log calls.
*
* Logging should always be optional, and if no logger is provided to your
* library creating a NullLogger instance to have something to throw logs at
* is a good way to avoid littering your code with `if ($this->logger) { }`
* blocks.
*/
require_once APPPATH . 'third_party/psr/log/src/Psr/Log/AbstractLogger.php';
class NullLogger extends AbstractLogger
{
/**
* Logs with an arbitrary level.
*
* @param mixed[] $context
*
* @throws \Psr\Log\InvalidArgumentException
*/
public function log($level, string|\Stringable $message, array $context = []): void
{
// noop
}
}
Please help me to proceed. Currently I use mpdf 6. I want to upgrade this to php 8.
I manually downloaded mpdf 8 files to the application\third-party
..Also Psr\log downloaded in application\psr\log .
I modified the path in Mpdf.php and i got this.
An uncaught Exception was encountered Type: TypeError
Message: Mpdf\ServiceFactory::getServices(): Argument #2 ($logger) must be of type psr\log\Psr\Log\LoggerInterface, Psr\Log\NullLogger given, called in D:\wamp\www\test\application\third_party\Mpdf\Mpdf.php on line 1092
Filename: D:\wamp\www\test\application\third_party\Mpdf\ServiceFactory.php
Line Number: 44
Mpdf.php file portion i got error
$this->logger = new NullLogger();
$originalConfig = $config;
$config = $this->initConfig($originalConfig);
$serviceFactory = new ServiceFactory($container);
$services = $serviceFactory->getServices(
$this,
$this->logger,
$config,
$this->languageToFont,
$this->scriptToLanguage,
$this->fontDescriptor,
$this->bmp,
$this->directWrite,
$this->wmf
);
NullLogger.php
<?php
namespace Psr\Log;
/**
* This Logger can be used to avoid conditional log calls.
*
* Logging should always be optional, and if no logger is provided to your
* library creating a NullLogger instance to have something to throw logs at
* is a good way to avoid littering your code with `if ($this->logger) { }`
* blocks.
*/
require_once APPPATH . 'third_party/psr/log/src/Psr/Log/AbstractLogger.php';
class NullLogger extends AbstractLogger
{
/**
* Logs with an arbitrary level.
*
* @param mixed[] $context
*
* @throws \Psr\Log\InvalidArgumentException
*/
public function log($level, string|\Stringable $message, array $context = []): void
{
// noop
}
}
Please help me to proceed. Currently I use mpdf 6. I want to upgrade this to php 8.
Share Improve this question edited Mar 13 at 11:47 ADyson 62.2k16 gold badges79 silver badges92 bronze badges Recognized by PHP Collective asked Mar 13 at 10:43 THUSHARATHUSHARA 191 bronze badge 2- 1 Just use composer to install mPDF, you'll save yourself a lot of headaches. – Finwe Commented Mar 13 at 12:39
- You probably should edit your question and add of what nature your changes of the path modification for Mpdf were, as it might be related to the missing interface. – hakre Commented Mar 15 at 11:30
2 Answers
Reset to default 0Do composer installation instead of manual
composer update mpdf/mpdf
Try to Install PSR Log as well.
composer require psr/log
I hope it will help.
I advise you not to modify any code in the vendor files until required.
It requires decent reading:
psr\log\Psr\Log\LoggerInterface
^^^^^^^^
This interface does not exist, therefore it can never be fulfilled and henceforth PHP can only error.
This is propably related to a similar confusion:
application\third-party
application\psr\log
You make use of psr\log as third-party, but you place it out of your third-party classes directory (the class path).
Therefore, I'd suggest the following:
1.) Move the third-party code into the third-party directory.
2.) Double-check the imports on top of the file that makes use of Psr\Log\LoggerInterface
(D:\wamp\www\test\application\third_party\Mpdf\ServiceFactory.php).
There certainly is an issue when making use of the logger (https://github/mpdf/mpdf/blob/development/src/ServiceFactory.php#L28), which by the source is not an issue in the third-party code there and the other location you present gives a line mismatch in the current version of the third-party code (https://github/mpdf/mpdf/blob/development/src/Mpdf.php#L1092) so it remains unknown to me whether it's just a buggy version you make use of, a misconfiguration on the logger aliasing during service configuration (a configuration issue on your end with MPdf), but you have your code at hand so you may already spot it.
Just take note on the namespaces and how they are different, you have a prefix that is not in Psr\Log:
psr\log\Psr\Log\LoggerInterface
^^^^^^^^