# ModelAndView.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2006-2007 by Anton E. Lebedevich                        *
    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     class ModelAndView
    00016     {
    00017         private $model  = null;
    00018
    00019         private $view   = null;
    00020
    00024         public static function create()
    00025         {
    00026             return new self;
    00027         }
    00028
    00029         public function __construct()
    00030         {
    00031             $this->model = new Model();
    00032         }
    00033
    00037         public function getModel()
    00038         {
    00039             return $this->model;
    00040         }
    00041
    00045         public function setModel(Model $model)
    00046         {
    00047             $this->model = $model;
    00048
    00049             return $this;
    00050         }
    00051
    00052         public function getView()
    00053         {
    00054             return $this->view;
    00055         }
    00056
    00060         public function setView($view)
    00061         {
    00062             Assert::isTrue(
    00063                 ($view instanceof View) || is_string($view),
    00064                 'do not know, what to do with such view'
    00065             );
    00066
    00067             $this->view = $view;
    00068
    00069             return $this;
    00070         }
    00071
    00072         public function viewIsRedirect()
    00073         {
    00074             return
    00075                 ($this->view instanceof CleanRedirectView)
    00076                 || (
    00077                     is_string($this->view)
    00078                     && strpos($this->view, 'redirect') === 0
    00079                 );
    00080         }
    00081
    00082         public function viewIsNormal()
    00083         {
    00084             return (
    00085                 !$this->viewIsRedirect()
    00086                 && $this->view !== View::ERROR_VIEW
    00087             );
    00088         }
    00089     }
    00090 ?>