.

RedirectRenderDecorator Class Reference
[Controller]

Redirect to given target path (not Url!). More...

Inheritance diagram for RedirectRenderDecorator:
RenderDecoratorBase IRenderDecorator

List of all members.

Public Member Functions

  __construct ($target_path)
  Constructor.
  initialize ($page_data)
  Initialize this decorator and the data passed.

Protected Member Functions

  build_redirect_url ($target_path, $source_path)
  Change URL to point ot new location.

Detailed Description

Redirect to given target path (not Url!).

This class understands backreferences {$0}, {$1}, {$2} etc. which are segments of the orginal path

$0 references the full source path, while $1 to $n reference to nth element of the source path

Example: Given URL /old/url/with/name should be redirected to /new/url/name.

This can be achieved by defining a RedirectRenderDecorator with target path

/new/url/{$4}

{$4} because name is the 4th elements of the original path. First would be "old", second "url" and so on.

Author:
Gerd Riesselmann

Definition at line 21 of file redirectrenderdecorator.cls.php.


Constructor & Destructor Documentation

RedirectRenderDecorator::__construct ( target_path  ) 

Constructor.

Parameters:
ICacheManager  $cache_manager Desired Cache Manager
Returns:
void

Definition at line 35 of file redirectrenderdecorator.cls.php.

00035                                                   {
00036                 $this->target_path = $target_path;
00037         }

Member Function Documentation

RedirectRenderDecorator::build_redirect_url ( target_path,
source_path  
) [protected]

Change URL to point ot new location.

Definition at line 61 of file redirectrenderdecorator.cls.php.

00061                                                                           {
00062                 // Replace back references
00063                 // $0
00064                 $target_path = str_replace('{$0}', $source_path, $target_path);
00065                 // $1 to $n
00066                 $i = 1;
00067                 $path_stack = new PathStack($source_path);
00068                 while($elem = $path_stack->shift()) {
00069                         $target_path = str_replace('{$' . $i . '}', $elem, $target_path);       
00070                         $i++;
00071                 }
00072                 // remove not referenced back reference
00073                 $target_path = preg_replace('|\{\$\d\}|', '', $target_path);
00074                 return $target_path;
00075         }
RedirectRenderDecorator::initialize ( page_data  ) 

Initialize this decorator and the data passed.

Parameters:
PageData  $page_data
Returns:
void

Reimplemented from RenderDecoratorBase.

Definition at line 45 of file redirectrenderdecorator.cls.php.

00045                                                {
00046                 $target = $this->target_path;
00047                 $source_path = Url::current()->get_path();
00048                 $full_target = $this->build_redirect_url($target, $source_path);
00049                                 
00050                 $url = Url::create($full_target);
00051                 if (!$url->is_valid()) {
00052                         $url = Url::current()->clear_query()->set_path($full_target);
00053                 }
00054                 $url->redirect(Url::PERMANENT);
00055                 exit;
00056         }

The documentation for this class was generated from the following file: