Overview

Namespaces

  • intouch
    • ical

Classes

  • Duration
  • Factory
  • Freq
  • iCal
  • Line
  • Parser
  • Query
  • Recurrence
  • VCalendar
  • VEvent
  • VTimeZone
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php // BUILD: Remove line
  2: 
  3: namespace intouch\ical;
  4: 
  5: use \ArrayAccess;
  6: use \Countable;
  7: use \IteratorAggregate;
  8: 
  9: /**
 10:  * A class for storing a single (complete) line of the iCal file.
 11:  * Will find the line-type, the arguments and the data of the file and
 12:  * store them.
 13:  *
 14:  * The line-type can be found by querying getIdent(), data via either
 15:  * getData() or typecasting to a string.
 16:  * Params can be access via the ArrayAccess. A iterator is also avilable
 17:  * to iterator over the params.
 18:  *
 19:  * @author Morten Fangel (C) 2008
 20:  * @author Michael Kahn (C) 2013
 21:  * @license http://creativecommons.org/licenses/by-sa/2.5/dk/deed.en_GB CC-BY-SA-DK
 22:  */
 23: class Line implements ArrayAccess, Countable, IteratorAggregate {
 24:     protected $ident;
 25:     protected $data;
 26:     protected $params = array();
 27: 
 28:     protected $replacements = array('from'=>array('\\,', '\\n', '\\;', '\\:', '\\"'), 'to'=>array(',', "\n", ';', ':', '"'));
 29: 
 30:     /**
 31:      * Constructs a new line.
 32:      */
 33:     public function __construct( $line ) {
 34:         $split = strpos($line, ':');
 35:         $idents = explode(';', substr($line, 0, $split));
 36:         $ident = strtolower(array_shift($idents));
 37: 
 38:         $data = trim(substr($line, $split+1));
 39:         $data = str_replace($this->replacements['from'], $this->replacements['to'], $data);
 40: 
 41:         $params = array();
 42:         foreach( $idents AS $v) {
 43:             list($k, $v) = explode('=', $v);
 44:             $params[ strtolower($k) ] = $v;
 45:         }
 46: 
 47:         $this->ident = $ident;
 48:         $this->params = $params;
 49:         $this->data = $data;
 50:     }
 51: 
 52:     /**
 53:      * Is this line the begining of a new block?
 54:      * @return bool
 55:      */
 56:     public function isBegin() {
 57:         return $this->ident == 'begin';
 58:     }
 59: 
 60:     /**
 61:      * Is this line the end of a block?
 62:      * @return bool
 63:      */
 64:     public function isEnd() {
 65:         return $this->ident == 'end';
 66:     }
 67: 
 68:     /**
 69:      * Returns the line-type (ident) of the line
 70:      * @return string
 71:      */
 72:     public function getIdent() {
 73:         return $this->ident;
 74:     }
 75: 
 76:     /**
 77:      * Returns the content of the line
 78:      * @return string
 79:      */
 80:     public function getData() {
 81:         return $this->data;
 82:     }
 83: 
 84:     /**
 85:      * Returns the content of the line
 86:      * @return string
 87:      */
 88:     public function getDataAsArray() {
 89:         if (strpos($this->data,",") !== false) {
 90:             return explode(",",$this->data);
 91:         }
 92:         else
 93:             return array($this->data);
 94:     }
 95: 
 96:     /**
 97:      * A static helper to get a array of intouch\ical\Line's, and calls
 98:      * getData() on each of them to lay the data "bare"..
 99:      *
100:      * @param intouch\ical\Line[]
101:      * @return array
102:      */
103:     public static function Remove_Line($arr) {
104:         $rtn = array();
105:         foreach( $arr AS $k => $v ) {
106:             if(is_array($v)) {
107:                 $rtn[$k] = self::Remove_Line($v);
108:             } elseif( $v instanceof Line ) {
109:                 $rtn[$k] = $v->getData();
110:             } else {
111:                 $rtn[$k] = $v;
112:             }
113:         }
114:         return $rtn;
115:     }
116: 
117:     /**
118:      * @see ArrayAccess.offsetExists
119:      */
120:     public function offsetExists( $param ) {
121:         return isset($this->params[ strtolower($param) ]);
122:     }
123: 
124:     /**
125:      * @see ArrayAccess.offsetGet
126:      */
127:     public function offsetGet( $param ) {
128:         $index = strtolower($param);
129:         if (isset($this->params[ $index ])) {
130:             return $this->params[ $index ];
131:         }
132:     }
133: 
134:     /**
135:      * Disabled ArrayAccess requirement
136:      * @see ArrayAccess.offsetSet
137:      */
138:     public function offsetSet( $param, $val ) {
139:         return false;
140:     }
141: 
142:     /**
143:      * Disabled ArrayAccess requirement
144:      * @see ArrayAccess.offsetUnset
145:      */
146:     public function offsetUnset( $param ) {
147:         return false;
148:     }
149: 
150:     /**
151:      * toString method.
152:      * @see getData()
153:      */
154:     public function __toString() {
155:         return $this->getData();
156:     }
157: 
158:     /**
159:      * @see Countable.count
160:      */
161:     public function count() {
162:         return count($this->params);
163:     }
164: 
165:     /**
166:      * @see IteratorAggregate.getIterator
167:      */
168:     public function getIterator() {
169:         return new ArrayIterator($this->params);
170:     }
171: }
172: 
intouch-iCalendar API documentation generated by ApiGen 2.8.0