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 
00015     final class ExplodedPrimitive extends PrimitiveString
00016     {
00017         protected $separator        = ' ';
00018         protected $splitByRegexp    = false;
00019         
00023         public function setSeparator($separator)
00024         {
00025             $this->separator = $separator;
00026             
00027             return $this;
00028         }
00029         
00030         public function getSeparator()
00031         {
00032             return $this->separator;
00033         }
00034         
00035         public function setSplitByRegexp($splitByRegexp = false)
00036         {
00037             $this->splitByRegexp = ($splitByRegexp === true);
00038             
00039             return $this;
00040         }
00041         
00042         public function isSplitByRegexp()
00043         {
00044             return $this->splitByRegexp;
00045         }
00046         
00047         public function import($scope)
00048         {
00049             if (!$result = parent::import($scope))
00050                 return $result;
00051             
00052             if (
00053                 $this->value =
00054                     $this->isSplitByRegexp()
00055                         ?
00056                             preg_split(
00057                                 $this->separator,
00058                                 $this->value,
00059                                 -1,
00060                                 PREG_SPLIT_NO_EMPTY
00061                             )
00062                         : explode($this->separator, $this->value)
00063             ) {
00064                 return true;
00065             } else {
00066                 return false;
00067             }
00068             
00069             Assert::isUnreachable();
00070         }
00071         
00072         public function exportValue()
00073         {
00074             throw new UnimplementedFeatureException();
00075         }
00076     }
00077 ?>