ExplodedPrimitive.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2007 by Sveta A. Smirnova                          *
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: ExplodedPrimitive.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class ExplodedPrimitive extends PrimitiveString
00017     {
00018         protected $separator        = ' ';
00019         protected $splitByRegexp    = false;
00020         
00024         public function setSeparator($separator)
00025         {
00026             $this->separator = $separator;
00027             
00028             return $this;
00029         }
00030         
00031         public function getSeparator()
00032         {
00033             return $this->separator;
00034         }
00035         
00036         public function setSplitByRegexp($splitByRegexp = false)
00037         {
00038             $this->splitByRegexp = ($splitByRegexp === true);
00039             
00040             return $this;
00041         }
00042         
00043         public function isSplitByRegexp()
00044         {
00045             return $this->splitByRegexp;
00046         }
00047         
00048         public function import($scope)
00049         {
00050             if (!$result = parent::import($scope))
00051                 return $result;
00052             
00053             if (
00054                 $this->value =
00055                     $this->isSplitByRegexp()
00056                         ?
00057                             preg_split(
00058                                 $this->separator,
00059                                 $this->value,
00060                                 -1,
00061                                 PREG_SPLIT_NO_EMPTY
00062                             )
00063                         : explode($this->separator, $this->value)
00064             ) {
00065                 return true;
00066             } else {
00067                 return false;
00068             }
00069             
00070             Assert::isUnreachable();
00071         }
00072     }
00073 ?>

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