I am facing this error "Uncaught TypeError: Argument 1 passed to Illuminate\Log\Logger
::__construct() must be an instance of Psr\Log\LoggerInterface, instance of Mono
log\Logger given,"
when i run php artisan command. my php version is 7.3.9
I had this issue last night, tried with php 7.3 and 7.4 in the end i just used the latest php 8.1 and this issue went away.
You could try going to illuminate/log/Logger.php and adding use Monolog\Logger as Monolog; at the beginning of the file. After that, change the constructor from this:
/**
* Create a new log writer instance.
*
* #param \Psr\Log\LoggerInterface $logger
* #param \Illuminate\Contracts\Events\Dispatcher|null $dispatcher
* #return void
*/
public function __construct(LoggerInterface $logger, Dispatcher $dispatcher = null)
{
$this->logger = $logger;
$this->dispatcher = $dispatcher;
}
to this:
/**
* Create a new log writer instance.
*
* #param \Monolog\Logger $logger
* #param \Illuminate\Contracts\Events\Dispatcher|null $dispatcher
* #return void
*/
public function __construct(Monolog $logger, Dispatcher $dispatcher = null)
{
$this->logger = $logger;
$this->dispatcher = $dispatcher;
}
Related
When I updated from Symfony 3.4 to 4 and displayed it in the browser, the following error is displayed on the toolbar, and the toolbar is not working properly.
Of course, I haven't changed the code myself. I hope someone can help me. Please let me know if you have any missing information.
Error message
//toolbar
An error occurred while loading the web debug toolbar.
Open the web profiler.
//web profiler
Argument 1 passed to Symfony\Component\Stopwatch\Stopwatch::stopSection() must be of the type string, null given,
called in /home/Symfony/vendor/symfony/http-kernel/Debug/TraceableEventDispatcher.php on line 69
Stopwatch.php
/**
* Starts an event.
*
* #param string $name The event name
* #param string $category The event category
*
* #return StopwatchEvent A StopwatchEvent instance
*/
public function start($name, $category = null)
{
return end($this->activeSections)->startEvent($name, $category);
}
TraceableEventDispatcher.php
/**
* Constructor.
*
* #param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance
* #param Stopwatch $stopwatch A Stopwatch instance
* #param LoggerInterface $logger A LoggerInterface instance
*/
public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null)
{
$this->dispatcher = $dispatcher;
$this->stopwatch = $stopwatch;
$this->logger = $logger;
$this->called = array();
$this->wrappedListeners = array();
$this->firstCalledEvent = array();
}
/**
* Sets the profiler.
*
* #param Profiler|null $profiler A Profiler instance
*/
public function setProfiler(Profiler $profiler = null)
{
$this->profiler = $profiler;
}
Version
Symfony4.0
symfony/stopwatch (v5.2.1)
I need to functionally test the a subscriber in Symfony 4 and I'm having problems finding how. The Subscriber has the following structure
/**
* Class ItemSubscriber
*/
class ItemSubscriber implements EventSubscriberInterface
{
/**
* #var CommandBus
*/
protected $commandBus;
/**
* Subscriber constructor.
*
* #param CommandBus $commandBus
*/
public function __construct(CommandBus $commandBus)
{
$this->commandBus = $commandBus;
}
/**
* {#inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
CommandFailedEvent::NAME => 'onCommandFailedEvent',
];
}
/**
* #param CommandFailedEvent $event
*
* #throws Exception
*/
public function onCommandFailedEvent(CommandFailedEvent $event)
{
$item = $event->getItem();
$this->processFailed($item);
}
/**
* Sends message
*
* #param array $item
*
* #throws Exception
*/
private function processFailed(array $item)
{
$this->commandBus->handle(new UpdateCommand($item));
}
}
The flow of the subscriber is receiving an internal event and send a message by rabbit through the command bus to another project.
How can I test that dispatching the event CommandFailedEvent the line in processFailed(array $item) is executed?
Does anyone has documentation on best practices to test Events and Subscribers in Symfony 4?
If you want to test the process of a command bus handler being call you could test dependency method calls thanks to mock expects. You have some examples in the PHPUnit documentation.
For instance, you would have something like:
$commandBus = $this->getMockBuilder(CommandBus::class)->disableOriginalConstructor()->getMock();
$commandBus->expects($this->once())->method('handle');
// Create your System Under Test
$SUT = new CommandFailedSubscriber($commandBus);
// Create event
$item = $this->getMockBuilder(YourItem::class)->getMock();
$event = new CommandFailedEvent($item);
// Dispatch your event
$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber($SUT);
$dispatcher->dispatch($event);
I hope this would be enough for you to explore possibilities and to have the coverage needed for your feature.
Have a nice time testing!
I'm trying to implement the paypal into my site.
But I'm getting this error .
Type error: Argument 1 passed to PayPal\Rest\ApiContext::setConfig() must be of the type array, null given, called in D:\wamp64\www\vonservices\app\Http\Controllers\PaymentController.php on line 40 .
Here is my controller code :
class PaymentController extends Controller
{
private $_api_context;
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
//parent::__construct();
/** setup PayPal api context **/
$paypal_conf = \Config::get('paypal');
$this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
$this->_api_context->setConfig($paypal_conf['settings']);
}
/**
* Show the application paywith paypalpage.
*
* #return \Illuminate\Http\Response
*/
public function payWithPaypal()
{
return view('paywithpaypal');
}
/**
* Store a details of payment with paypal.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
}
?>```
\Config::get('paypal') is an old way to find data in config. Try use config('paypal') and php artisan config:cache before using it.
I know its very late but I had the same problem. What solved my problem was running
php artisan config:cache
And voila, it solved everything for me. Hope it works for others too.
I have a strange error with Twig and the WebProfiler when I enable a Doctrine filter.
request.CRITICAL: Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown
during the rendering of a template ("Error when rendering "http://community.localhost:8000/
_profiler/e94abf?community_subdomain=community&panel=request" (Status code is 404).")." at
/../vendor/symfony/symfony/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/
layout.html.twig line 103
This {{ render(path('_profiler_search_bar', request.query.all)) }} causes the error.
My doctrine filter allows to add filter constraint on some classes (multi tenant app with dynamic subdomains)
<?php
namespace AppBundle\Group\Community;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\Filter\SQLFilter;
/**
* Class CommunityAwareFilter
*/
class CommunityAwareFilter extends SQLFilter
{
/**
* Gets the SQL query part to add to a query.
*
* #param ClassMetadata $targetEntity
* #param string $targetTableAlias
*
* #return string The constraint SQL if there is available, empty string otherwise.
*/
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
if (!$targetEntity->reflClass->implementsInterface(CommunityAwareInterface::class)) {
return '';
}
return sprintf('%s.community_id = %s', $targetTableAlias, $this->getParameter('communityId')); // <-- error
// return ''; <-- no error
}
}
I have also extended Symfony Router to add subdomain placeholder automatically in routing.
Do you have any idea what can cause this ?
UPDATE
<?php
namespace AppBundle\Routing;
use AppBundle\Group\Community\CommunityResolver;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Bundle\FrameworkBundle\Routing\Router as BaseRouter;
class Router implements RouterInterface
{
/**
* #var BaseRouter
*/
private $router;
/**
* #var RequestStack
*/
private $request;
/**
* #var CommunityResolver
*/
private $communityResolver;
/**
* Router constructor.
*
* #param BaseRouter $router
* #param RequestStack $request
* #param CommunityResolver $communityResolver
*/
public function __construct(BaseRouter $router, RequestStack $request, CommunityResolver $communityResolver)
{
$this->router = $router;
$this->request = $request;
$this->communityResolver = $communityResolver;
}
/**
* Sets the request context.
*
* #param RequestContext $context The context
*/
public function setContext(RequestContext $context)
{
$this->router->setContext($context);
}
/**
* Gets the request context.
*
* #return RequestContext The context
*/
public function getContext()
{
return $this->router->getContext();
}
/**
* Gets the RouteCollection instance associated with this Router.
*
* #return RouteCollection A RouteCollection instance
*/
public function getRouteCollection()
{
return $this->router->getRouteCollection();
}
/**
* Tries to match a URL path with a set of routes.
*
* If the matcher can not find information, it must throw one of the exceptions documented
* below.
*
* #param string $pathinfo The path info to be parsed (raw format, i.e. not urldecoded)
*
* #return array An array of parameters
*
* #throws ResourceNotFoundException If the resource could not be found
* #throws MethodNotAllowedException If the resource was found but the request method is not allowed
*/
public function match($pathinfo)
{
return $this->router->match($pathinfo);
}
public function generate($name, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
if (null !== ($community = $this->communityResolver->getCommunity())) {
$parameters['community_subdomain'] = $community->getSubDomain();
}
return $this->router->generate($name, $parameters, $referenceType);
}
}
I found the solution, in fact I passed my "tenant" (here my "community") object in the Session like this (in a subscriber onKernelRequest)
if (null === ($session = $request->getSession())) {
$session = new Session();
$session->start();
$request->setSession($session);
}
$session->set('community', $community);
I changed to store this object in a service and it works. Maybe using the Session to store data is a bad practice.
I think your Symmfony Router override may cause the problem. Can you paste us the code ?
I'm trying to run iFlyChat with Symfony using their PHP client https://iflychat.com/installation/php-chat-client which I have successfully install using composer.
I've created an extension for the code:
<?php
namespace DW\UserBundle\Twig;
use DW\UserBundle\Service\UserService;
use Iflylabs\iFlyChat;
class ChatExtension extends \Twig_Extension
{
/**
* #var UserService
*/
private $userService;
/**
* #var string
*/
private $appId;
/**
* #var string
*/
private $apiKey;
/**
* #param UserService $userService
* #param string $appId
* #param string $apiKey
*/
public function __construct(UserService $userService, string $appId, string $apiKey)
{
$this->userService = $userService;
$this->appId = $appId;
$this->apiKey = $apiKey;
}
/**
* #return array
*/
public function getFunctions()
{
return [
new \Twig_SimpleFunction("chat", [$this, "chat"])
];
}
public function chat()
{
$iflyChat = new iFlyChat($this->appId, $this->apiKey);
echo $iflyChat->getHtmlCode();
}
/**
* #return string
*/
public function getName()
{
return 'chat_extension';
}
}
but I get an error:
Attempted to load class "iFlyChat" from namespace "IFlyLabs". Did you
forget a "use" statement for another namespace?
Do I need to do something with the autoloader? I've been looking into registerPrefixes here but that doesn't exist anymore for Symfony3.2.
Have a look at vendor/composer/autoload_psr4.php so you can make sure there is an autoload namespace generated for IflyChat.
If there isn't you can execute:
composer dump-autoload
to force composer to regenerate the autoload for your dependencies.
It's because the file name does not match class name, it's installed as iflychat.php while the class is iFlyChat. Renaming the file to iFlyChat.php works.