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: ImageAltTitle.php 866 2013-08-25 16:22:35Z geert $ 30 */ 31 32 /** 33 * Implementation of the \Scrivo\ListItemProperty\ImageAltTitle class. 34 */ 35 36 namespace Scrivo\ListItemProperty; 37 38 /** 39 * Property to hold an image source (src) url. 40 * 41 * @property \Scrivo\String $src The image source (src attribute). 42 * @property \Scrivo\String $alt The alternative text for the image (alt 43 * attribute). 44 * @property \Scrivo\String $title The image title (title attribute). 45 */ 46 class ImageAltTitle extends \Scrivo\ListItemProperty { 47 48 /** 49 * The src property of the url. 50 * @var \Scrivo\String 51 */ 52 private $src; 53 54 /** 55 * The alt property of the url. 56 * @var \Scrivo\String 57 */ 58 private $alt; 59 60 /** 61 * The title property of the url. 62 * @var \Scrivo\String 63 */ 64 private $title; 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->src) { 76 $this->fromData(); 77 } 78 switch($name) { 79 case "src": return $this->src; 80 case "alt": return $this->alt; 81 case "title": return $this->title; 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 "src": $this->src = $value; $this->toData(); return; 96 case "alt": $this->alt = $value; $this->toData(); return; 97 case "title": $this->title = $value; $this->toData(); return; 98 } 99 parent::__set($name, $value); 100 } 101 102 /** 103 * Convert the property data field to the image members. 104 */ 105 private function fromData() { 106 $t = parent::__get("data")->split(new \Scrivo\String("\t")); 107 $c = count($t); 108 $this->src = $c>0 ? $t[0] : new \Scrivo\String(""); 109 $this->alt = $c>1 ? $t[1] : new \Scrivo\String(""); 110 $this->title = $c>2 ? $t[2] : new \Scrivo\String(""); 111 } 112 113 /** 114 * Convert the property data field to the image members. 115 */ 116 private function toData() { 117 $this->data = new \Scrivo\String( 118 (string)$this->src."\t". 119 (string)$this->alt."\t". 120 (string)$this->title 121 ); 122 return $this->data; 123 } 124 125 } 126 127 ?>
Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013