Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

mvc_configuration.php
Go to the documentation of this file.
1 <?php
11 class ezpMvcConfiguration implements ezcMvcDispatcherConfiguration
12 {
13 const FILTER_TYPE_PREROUTING = 'PreRouting';
14 const FILTER_TYPE_REQUEST = 'Request';
15 const FILTER_TYPE_RESULT = 'Result';
16 const FILTER_TYPE_RESPONSE = 'Response';
17
18 const INDEX_FILE = 'index_rest.php';
19
23 public $apiPrefix;
24
25 private $responseWriterClass;
26
27 public function __construct( $responseWriterClass = null )
28 {
29 $this->apiPrefix = eZINI::instance( 'rest.ini' )->variable( 'System', 'ApiPrefix' );
30 $this->responseWriterClass = $responseWriterClass;
31 }
32
33 public function createFatalRedirectRequest( ezcMvcRequest $request, ezcMvcResult $result, Exception $e )
34 {
35 $req = clone $request;
36 $req->uri = $this->apiPrefix . '/fatal';
37 $req->variables['exception'] = $e;
38 $req->protocol = 'http-get';
39 return $req;
40 }
41
42 public function createRequestParser()
43 {
44 $parser = new ezpRestHttpRequestParser();
45 if ( strpos( $_SERVER['SCRIPT_NAME'], self::INDEX_FILE ) !== false ) // Non-vhost mode
46 {
47 // In non-vhost mode we need to build the prefix to be removed from URI
48 $parser->prefix = eZSys::indexDir(true);
49 }
50
51 return $parser;
52 }
53
54 public function createResponseWriter( ezcMvcRoutingInformation $routeInfo, ezcMvcRequest $request, ezcMvcResult $result, ezcMvcResponse $response )
55 {
56 $class = isset( $this->responseWriterClass ) ? $this->responseWriterClass : 'ezpRestHttpResponseWriter';
57 return new $class( $response );
58 }
59
60 public function createRouter( ezcMvcRequest $request )
61 {
62 return new ezpRestRouter( $request );
63 }
64
65 public function createView( ezcMvcRoutingInformation $routeInfo, ezcMvcRequest $request, ezcMvcResult $result )
66 {
67 $viewController = ezpRestProvider::getProvider( ezpRestPrefixFilterInterface::getApiProviderName() )->getViewController();
68 $view = $viewController->loadView( $routeInfo, $request, $result );
69
70 return $view;
71 }
72
73 public function runPreRoutingFilters( ezcMvcRequest $request )
74 {
75 $prefixFilterOptions = new ezpExtensionOptions();
76 $prefixFilterOptions->iniFile = 'rest.ini';
77 $prefixFilterOptions->iniSection = 'System';
78 $prefixFilterOptions->iniVariable = 'PrefixFilterClass';
79 $prefixFilterOptions->handlerParams = array( $request, $this->apiPrefix );
80
81 $prefixFilter = eZExtension::getHandlerClass( $prefixFilterOptions );
82 $prefixFilter->filter();
83 // We call this method here, so that implementors won't have to remember
84 // adding this call to their own filter() implementation.
85 $prefixFilter->filterRequestUri();
86
87 try
88 {
89 $this->runCustomFilters( self::FILTER_TYPE_PREROUTING, array( 'request' => $request ) );
90 }
91 catch ( Exception $e )
92 {
93 $request->variables['exception'] = $e;
94 $request->uri = $this->apiPrefix . '/fatal';
95 return new ezcMvcInternalRedirect( $request );
96 }
97 }
98
99 public function runRequestFilters( ezcMvcRoutingInformation $routeInfo, ezcMvcRequest $request )
100 {
101 // We need to catch exceptions here, as exceptions thrown in the RequestFilter
102 // is not caught by MvcTools, so the error controller will not pick them up.
103 try
104 {
105 $this->runCustomFilters( self::FILTER_TYPE_REQUEST, array( 'routeInfo' => $routeInfo, 'request' => $request ) );
106 $authConfig = new ezpRestAuthConfiguration( $routeInfo, $request );
107 // For now this return is needed in order to pass redirect requests to the dispatcher
108 return $authConfig->filter();
109 }
110 catch ( Exception $e )
111 {
112 $request->variables['exception'] = $e;
113 $request->uri = $this->apiPrefix . '/fatal';
114 return new ezcMvcInternalRedirect( $request );
115 }
116 }
117
118 public function runResponseFilters( ezcMvcRoutingInformation $routeInfo, ezcMvcRequest $request, ezcMvcResult $result, ezcMvcResponse $response )
119 {
120 $response->generator = "Exponential";
121 $params = array( 'routeInfo' => $routeInfo, 'request' => $request,
122 'result' => $result, 'response' => $response );
123 try
124 {
125 $this->runCustomFilters( self::FILTER_TYPE_RESPONSE, $params );
126 } catch ( Exception $e )
127 {
128 $request->variables['exception'] = $e;
129 $request->uri = $this->apiPrefix . '/fatal';
130 return new ezcMvcInternalRedirect( $request );
131 }
132 }
133
134 public function runResultFilters( ezcMvcRoutingInformation $routeInfo, ezcMvcRequest $request, ezcMvcResult $result )
135 {
136 $params = array( 'routeInfo' => $routeInfo, 'request' => $request,
137 'result' => $result );
138 try
139 {
140 $this->runCustomFilters( self::FILTER_TYPE_RESULT, $params );
141 } catch ( Exception $e )
142 {
143 $request->variables['exception'] = $e;
144 $request->uri = $this->apiPrefix . '/fatal';
145 return new ezcMvcInternalRedirect( $request );
146 }
147 }
148
149 protected function runCustomFilters( $type, array $filterParams )
150 {
151 $filterName = $type . 'Filters';
152 $interfaceName = 'ezpRest' . $type . 'FilterInterface';
153 $definedCustomFilters = eZINI::instance( 'rest.ini' )->variable( $filterName , 'Filters' );
154
155 if ( empty( $definedCustomFilters ) )
156 return;
157
158 foreach ( $definedCustomFilters as $filter )
159 {
160 switch( $interfaceName )
161 {
162 case 'ezpRestPreRoutingFilterInterface':
163 $filterObject = new $filter( $filterParams['request'] );
164 break;
165
166 case 'ezpRestRequestFilterInterface':
167 $filterObject = new $filter( $filterParams['routeInfo'], $filterParams['request'] );
168 break;
169
170 case 'ezpRestResultFilterInterface':
171 $filterObject = new $filter( $filterParams['routeInfo'], $filterParams['request'], $filterParams['result'] );
172 break;
173
174 case 'ezpRestResponseFilterInterface':
175 $filterObject = new $filter( $filterParams['routeInfo'], $filterParams['request'], $filterParams['result'], $filterParams['response'] );
176 break;
177 }
178
179 if ( ! $filterObject instanceof $interfaceName )
180 throw new ezpRestFilterNotFoundException( $filter );
181
182 $filterObject->filter();
183 }
184 }
185
186 protected function handleFilterException( $request, Exception $e )
187 {
188 $request->variables['exception'] = $e;
189 $request->uri = $this->apiPrefix . '/fatal';
190 return new ezcMvcInternalRedirect( $request );
191 }
192 }
193 ?>
eZExtension\getHandlerClass
static getHandlerClass(ezpExtensionOptions $options)
Definition: ezextension.php:480
eZSys\indexDir
static indexDir( $withAccessList=true)
Definition: ezsys.php:594
$type
$type
Definition: classes/admin/linkselect.php:220
ezpExtensionOptions
Definition: ezpextensionoptions.php:59
ezpMvcConfiguration
Definition: mvc_configuration.php:12
ezpMvcConfiguration\handleFilterException
handleFilterException( $request, Exception $e)
Definition: mvc_configuration.php:186
ezpMvcConfiguration\runPreRoutingFilters
runPreRoutingFilters(ezcMvcRequest $request)
Definition: mvc_configuration.php:73
ezpMvcConfiguration\FILTER_TYPE_PREROUTING
const FILTER_TYPE_PREROUTING
Definition: mvc_configuration.php:13
ezpMvcConfiguration\createRequestParser
createRequestParser()
Definition: mvc_configuration.php:42
ezpMvcConfiguration\createRouter
createRouter(ezcMvcRequest $request)
Definition: mvc_configuration.php:60
ezpMvcConfiguration\createFatalRedirectRequest
createFatalRedirectRequest(ezcMvcRequest $request, ezcMvcResult $result, Exception $e)
Definition: mvc_configuration.php:33
ezpMvcConfiguration\createView
createView(ezcMvcRoutingInformation $routeInfo, ezcMvcRequest $request, ezcMvcResult $result)
Definition: mvc_configuration.php:65
ezpMvcConfiguration\$responseWriterClass
$responseWriterClass
Definition: mvc_configuration.php:25
ezpMvcConfiguration\INDEX_FILE
const INDEX_FILE
Definition: mvc_configuration.php:18
ezpMvcConfiguration\runCustomFilters
runCustomFilters( $type, array $filterParams)
Definition: mvc_configuration.php:149
ezpMvcConfiguration\FILTER_TYPE_REQUEST
const FILTER_TYPE_REQUEST
Definition: mvc_configuration.php:14
ezpMvcConfiguration\FILTER_TYPE_RESULT
const FILTER_TYPE_RESULT
Definition: mvc_configuration.php:15
ezpMvcConfiguration\__construct
__construct( $responseWriterClass=null)
Definition: mvc_configuration.php:27
ezpMvcConfiguration\$apiPrefix
$apiPrefix
Definition: mvc_configuration.php:23
ezpMvcConfiguration\runResponseFilters
runResponseFilters(ezcMvcRoutingInformation $routeInfo, ezcMvcRequest $request, ezcMvcResult $result, ezcMvcResponse $response)
Definition: mvc_configuration.php:118
ezpMvcConfiguration\runResultFilters
runResultFilters(ezcMvcRoutingInformation $routeInfo, ezcMvcRequest $request, ezcMvcResult $result)
Definition: mvc_configuration.php:134
ezpMvcConfiguration\runRequestFilters
runRequestFilters(ezcMvcRoutingInformation $routeInfo, ezcMvcRequest $request)
Definition: mvc_configuration.php:99
ezpMvcConfiguration\createResponseWriter
createResponseWriter(ezcMvcRoutingInformation $routeInfo, ezcMvcRequest $request, ezcMvcResult $result, ezcMvcResponse $response)
Definition: mvc_configuration.php:54
ezpMvcConfiguration\FILTER_TYPE_RESPONSE
const FILTER_TYPE_RESPONSE
Definition: mvc_configuration.php:16
ezpRestAuthConfiguration
Definition: auth_configuration.php:20
ezpRestFilterNotFoundException
Definition: filter_not_found.php:13
ezpRestHttpRequestParser
Definition: http_parser.php:20
ezpRestPrefixFilterInterface\getApiProviderName
static getApiProviderName()
Definition: prefix_filter.php:98
ezpRestProvider\getProvider
static getProvider( $provider)
Definition: rest_provider.php:47
ezpRestRouter
Definition: router.php:12
$result
$result
Definition: companysearch.php:94
$response
while(!feof($socket)) $response
Definition: paypalnotify.php:196
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.