1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * For full copyright and license information, please see the LICENSE.txt
8: * Redistributions of files must retain the above copyright notice.
9: *
10: * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11: * @link https://cakephp.org CakePHP(tm) Project
12: * @since 3.0.0
13: * @license https://opensource.org/licenses/mit-license.php MIT License
14: */
15: namespace Cake\View\Form;
16:
17: use Cake\Http\ServerRequest;
18:
19: /**
20: * Provides a context provider that does nothing.
21: *
22: * This context provider simply fulfils the interface requirements
23: * that FormHelper has and allows access to the request data.
24: */
25: class NullContext implements ContextInterface
26: {
27:
28: /**
29: * The request object.
30: *
31: * @var \Cake\Http\ServerRequest
32: */
33: protected $_request;
34:
35: /**
36: * Constructor.
37: *
38: * @param \Cake\Http\ServerRequest $request The request object.
39: * @param array $context Context info.
40: */
41: public function __construct(ServerRequest $request, array $context)
42: {
43: $this->_request = $request;
44: }
45:
46: /**
47: * {@inheritDoc}
48: */
49: public function primaryKey()
50: {
51: return [];
52: }
53:
54: /**
55: * {@inheritDoc}
56: */
57: public function isPrimaryKey($field)
58: {
59: return false;
60: }
61:
62: /**
63: * {@inheritDoc}
64: */
65: public function isCreate()
66: {
67: return true;
68: }
69:
70: /**
71: * {@inheritDoc}
72: */
73: public function val($field)
74: {
75: return $this->_request->getData($field);
76: }
77:
78: /**
79: * {@inheritDoc}
80: */
81: public function isRequired($field)
82: {
83: return false;
84: }
85:
86: /**
87: * {@inheritDoc}
88: */
89: public function getRequiredMessage($field)
90: {
91: return null;
92: }
93:
94: /**
95: * {@inheritDoc}
96: */
97: public function getMaxLength($field)
98: {
99: return null;
100: }
101:
102: /**
103: * {@inheritDoc}
104: */
105: public function fieldNames()
106: {
107: return [];
108: }
109:
110: /**
111: * {@inheritDoc}
112: */
113: public function type($field)
114: {
115: return null;
116: }
117:
118: /**
119: * {@inheritDoc}
120: */
121: public function attributes($field)
122: {
123: return [];
124: }
125:
126: /**
127: * {@inheritDoc}
128: */
129: public function hasError($field)
130: {
131: return false;
132: }
133:
134: /**
135: * {@inheritDoc}
136: */
137: public function error($field)
138: {
139: return [];
140: }
141: }
142: