MonolithicController.class.php

Go to the documentation of this file.
00001 <?php
00002 /****************************************************************************
00003  *   Copyright (C) 2006-2008 by Anton E. Lebedevich, Konstantin V. Arkhipov *
00004  *                                                                          *
00005  *   This program is free software; you can redistribute it and/or modify   *
00006  *   it under the terms of the GNU Lesser General Public License as         *
00007  *   published by the Free Software Foundation; either version 3 of the     *
00008  *   License, or (at your option) any later version.                        *
00009  *                                                                          *
00010  ****************************************************************************/
00011     
00015     abstract class MonolithicController extends BaseEditor
00016     {
00017         public function __construct(Prototyped $subject)
00018         {
00019             $this->commandMap['import'] = 'doImport';
00020             $this->commandMap['drop']   = 'doDrop';
00021             $this->commandMap['save']   = 'doSave';
00022             $this->commandMap['edit']   = 'doEdit';
00023             $this->commandMap['add']    = 'doAdd';
00024             
00025             parent::__construct($subject);
00026         }
00027         
00031         public function handleRequest(HttpRequest $request)
00032         {
00033             $this->map->import($request);
00034             
00035             $form = $this->getForm();
00036             
00037             if (!$command = $form->getValue('action'))
00038                 $command = $form->get('action')->getDefault();
00039             
00040             if ($command) {
00041                 $mav = $this->{$this->commandMap[$command]}(
00042                     $this->subject, $form, $request
00043                 );
00044             } else
00045                 $mav = ModelAndView::create();
00046             
00047             return $this->postHandleRequest($mav, $request);
00048         }
00049         
00053         public function doImport(
00054             Prototyped $subject, Form $form, HttpRequest $request
00055         )
00056         {
00057             return ImportCommand::create()->run($subject, $form, $request);
00058         }
00059         
00063         public function doDrop(
00064             Prototyped $subject, Form $form, HttpRequest $request
00065         )
00066         {
00067             return DropCommand::create()->run($subject, $form, $request);
00068         }
00069         
00073         public function doSave(
00074             Prototyped $subject, Form $form, HttpRequest $request
00075         )
00076         {
00077             return SaveCommand::create()->run($subject, $form, $request);
00078         }
00079         
00083         public function doEdit(
00084             Prototyped $subject, Form $form, HttpRequest $request
00085         )
00086         {
00087             return EditCommand::create()->run($subject, $form, $request);
00088         }
00089         
00093         public function doAdd(
00094             Prototyped $subject, Form $form, HttpRequest $request
00095         )
00096         {
00097             return AddCommand::create()->run($subject, $form, $request);
00098         }
00099     }
00100 ?>