1: <?php
2:
3: namespace PHPixie\Framework;
4:
5: use PHPixie\Route\Translator;
6: use PHPixie\Slice\Data;
7:
8: /**
9: * Processors factory
10: */
11: class Processors
12: {
13: /**
14: * @type Builder
15: */
16: protected $builder;
17:
18: /**
19: * Constructor
20: * @param Builder $builder
21: */
22: public function __construct($builder)
23: {
24: $this->builder = $builder;
25: }
26:
27: /**
28: * Processor that parses the url route
29: * @param Translator $routeTranslator
30: * @return Processors\HTTP\ParseRoute
31: */
32: public function httpParseRoute($routeTranslator)
33: {
34: return new Processors\HTTP\ParseRoute(
35: $routeTranslator
36: );
37: }
38:
39: /**
40: * Processor that renders the exception response
41: * @param Data $configData
42: * @return Processors\HTTP\Response\Exception
43: */
44: public function httpExceptionResponse($configData)
45: {
46: $components = $this->builder->components();
47:
48: return new Processors\HTTP\Response\Exception(
49: $components->debug(),
50: $components->http(),
51: $components->template(),
52: $configData
53: );
54: }
55:
56: /**
57: * Processor for the "not found" page
58: * @param Data $configData
59: * @return Processors\HTTP\Response\NotFound
60: */
61: public function httpNotFoundResponse($configData)
62: {
63: $components = $this->builder->components();
64:
65: return new Processors\HTTP\Response\NotFound(
66: $components->http(),
67: $components->template(),
68: $configData
69: );
70: }
71:
72: /**
73: * Processor that turns return values into HTTP Responses.
74: *
75: * E.g. objects are turned into JSON responses
76: * and template containers are rendered automatically
77: * @return Processors\HTTP\Response\Normalize
78: */
79: public function httpNormalizeResponse()
80: {
81: $components = $this->builder->components();
82:
83: return new Processors\HTTP\Response\Normalize(
84: $components->http()
85: );
86: }
87: }