1 <?php 2 /* Copyright (c) 2012, Geert Bergman (geert@scrivo.nl) 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. Neither the name of "Scrivo" nor the names of its contributors may be 14 * used to endorse or promote products derived from this software without 15 * specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 * 29 * $Id: Url.php 866 2013-08-25 16:22:35Z geert $ 30 */ 31 32 /** 33 * Implementation of the \Scrivo\PageProperty\Url class. 34 */ 35 36 namespace Scrivo\PageProperty; 37 38 /** 39 * Property to hold html link data. 40 * 41 * @property \Scrivo\String $href The link url (href attribute). 42 * @property \Scrivo\String $title A descriptive tilte for the link (title 43 * attribute). 44 * @property \Scrivo\String $target A link target (target attribute). 45 */ 46 class Url extends \Scrivo\PageProperty { 47 48 /** 49 * The href property of the url. 50 * @var \Scrivo\String 51 */ 52 private $href; 53 54 /** 55 * The title property of the url. 56 * @var \Scrivo\String 57 */ 58 private $title; 59 60 /** 61 * The target property of the url. 62 * @var \Scrivo\String 63 */ 64 private $target; 65 66 /** 67 * Implementation of the readable properties using the PHP magic 68 * method __get(). 69 * 70 * @param string $name The name of the property to get. 71 * 72 * @return mixed The value of the requested property. 73 */ 74 public function __get($name) { 75 if (!$this->href) { 76 $this->fromData(); 77 } 78 switch($name) { 79 case "href": return $this->href; 80 case "title": return $this->title; 81 case "target": return $this->target; 82 } 83 return parent::__get($name); 84 } 85 86 /** 87 * Implementation of the writable properties using the PHP magic 88 * method __set(). 89 * 90 * @param string $name The name of the property to set. 91 * @param mixed $value The value of the property to set. 92 */ 93 public function __set($name, $value) { 94 switch($name) { 95 case "href": $this->href = $value; $this->toData(); return; 96 case "title": $this->title = $value; $this->toData(); return; 97 case "target": $this->target = $value; $this->toData(); return; 98 } 99 parent::__set($name, $value); 100 } 101 102 /** 103 * Convert the property data field to the link members. 104 */ 105 protected function fromData() { 106 $t = parent::__get("data")->split(new \Scrivo\String("\t")); 107 $c = count($t); 108 $this->href = $c>0 ? $t[0] : new \Scrivo\String(""); 109 $this->title = $c>1 ? $t[1] : new \Scrivo\String(""); 110 $this->target = $c>2 ? $t[2] : new \Scrivo\String(""); 111 } 112 113 /** 114 * Convert the property data field to the link members. 115 */ 116 private function toData() { 117 $this->data = new \Scrivo\String( 118 (string)$this->href."\t". 119 (string)$this->title."\t". 120 (string)$this->target 121 ); 122 } 123 124 } 125 126 ?>
Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013