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: * The request object.
29: *
30: * @var \Cake\Http\ServerRequest
31: */
32: protected $_request;
33:
34: /**
35: * Constructor.
36: *
37: * @param \Cake\Http\ServerRequest $request The request object.
38: * @param array $context Context info.
39: */
40: public function __construct(ServerRequest $request, array $context)
41: {
42: $this->_request = $request;
43: }
44:
45: /**
46: * {@inheritDoc}
47: */
48: public function primaryKey()
49: {
50: return [];
51: }
52:
53: /**
54: * {@inheritDoc}
55: */
56: public function isPrimaryKey($field)
57: {
58: return false;
59: }
60:
61: /**
62: * {@inheritDoc}
63: */
64: public function isCreate()
65: {
66: return true;
67: }
68:
69: /**
70: * {@inheritDoc}
71: */
72: public function val($field)
73: {
74: return $this->_request->getData($field);
75: }
76:
77: /**
78: * {@inheritDoc}
79: */
80: public function isRequired($field)
81: {
82: return false;
83: }
84:
85: /**
86: * {@inheritDoc}
87: */
88: public function getRequiredMessage($field)
89: {
90: return null;
91: }
92:
93: /**
94: * {@inheritDoc}
95: */
96: public function getMaxLength($field)
97: {
98: return null;
99: }
100:
101: /**
102: * {@inheritDoc}
103: */
104: public function fieldNames()
105: {
106: return [];
107: }
108:
109: /**
110: * {@inheritDoc}
111: */
112: public function type($field)
113: {
114: return null;
115: }
116:
117: /**
118: * {@inheritDoc}
119: */
120: public function attributes($field)
121: {
122: return [];
123: }
124:
125: /**
126: * {@inheritDoc}
127: */
128: public function hasError($field)
129: {
130: return false;
131: }
132:
133: /**
134: * {@inheritDoc}
135: */
136: public function error($field)
137: {
138: return [];
139: }
140: }
141: