Changeset 1787

Show
Ignore:
Timestamp:
08/27/08 14:27:24 (4 months ago)
Author:
mikey
Message:

add net::stubbles::peer::stubURLContainer

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework/trunk/src/main/php/net/stubbles/peer/http/stubHTTPURL.php

    r1763 r1787  
    11<?php 
    22/** 
    3  * Class for URLs of hypertext transfer protocol. 
     3 * Class for URLs of scheme hypertext transfer protocol. 
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
     
    77 * @subpackage  peer_http 
    88 */ 
    9 stubClassLoader::load('net::stubbles::lang::exceptions::stubIllegalArgumentException', 
    10                       'net::stubbles::peer::stubURL' 
    11 ); 
     9stubClassLoader::load('net::stubbles::peer::stubURL'); 
    1210/** 
    13  * Class for URLs of hypertext transfer protocol. 
     11 * Class for URLs of scheme hypertext transfer protocol. 
    1412 * 
    1513 * @package     stubbles 
     
    7371         
    7472        return true; 
    75     } 
    76  
    77     /** 
    78      * add a parameter to the url 
    79      * 
    80      * @param   string  $key    name of parameter 
    81      * @param   mixed   $value  value of parameter 
    82      * @throws  stubIllegalArgumentException 
    83      */ 
    84     public function addParam($key, $value) 
    85     { 
    86         if (is_string($key) == false) { 
    87             throw new stubIllegalArgumentException('Argument 1 passed to ' . __METHOD__ . '() must be an instance of string.'); 
    88         } 
    89          
    90         if (null !== $value && is_array($value) == false && is_scalar($value) == false) { 
    91             throw new stubIllegalArgumentException('Argument 2 passed to ' . __METHOD__ . '() must be an instance of string, array or any other scalar value or null.'); 
    92         } 
    93          
    94         if (null === $value and isset($this->params[$key]) == true) { 
    95             unset($this->params[$key]); 
    96         } elseif (null !== $value) { 
    97             if (false === $value) { 
    98                 $value = 0; 
    99             } elseif (true === $value) { 
    100                 $value = 1; 
    101             } 
    102              
    103             $this->params[$key] = $value; 
    104         } 
    10573    } 
    10674 
  • framework/trunk/src/main/php/net/stubbles/peer/stubURL.php

    r1763 r1787  
    77 * @subpackage  peer_net 
    88 */ 
    9 stubClassLoader::load('net::stubbles::peer::stubMalformedURLException'); 
     9stubClassLoader::load('net::stubbles::lang::exceptions::stubIllegalArgumentException', 
     10                      'net::stubbles::peer::stubMalformedURLException', 
     11                      'net::stubbles::peer::stubURLContainer' 
     12); 
    1013/** 
    1114 * Class for URLs and methods on URLs. 
     
    1417 * @subpackage  peer_net 
    1518 */ 
    16 class stubURL extends stubBaseObject 
     19class stubURL extends stubBaseObject implements stubURLContainer 
    1720{ 
    1821    /** 
     
    252255 
    253256    /** 
     257     * sets the port 
     258     * 
     259     * @param  int  $port 
     260     */ 
     261    public function setPort($port) 
     262    { 
     263        $this->url['port'] = $port; 
     264    } 
     265 
     266    /** 
    254267     * returns port of the url 
    255268     * 
     
    267280 
    268281    /** 
    269      * sets the port 
    270      * 
    271      * @param  int  $port 
    272      */ 
    273     public function setPort($port) 
    274     { 
    275         $this->url['port'] = $port; 
    276     } 
    277  
    278     /** 
    279282     * returns path of the url 
    280283     * 
     
    302305    { 
    303306        return (isset($this->url['query']) === true && strlen($this->url['query']) > 0); 
     307    } 
     308 
     309    /** 
     310     * add a parameter to the url 
     311     * 
     312     * @param   string  $key    name of parameter 
     313     * @param   mixed   $value  value of parameter 
     314     * @throws  stubIllegalArgumentException 
     315     */ 
     316    public function addParam($key, $value) 
     317    { 
     318        if (is_string($key) == false) { 
     319            throw new stubIllegalArgumentException('Argument 1 passed to ' . __METHOD__ . '() must be an instance of string.'); 
     320        } 
     321         
     322        if (null !== $value && is_array($value) == false && is_scalar($value) == false) { 
     323            throw new stubIllegalArgumentException('Argument 2 passed to ' . __METHOD__ . '() must be an instance of string, array or any other scalar value or null.'); 
     324        } 
     325         
     326        if (null === $value and isset($this->params[$key]) == true) { 
     327            unset($this->params[$key]); 
     328        } elseif (null !== $value) { 
     329            if (false === $value) { 
     330                $value = 0; 
     331            } elseif (true === $value) { 
     332                $value = 1; 
     333            } 
     334             
     335            $this->params[$key] = $value; 
     336        } 
    304337    } 
    305338