PostfixUnaryExpression.class.php

Go to the documentation of this file.
00001 <?php
00002 /****************************************************************************
00003  *   Copyright (C) 2004-2007 by Konstantin V. Arkhipov, 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     final class PostfixUnaryExpression implements LogicalObject, MappableObject
00016     {
00017         const IS_NULL           = 'IS NULL';
00018         const IS_NOT_NULL       = 'IS NOT NULL';
00019 
00020         const IS_TRUE           = 'IS TRUE';
00021         const IS_FALSE          = 'IS FALSE';
00022 
00023         private $subject    = null;
00024         private $logic      = null;
00025         
00026         public function __construct($subject, $logic)
00027         {
00028             $this->subject  = $subject;
00029             $this->logic    = $logic;
00030         }
00031         
00032         public function toDialectString(Dialect $dialect)
00033         {
00034             return
00035                 '('
00036                 .$dialect->toFieldString($this->subject)
00037                 .' '.$this->logic
00038                 .')';
00039         }
00040         
00044         public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
00045         {
00046             return new self(
00047                 $dao->guessAtom($this->subject, $query),
00048                 $this->logic
00049             );
00050         }
00051         
00052         public function toBoolean(Form $form)
00053         {
00054             $subject = $form->toFormValue($this->subject);
00055                 
00056             switch ($this->logic) {
00057                 case self::IS_NULL:
00058                     return null === $subject;
00059 
00060                 case self::IS_NOT_NULL:
00061                     return null !== $subject;
00062 
00063                 case self::IS_TRUE:
00064                     return true === $subject;
00065 
00066                 case self::IS_FALSE:
00067                     return false === $subject;
00068 
00069                 default:
00070                     
00071                     throw new UnsupportedMethodException(
00072                         "'{$this->logic}' doesn't supported yet"
00073                     );
00074             }
00075         }
00076     }
00077 ?>