У меня есть TypeError
в конструкторе TraceableVoter в Symfony 4.2.2 проекте при рендеринге индексной страницы с добавленной пользовательской панелью навигации.Файл security.yaml прилагается к этому вопросу ниже.
Весь исходный проект является полной копией курса Symfony 4 от Udemy.
TypeError
идет со следующей трассировкой:
Аргумент 4, передаваемый в Symfony \ Component \ Security \ Core \ Event \ VoteEvent :: __ construct (), должен иметь тип integer, значение NULL и вызываться из / home / vagrant / symfony-01 / vendor / symfony / security-core/Authorization/Voter/TraceableVoter.php в строке 40 Twig_Environment-> render ('micro-post / index.html.twig', массив ('posts' => array (object (MicroPost), объект (MicroPost), объект (MicroPost)), объект (MicroPost), объект (MicroPost), объект (MicroPost), объект (MicroPost), объект (MicroPost), объект (MicroPost), объект (MicroPost)))) в src / Controller / MicroPostController.php (строка 81)
панель навигации от intex.html
<nav class="navbar navbar-dark navbar-expand-md sticky-top bg-dark p-0">
<a class="navbar-brand col-sm-3 col-md-2 mr-0"
href="{{ path('micro_post_index') }}">Micro Post App</a>
<div class="w-100 order-1 order-md-0">
<ul class="navbar-nav px-3">
{% if is_granted('ROLE_USER') %}
<li class="nav-item text-nowrap">
<a class="nav-link" href="{{ path('micro_post_add') }}">Add new</a>
</li>
{% endif %}
</ul>
</div>
<div class="order-2 order-md-1">
<ul class="navbar-nav px-3">
{% if is_granted('ROLE_USER') %}
<li class="nav-item text-nowrap">
<a class="nav-link"
href="#">{{ app.user.fullName }}</a>
</li>
<li class="nav-item text-nowrap">
<a class="nav-link"
href="{{ path('security_logout') }}">Sign out</a>
</li>
{% else %}
<li class="nav-item text-nowrap">
<a class="nav-link"
href="{{ path('security_login') }}">Sign in</a>
</li>
{% endif %}
</ul>
</div>
</nav>
Обработка страницы индекса в MicroPostController.php
/**
* @Route("/", name="micro_post_index")
* */
public function index()
{
$html = $this->twig->render('micro-post/index.html.twig', ['posts' => $this->microPostRepository->findAll()]);
return new Response($html);
}
security.yaml
security:
encoders:
App\Entity\User:
algorithm: bcrypt
app_user_provider:
entity:
class: App\Entity\User
property: username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
pattern: ^/
form_login:
check_path: security_login
login_path: security_login
csrf_token_generator: security.csrf.token_manager
default_target_path: micro_post_index
logout:
path: security_logout
target: micro_post_index
access_control:
- { path: ^/micro-post, roles: ROLE_USER }
Это не повторяющийся квест преобразование ролей toArray()
НЕ не решает мою проблему.Вот полная трассировка стека:
TypeError:
Argument 4 passed to Symfony\Component\Security\Core\Event\VoteEvent::__construct() must be of the type integer, null given, called in /home/vagrant/symfony-01/vendor/symfony/security-core/Authorization/Voter/TraceableVoter.php on line 40
at vendor/symfony/security-core/Event/VoteEvent.php:31
at Symfony\Component\Security\Core\Event\VoteEvent->__construct(object(ExampleVoter), object(Request), array('ROLE_USER'), null)
(vendor/symfony/security-core/Authorization/Voter/TraceableVoter.php:40)
at Symfony\Component\Security\Core\Authorization\Voter\TraceableVoter->vote(object(AnonymousToken), object(Request), array('ROLE_USER'))
(vendor/symfony/security-core/Authorization/AccessDecisionManager.php:73)
at Symfony\Component\Security\Core\Authorization\AccessDecisionManager->decideAffirmative(object(AnonymousToken), array('ROLE_USER'), object(Request))
(vendor/symfony/security-core/Authorization/AccessDecisionManager.php:60)
at Symfony\Component\Security\Core\Authorization\AccessDecisionManager->decide(object(AnonymousToken), array('ROLE_USER'), object(Request))
(vendor/symfony/security-core/Authorization/TraceableAccessDecisionManager.php:61)
at Symfony\Component\Security\Core\Authorization\TraceableAccessDecisionManager->decide(object(AnonymousToken), array('ROLE_USER'), object(Request))
(vendor/symfony/security-http/Firewall/AccessListener.php:67)
at Symfony\Component\Security\Http\Firewall\AccessListener->handle(object(GetResponseEvent))
(vendor/symfony/security-bundle/Debug/WrappedListener.php:46)
at Symfony\Bundle\SecurityBundle\Debug\WrappedListener->handle(object(GetResponseEvent))
(vendor/symfony/security-bundle/Debug/TraceableFirewallListener.php:35)
at Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener->handleRequest(object(GetResponseEvent), object(Generator))
(vendor/symfony/security-http/Firewall.php:90)
at Symfony\Component\Security\Http\Firewall->onKernelRequest(object(GetResponseEvent))
(vendor/symfony/security-bundle/EventListener/FirewallListener.php:48)
at Symfony\Bundle\SecurityBundle\EventListener\FirewallListener->onKernelRequest(object(GetResponseEvent), 'kernel.request', object(TraceableEventDispatcher))
(vendor/symfony/event-dispatcher/Debug/WrappedListener.php:111)
at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(GetResponseEvent), 'kernel.request', object(EventDispatcher))
(vendor/symfony/event-dispatcher/EventDispatcher.php:212)
at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(GetResponseEvent))
(vendor/symfony/event-dispatcher/EventDispatcher.php:44)
at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.request', object(GetResponseEvent))
(vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:145)
at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('kernel.request', object(GetResponseEvent))
(vendor/symfony/http-kernel/HttpKernel.php:126)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor/symfony/http-kernel/HttpKernel.php:67)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor/symfony/http-kernel/Kernel.php:198)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(public/index.php:25)