PrimitiveHttpUrl.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2007 by Ivan Y. Khvostishkov                            *
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 PrimitiveHttpUrl extends PrimitiveString
00016     {
00017         public function import($scope)
00018         {
00019             if (!$result = parent::import($scope))
00020                 return $result;
00021             
00022             try {
00023                 $this->value = HttpUrl::create()->parse($this->value);
00024             } catch (WrongArgumentException $e) {
00025                 $this->value = null;
00026                 
00027                 return false;
00028             }
00029             
00030             if (!$this->value->isValid()) {
00031                 $this->value = null;
00032                 return false;
00033             }
00034             
00035             $this->value->normalize();
00036             
00037             return true;
00038         }
00039         
00040         public function importValue($value)
00041         {
00042             if ($value instanceof HttpUrl) {
00043                 
00044                 return
00045                     $this->import(
00046                         array($this->getName() => $value->toString())
00047                     );
00048             }
00049             
00050             return parent::importValue(null);
00051         }
00052         
00053         public function exportValue()
00054         {
00055             if (!$this->value)
00056                 return null;
00057             
00058             return $this->value->toString();
00059         }
00060     }
00061 ?>