pluf2

pluf2 Commit Details


Date:2009-04-06 07:53:17 (15 years 8 months ago)
Author:Loic d'Anterroches
Branch:master
Commit:9f2a573297da70a7ec7e3ab72a8605f9d90196be
Parents: a7df883a9b6b4e4bd529e6f8c03a811045d1996c
Message:Removed unnecessary code.

Changes:

File differences

src/Pluf/Dispatcher.php
206206
207207
208208
209
210209
211210
212
211
213212
214213
215
216
217
218
219
214
220215
221216
222217
223218
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303219
304220
* Load the controllers.
*
* @param string File including the views.
* @param string Possible prefix to add to the views.
* @return bool Success.
*/
public static function loadControllers($file, $prefix='')
public static function loadControllers($file)
{
if (file_exists($file)) {
if ($prefix == '') {
$GLOBALS['_PX_views'] = include $file;
} else {
$GLOBALS['_PX_views'] = Pluf_Dispatcher::addPrefixToViewFile($prefix, $file);
}
$GLOBALS['_PX_views'] = include $file;
return true;
}
return false;
}
/**
* Register an action controller.
*
* - The class must provide a "standalone" action method
* class::actionmethod($request, $match)
* - The priority is to order the controller matches.
* 5: Default, if the controller provides some content
* 1: If the controller provides a control before, without providing
* content, note that in this case the return code must be a redirection.
* 8: If the controller is providing a catch all case to replace the
* default 404 error page.
*
* @param string Class name providing the action controller
* @param string The method of the plugin to be called
* @param string Regex to match on the query string
* @param int Priority (5)
* @return void
*/
public static function registerController($model, $method, $regex, $priority=5)
{
if (!isset($GLOBALS['_PX_views'])) {
$GLOBALS['_PX_views'] = array();
}
$GLOBALS['_PX_views'][] = array('model' => $model,
'regex' => $regex,
'priority' => $priority,
'method' => $method);
}
/**
* Add the controllers of an application with a given prefix.
*
* Suppose you have a new app you want to use within another
* existing application, you may need to change the base URL not
* to conflict with the existing one. For example you want to have
* domain.com/forum-a/ and domain.com/forum-b/ to use 2 forums at
* the same time.
*
* This method do that, it takes a typical "view" file and rewrite
* the regex to append the prefix. Note that you should use the
* 'url' tag in the template and use Pluf_HTTP_URL_reverse in the
* views to not hardcode the urls or this will not work.
*
* @param string Prefix, for example '/alternate'.
* @param string File with the views.
* @return array Prefixed views.
*/
static public function addPrefixToViewFile($prefix, $file)
{
if (file_exists($file)) {
$views = include $file;
} else {
throw new Exception('View file not found: '.$file);
}
return Pluf_Dispatcher::addPrefixToViews($prefix, $views);
}
/**
* Add a prefix to an array of views.
*
* You can use it for example to not hardcode that in your CMS the
* blog is located as /blog but is configured in the configuration
* of the CMS, that way in French this could be /carnet.
*
* @param string Prefix, for example '/alternate'.
* @param array Array of the views.
* @return array Prefixed views.
*/
static public function addPrefixToViews($prefix, $views)
{
$res = array();
foreach ($views as $view) {
$view['regex'] = '#^'.$prefix.substr($view['regex'], 2);
$res[] = $view;
}
return $res;
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.05664s using 13 queries.