FormToArgumentsConverter.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2009 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 
00012     final class FormToArgumentsConverter extends StaticFactory
00013     {
00014         public static function getShort(Form $form)
00015         {
00016             $short = null;
00017             
00018             foreach ($form->getPrimitiveList() as $primitive)
00019                 if (strlen($primitive->getName()) == 1)
00020                     $short .=
00021                         $primitive->getName()
00022                         .self::getValueType($primitive);
00023             
00024             return $short;
00025         }
00026         
00027         public static function getLong(Form $form)
00028         {
00029             $long = array();
00030             
00031             foreach ($form->getPrimitiveList() as $primitive)
00032                 if (strlen($primitive->getName()) > 1)
00033                     $long[] =
00034                         $primitive->getName()
00035                         .self::getValueType($primitive);
00036             
00037             return $long;
00038         }
00039         
00040         private static function getValueType(BasePrimitive $primitive)
00041         {
00042             if ($primitive instanceof PrimitiveNoValue)
00043                 return null;
00044             
00045             if ($primitive->isRequired())
00046                 return ':';
00047             else
00048                 return '::';
00049         }
00050     }
00051 ?>