1: <?php
2:
3: namespace Racoon\Api;
4:
5:
6: use Racoon\Api\Schema\Schema;
7:
8: abstract class Controller
9: {
10:
11: /**
12: * @var Request
13: */
14: protected $request;
15:
16:
17: /**
18: * @return Request
19: */
20: public function getRequest()
21: {
22: return $this->request;
23: }
24:
25:
26: /**
27: * @param Request $request
28: */
29: public function setRequest($request)
30: {
31: $this->request = $request;
32: }
33:
34:
35: /**
36: * @param Schema $schema
37: */
38: public function setSchema(Schema $schema)
39: {
40: $this->getRequest()->setSchema($schema);
41: }
42:
43:
44: /**
45: * @param Schema|null $schema
46: * @param bool $setSchema
47: * @throws Exception\InvalidArgumentException
48: */
49: public function validateSchema(Schema $schema = null, $setSchema = true)
50: {
51: if ($schema === null) {
52: $schema = $this->getRequest()->getSchema();
53: }
54:
55: if (is_object($schema)) {
56: if ($setSchema) {
57: $this->setSchema($schema);
58: }
59: $schema->validate($this->getRequest()->getRequestData());
60: }
61: }
62:
63: }