Php Symfony缓存无效argumantException
我需要了解symfony缓存组件的帮助。我用symfony表单从其他程序员那里继承了创建项目的脚本。这:Php Symfony缓存无效argumantException,php,symfony,caching,Php,Symfony,Caching,我需要了解symfony缓存组件的帮助。我用symfony表单从其他程序员那里继承了创建项目的脚本。这: class OfferController extends Controller { public function createAction(Request $request) { $api_offer = $this->get('gamexp_affiliates.api.admin.offer'); $api_user = $this-&g
class OfferController extends Controller
{
public function createAction(Request $request) {
$api_offer = $this->get('gamexp_affiliates.api.admin.offer');
$api_user = $this->get('gamexp_affiliates.api.admin.user');
$api_project = $this->get('gamexp_affiliates.api.admin.project');
$api_goal = $this->get('gamexp_affiliates.api.admin.goal');
$tpl = '@GamexpAffiliates/Admin/Offer/Form/create.html.twig';
$offer_webmasters = $offer_projects = $offer_goals = null;
$sendCommonResponse = function(FormInterface $form = null, $code = 200, $headers = []) use ($tpl, &$offer_webmasters, &$offer_projects, &$offer_goals) {
$params = [
'offer_webmasters' => $offer_webmasters,
'offer_projects' => $offer_projects,
'offer_goals' => $offer_goals,
];
$response = $this->render($tpl, $form ? array_merge([
'offer' => $form->createView(),
], $params) : $params, new Response('', $code, $headers));
return $response;
};
$selectProject = function($project_id) use ($api_project, &$offer_projects, &$projects_sort, &$projects_count) {
$project = null;
if ($project_id > 0 && is_numeric($project_id)) {
foreach ($offer_projects as $offer_project) {
if ($project_id == $offer_project['id']) {
$project = $offer_project;
break;
}
}
if (!$project) {
try {
if ($project = $api_project->findProjectByIdWithLandings($project_id, ['id', 'name', 'status'])) {
if ($projects_count <= $cnt = count($offer_projects)) {
$offer_projects = array_slice($offer_projects, $cnt - $projects_count + 1, $projects_count);
}
$offer_projects = array_merge($offer_projects, [$project]);
if ($projects_sort) {
usort($offer_projects, function(array $a, array $b) use ($api_project, $projects_sort) {
foreach ($projects_sort as $field => $sort_type) {
if ($comp = $sort_type === $api_project::SORT_ASCENDING ? strnatcmp($a[$field], $b[$field]) : strnatcmp($b[$field], $a[$field])) {
return $comp;
}
continue;
}
return 0;
});
}
}
} catch (\Exception $e) {
$this->get('logger')->error("Ошибка: " . $e->getMessage() . "на строке: " . $e->getLine());
}
}
}
return $project;
};
$createForm = function($data, $project = null, $landings = null) use ($api_offer, &$offer_webmasters, &$offer_projects, &$offer_goals) {
$params = [
'action' => $this->generateUrl('gamexp_affiliates.admin.api.offer.create'),
'statuses' => $api_offer->getAvailableStatuses($landings ? array_unique(array_column($landings, 'status')) : null),
'offer_webmasters' => $offer_webmasters,
'offer_projects' => $offer_projects,
'offer_goals' => $offer_goals,
];
if ($project && !empty($project['landings'])) {
$params['offer_landings'] = $project['landings'];
}
return $this->createForm(AdminOfferCreateType::class, $data, $params);
};
try {
if (!$offer_webmasters = $api_user->findAll(null, 10, 0, ['id', 'email', 'phone'])) {
return $sendCommonResponse();
}
} catch (\Exception $e) {
return $sendCommonResponse();
}
try {
if (!$offer_projects = $api_project->findAllProjectsWithLandingsAndUser(null, 10, 0, ['id', 'name', 'status'])) {
return $sendCommonResponse();
}
} catch (\Exception $e) {
return $sendCommonResponse();
}
try {
if (!$offer_goals = $api_goal->findAllItems(null, 10, 0, ['id', 'name', 'revshare', 'status'])) {
return $sendCommonResponse();
}
} catch (\Exception $e) {
return $sendCommonResponse();
}
$fast_mode = false;
if ($request->isMethod('GET')) {
$fast_mode = (0 < $project_id = $request->get('project') and is_numeric($project_id));
} else {
$project_id = null;
}
if ($project = $selectProject($project_id)) {
$data = [
'project' => $project['id'],
];
} else {
$data = null;
}
$form = $createForm($data, $project);
$form->handleRequest($request);
if ($form->isSubmitted()) {
if (!$request->isXmlHttpRequest()) {
throw $this->createNotFoundException();
}
if (!$request->isMethod('POST')) {
throw $this->createHttpException(405);
}
$data = $form->getData();
$landings = [];
if ($project = $selectProject(isset($data['project']) ? $data['project'] : null)) {
if (!empty($data['landings']) && !empty($project['landings'])) {
$data['landings'] = array_intersect($data['landings'], array_column($project['landings'], 'id'));
foreach ($project['landings'] as $landing) {
if (in_array($landing['id'], $data['landings'])) {
$landings[$landing['id']] = $landing;
}
}
}
}
$form = $createForm($data, $project, $landings);
$form->handleRequest($request);
$data = $form->getData();
if ($form->isValid()) {
if ($res = $this->linkApiResponseToForm($form, function(FormInterface $form, array $params) use ($api_offer, $data, $sendCommonResponse) {
if (in_array('project_selection', $params['validation_groups']) || in_array('landings_selection', $params['validation_groups']) || in_array('header_image_upload', $params['validation_groups'])) {
if (in_array('header_image_upload', $params['validation_groups'])) {
if (isset($data['header_image']) && $data['header_image'] instanceof UploadedFile) {
$api_offer->saveHeaderImage($data['header_image']);
}
}
return $sendCommonResponse($form, 300, [
'Location' => $this->generateUrl('gamexp_affiliates.admin.api.offer.create'),
]);
}
$data['creator'] = $this->getUser()->getId();
if ($id = (int)$api_offer->createOffer($data)) {
return new JsonResponse([
'id' => $id,
'name' => trim($data['name']),
], 201, [
'Location' => $this->generateUrl('gamexp_affiliates.admin.api.offer.update', ['id' => $id]),
]);
}
})) {
return $res;
}
}
return $sendCommonResponse($form, 400);
} elseif ($fast_mode && !$data['project']) {
$this->addFlash($form->getName().':warning', 'Проекта, который вы выбрали, не существует. Возможно кто-то другой его только что удалил. Попробуйте выбрать другой проект из списка.');
}
return $sendCommonResponse($form);
}
}
控制器类扩展控制器
{
公共函数createAction(请求$Request){
$api_offer=$this->get('gamexp_affiliates.api.admin.offer');
$api_user=$this->get('gamexp_affiliates.api.admin.user');
$api_project=$this->get('gamexp_affiliates.api.admin.project');
$api_-goal=$this->get('gamexp_-associates.api.admin.goal');
$tpl='@gamexpassociates/Admin/Offer/Form/create.html.twig';
$offer\u webmasters=$offer\u projects=$offer\u goals=null;
$sendCommonResponse=function(FormInterface$form=null,$code=200,$headers=[])使用($tpl,&$offer\u网站管理员,&$offer\u项目,&$offer\u目标){
$params=[
'offer_webmasters'=>$offer_webmasters,
“提供项目”=>$offer\u项目,
“提供目标”=>$offer\u目标,
];
$response=$this->render($tpl,$form?数组\u合并)([
'offer'=>$form->createView(),
],$params):$params,新响应(“”,$code,$headers));
返回$response;
};
$selectProject=function($project\u id)use($api\u project,&$offer\u projects,&$projects\u sort,&$projects\u count){
$project=null;
如果($project\u id>0&&is\u numeric($project\u id)){
foreach($offer\u项目作为$offer\u项目){
如果($project\u id==$offer\u project['id']){
$project=$offer\u项目;
打破
}
}
如果(!$项目){
试一试{
如果($project=$api\U project->FINDPROJECTBYID WITHLANDINGS($project\U id,['id','name','status'])){
if($projects\u count$sort\u type){
如果($comp=$sort\u type==$api\u项目::sort\u升序?strnatcmp($a[$field],$b[$field]):strnatcmp($b[$field],$a[$field])){
返回$comp;
}
继续;
}
返回0;
});
}
}
}捕获(\异常$e){
$this->get('logger')->错误(“аббббаa:.$e->getMessage()。$e->getLine());
}
}
}
返回$project;
};
$createForm=function($data,$project=null,$landings=null)使用($api_offer,&$offer_网站管理员,&$offer_项目,&$offer_目标){
$params=[
'action'=>this->generateUrl('gamexp_affiliates.admin.api.offer.create'),
“状态”=>$api\u offer->GetAvailableStatus($landings?array\u unique(array\u列($landings,'status')):null),
'offer_webmasters'=>$offer_webmasters,
“提供项目”=>$offer\u项目,
“提供目标”=>$offer\u目标,
];
如果($project&&!empty($project['landings'])){
$params['offer_landings']=$project['landings'];
}
返回$this->createForm(AdminOfferCreateType::class、$data、$params);
};
试一试{
如果(!$offer\u网站管理员=$api\u用户->findAll(null,10,0,['id','email','phone'])){
返回$sendCommonResponse();
}
}捕获(\异常$e){
返回$sendCommonResponse();
}
试一试{
if(!$offer\u projects=$api\u project->findAllProjectsWithLandingsAndUser(null,10,0,['id','name','status'])){
返回$sendCommonResponse();
}
}捕获(\异常$e){
返回$sendCommonResponse();
}
试一试{
if(!$offer\u goals=$api\u goal->findAllItems(null,10,0,['id','name','revshare','status'])){
返回$sendCommonResponse();
}
}捕获(\异常$e){
返回$sendCommonResponse();
}
$fast\u mode=false;
如果($request->isMethod('GET')){
$fast_mode=(0<$project_id=$request->get('project'),并且是数字($project_id));
}否则{
$project_id=null;
}
如果($project=$selectProject($project\u id)){
$data=[
'project'=>$project['id'],
];
}否则{
$data=null;
}
$form=$createForm($data,$project);
$form->handleRequest($request);
如果($form->isSubmitted()){
如果(!$request->isXmlHttpRequest()){
抛出$this->createNotFoundException();
}
如果(!$request->isMethod('POST')){
抛出$this->createHttpException(405);
}
$data=$form->getData();
$landings=[];
如果($project=$selectProject(isset($data['project'])?$data['project']:null)){
如果(!empty($data['landings]])和(!empty($project['landings]])){
$data['landings']=array_intersect($data['landings',array_列($project['landings','id'));
foreach($project['landing']作为$landing){
if(在数组中($landing['id',$data['landing'])){
$landings[$landing['id']]=$landing;
}
}
}
}
$form=$createForm($data,$project,$landings);
$form->handleRequest($request);
$data=$form->getData();
如果($form->isValid()){
如果($r)