У меня есть 3 роли, определенные в моем security.yml следующим образом:
role_hierarchy:
ROLE_ADMIN: [ROLE_MANAGER]
ROLE_MANAGER: [ROLE_EMPLOYEE]
ROLE_EMPLOYEE: [ROLE_USER]
иногда я получаю следующую ошибку:
2019-01-13T19: 07: 19 + 00: 00 [критический] Ошибка типа: Аргумент 1 передан Symfony \ Component \ Security \ Core \ Role \ RoleHierarchy :: getReachableRoles () должен быть
массива типов, с указанным нулем, вызывается в / app / vendor / sensio / framework-extra-
bundle / EventListener / SecurityListener.php в строке 90
2019-01-13T19: 07: 19.205536 + приложение 00:00 [web.1]: 2019-01-13T19: 07: 19 + 00:00
[критическое] Uncaught PHP Exception
Symfony \ Component \ Debug \ Exception \ FatalThrowableError: "Ошибка типа: Аргумент 1
перешел к
Symfony \ Component \ Security \ Core \ Role \ RoleHierarchy :: getReachableRoles () должен быть
массива типов, с указанным нулем, вызывается в / app / vendor / sensio / framework-extra-
bundle / EventListener / SecurityListener.php в строке 90 "в / app / vendor / symfony / symfony / src / Symfony / Component / Security / Core / Role / RoleHierarchy.php, строка 37
2019-01-13T19: 07: 19.208667 + приложение 00: 00 [web.1]: 2019-01-13T19: 07: 19 + 00: 00
[предупреждение] Предупреждение: array_map (): ожидаемый параметр 2 будет массивом, значение NULL
У вас есть идеи?
UPDATE
SendSurveyFormBuilder.php
class SendSurveyFormBuilder extends FormBuilder
{
private $teamManager;
private $officeManager;
private $projectManager;
private $formFactory;
private $surveyTypeManager;
public function __construct
(
# TeamManager $teamManager,
# OfficeManager $officeManager,
# ProjectManager $projectManager,
FormFactoryInterface $formFactory#,
# SurveyTypeManager $surveyTypeManager
)
{
# $this->teamManager = $teamManager;
# $this->officeManager = $officeManager;
# $this->projectManager = $projectManager;
$this->formFactory = $formFactory;
# $this->surveyTypeManager = $surveyTypeManager;
}
public function buildForm(Company $company)
{
#$company = $user->getCompany();
$teams = [];
$projects = [];
$offices = [];
$surveyTypeChoices = [];
$targetChoices = [];
$options = [];
# if ($user->hasRole("ROLE_ADMIN")) {
/*
$teams = $this->teamManager->getTeamsByCompany($company);
$projects = $this->projectManager->getByCompany($company);
$offices = $this->officeManager->getOfficesByCompany($company);
*/
$targetChoices["Groups"] = [
sprintf("%s (%s)", 'All Employees', $company->getEmployees()->count()) => new Group(Team::GROUP_ALL),
// 'All Managers' => Team::GROUP_MANAGERS,
// 'All Employees without Managers' => Team::GROUP_NO_MANAGERS
];
/* } elseif ($user->hasRole("ROLE_MANAGER")) {
$teams = $this->teamManager->getTeamsByManager($user);
$projects = $this->projectManager->getByManager($user);
}*/
$targetChoices["Teams"] = $this->transformTargetChoices($teams);
$targetChoices["Projects"] = $this->transformTargetChoices($projects);
$targetChoices["Offices"] = $this->transformTargetChoices($offices);
/*
* $standardSurveyTypes = $this->surveyTypeManager->getStandardSurveyTypes();
$customSurveyTypes = $this->surveyTypeManager->getCustomSurveyTypesByCompany($user->getCompany());
*
*
$surveyTypeChoices = [
"Standard" => $this->transformSurveyTypeChoices($standardSurveyTypes),
"Custom" => $this->transformSurveyTypeChoices($customSurveyTypes)
];*/
$options["targetChoices"] = $targetChoices;
$options["surveyTypeChoices"] = $surveyTypeChoices;
$this->form = $this->formFactory->create(NewSurveyType::class, null, $options);
return $this;
}
private function transformTargetChoices($objects)
{
$choices = [];
for ($i=0; $i<count($objects); $i++) {
$name = sprintf("%s (%s)", $objects[$i]->getName(), $objects[$i]->getEmployees()->count());
$choices[$name] = $objects[$i];
}
return $choices;
}
private function transformSurveyTypeChoices($objects)
{
$choices = [];
for ($i=0; $i<count($objects); $i++) {
$name = $objects[$i]->getName();
$choices[$name] = $objects[$i];
}
return $choices;
}
}
Фактическая форма:
class NewSurveyType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$targetChoices = $options["targetChoices"];
$surveyTypeChoices = $options["surveyTypeChoices"];
$builder
->add("surveyType", ChoiceType::class, [
"choices" => $surveyTypeChoices
])
->add("target", ChoiceType::class, [
'choices' => $targetChoices,
"mapped" => false
])
->add("deadline", ChoiceType::class, [
"choices" => [
"Same Day" => QuestionnaireInterval::RANGE_SAME_DAY,
"7 Days" => QuestionnaireInterval::RANGE_7_DAYS,
"30 Days" => QuestionnaireInterval::RANGE_30_DAYS
]
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired("targetChoices");
$resolver->setRequired("surveyTypeChoices");
}
}
И метод проверки контроллера:
/**
* @Route("/test-survey", name="survey_test")
*/
public function testAction()
{
$user = $this->getUser();
$company = $user->getCompany();
$form = $this->sendSurveyFormBuilder->buildForm($company)->getForm();
return new Response();
}
Когда я иду по этому маршруту, а затем иду по другому маршруту (даже если я ввожу его вручную в браузере, возникает ошибка. Я потратил целый день на эту ошибку ..