FixedLengthStringType.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2007 by Denis M. Gabaidulin                             *
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 /* $Id: FixedLengthStringType.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class FixedLengthStringType extends StringType
00017     {
00018         public function toSetter(
00019             MetaClass $class,
00020             MetaClassProperty $property,
00021             MetaClassProperty $holder = null
00022         )
00023         {
00024             $name = $property->getName();
00025             $methodName = 'set'.ucfirst($name);
00026             
00027             $assert = <<<EOT
00028 Assert::isTrue(
00029     (\${$name} === null)
00030     || (mb_strlen(\${$name}) == {$property->getSize()})
00031 );
00032 EOT;
00033             
00034             if ($holder) {
00035                 return <<<EOT
00036 
00040 public function {$methodName}(\${$name})
00041 {
00042     {$assert}
00043     
00044     \$this->{$holder->getName()}->{$methodName}(\${$name});
00045 
00046     return \$this;
00047 }
00048 
00049 EOT;
00050             } else {
00051                 return <<<EOT
00052 
00056 public function {$methodName}(\${$name})
00057 {
00058     {$assert}
00059     
00060     \$this->{$name} = \${$name};
00061 
00062     return \$this;
00063 }
00064 
00065 EOT;
00066             }
00067             
00068             Assert::isUnreachable();
00069         }
00070         
00071         public function toColumnType($length = null)
00072         {
00073             return 'DataType::create(DataType::CHAR)';
00074         }
00075     }
00076 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4