|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Eccube\Application; |
|
4
|
|
|
|
|
5
|
|
|
use Eccube\Event\TemplateEvent; |
|
6
|
|
|
use Monolog\Logger; |
|
7
|
|
|
use Symfony\Component\Form\FormBuilder; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
|
11
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface; |
|
12
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
13
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
14
|
|
|
|
|
15
|
|
|
trait ApplicationTrait |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
|
|
|
|
|
18
|
|
|
* Application Shortcut Methods |
|
19
|
|
|
*/ |
|
20
|
82 |
|
public function addSuccess($message, $namespace = 'front') |
|
21
|
|
|
{ |
|
22
|
82 |
|
$this['session']->getFlashBag()->add('eccube.' . $namespace . '.success', $message); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
8 |
|
public function addError($message, $namespace = 'front') |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
8 |
|
$this['session']->getFlashBag()->add('eccube.' . $namespace . '.error', $message); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function addDanger($message, $namespace = 'front') |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
$this['session']->getFlashBag()->add('eccube.' . $namespace . '.danger', $message); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
4 |
|
public function addWarning($message, $namespace = 'front') |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
4 |
|
$this['session']->getFlashBag()->add('eccube.' . $namespace . '.warning', $message); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
public function addInfo($message, $namespace = 'front') |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
1 |
|
$this['session']->getFlashBag()->add('eccube.' . $namespace . '.info', $message); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function addRequestError($message, $namespace = 'front') |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
$this['session']->getFlashBag()->set('eccube.' . $namespace . '.request.error', $message); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function clearMessage() |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
$this['session']->getFlashBag()->clear(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function deleteMessage() |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
$this->clearMessage(); |
|
58
|
|
|
$this->addWarning('admin.delete.warning', 'admin'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function setLoginTargetPath($targetPath, $namespace = null) |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
if (is_null($namespace)) { |
|
64
|
|
|
$this['session']->getFlashBag()->set('eccube.login.target.path', $targetPath); |
|
65
|
|
|
} else { |
|
66
|
|
|
$this['session']->getFlashBag()->set('eccube.' . $namespace . '.login.target.path', $targetPath); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
329 |
|
public function isAdminRequest() |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
329 |
|
return isset($this['admin']) ? $this['admin'] : null; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
327 |
|
public function isFrontRequest() |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
327 |
|
return isset($this['front']) ? $this['front'] : null; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* 他のコントローラにリクエストをフォワードします. |
|
82
|
|
|
* |
|
83
|
|
|
* @param string $path フォワード先のパス |
|
|
|
|
|
|
84
|
|
|
* @param array $requestParameters |
|
|
|
|
|
|
85
|
|
|
* @return Response |
|
86
|
|
|
*/ |
|
87
|
17 |
|
public function forward($path, array $requestParameters = []) |
|
88
|
|
|
{ |
|
89
|
17 |
|
$request = $this['request_stack']->getCurrentRequest(); |
|
90
|
|
|
|
|
91
|
17 |
|
$subRequest = Request::create( |
|
92
|
17 |
|
$path, |
|
93
|
17 |
|
$request->getMethod(), |
|
94
|
17 |
|
$requestParameters, |
|
95
|
17 |
|
$request->cookies->all(), |
|
96
|
17 |
|
[], |
|
97
|
17 |
|
$request->server->all() |
|
98
|
|
|
); |
|
99
|
17 |
|
if ($request->getSession()) { |
|
100
|
17 |
|
$subRequest->setSession($request->getSession()); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
17 |
|
return $this->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* フォワードをチェーンでつなげます. |
|
108
|
|
|
* |
|
109
|
|
|
* @param string $path フォワード先のパス |
|
|
|
|
|
|
110
|
|
|
* @param array $requestParameters |
|
|
|
|
|
|
111
|
|
|
* @param Response $response |
|
112
|
|
|
* @return Application |
|
113
|
|
|
*/ |
|
114
|
|
|
public function forwardChain($path, array $requestParameters = [], Response &$response = null) |
|
115
|
|
|
{ |
|
116
|
|
|
$response = $this->forward($path, $requestParameters); |
|
117
|
|
|
return $this; |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
|
|
|
|
|
121
|
|
|
* コンテナに登録済のサービスを上書きする. |
|
122
|
|
|
* Pimple標準では再登録を行うと, `RuntimeException: Cannot override frozen service`が投げられるため,一度unsetしてから再登録を行う. |
|
123
|
|
|
* config系の変更程度に利用はとどめること |
|
124
|
|
|
* |
|
125
|
|
|
* @param $key |
|
|
|
|
|
|
126
|
|
|
* @param $service |
|
|
|
|
|
|
127
|
|
|
* @throws \InvalidArgumentException keyが存在しない場合. |
|
128
|
|
|
*/ |
|
129
|
40 |
|
public function overwrite($key, $service) |
|
130
|
|
|
{ |
|
131
|
40 |
|
if (!$this->offsetExists($key)) { |
|
|
|
|
|
|
132
|
|
|
throw new \InvalidArgumentException(); |
|
133
|
|
|
} |
|
134
|
40 |
|
$this->offsetUnset($key); |
|
|
|
|
|
|
135
|
40 |
|
$this[$key] = $service; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|