/Document/src/document/xml/odt/formatting/properties.php

https://github.com/F5/zetacomponents · PHP · 238 lines · 69 code · 22 blank · 147 comment · 3 complexity · a22e5b37c76849db3cfbc1616720a677 MD5 · raw file

  1. <?php
  2. /**
  3. * File containing the ezcDocumentOdtFormattingProperties class.
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package Document
  23. * @version //autogen//
  24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25. */
  26. /**
  27. * Class for representing formatting properties of a certain type.
  28. *
  29. * An instance of this class represents formatting properties of a certain type
  30. * (indicated by a PROPERTIES_* constant). The formatting properties set inside
  31. * such an object must obay to the ODF specification.
  32. *
  33. * @property-read string $type The type of the formatting properties. Set in
  34. * the constructor
  35. *
  36. * @package Document
  37. * @version //autogen//
  38. * @access private
  39. */
  40. class ezcDocumentOdtFormattingProperties extends ArrayObject
  41. {
  42. /**
  43. * May be contained only in <style:page-layout>.
  44. */
  45. const PROPERTIES_PAGE_LAYOUT = 'page-layout-properties';
  46. /**
  47. * May be contained in <style:header-style> and <style:footer-style>, which
  48. * are sub-elements of <style:page-layout>.
  49. */
  50. const PROPERTIES_HEADER_FOOTER = 'header-footer-properties';
  51. /**
  52. * May be contained in <style:style> for families "text", "paragraph" and
  53. * "cell", but might also occur in arbitrary style families (specs not
  54. * clear).
  55. */
  56. const PROPERTIES_TEXT = 'text-properties';
  57. /**
  58. * May be contained in <style:style> for families "paragraph" and "cell",
  59. * but might also occur in arbitrary style families (specs not clear).
  60. */
  61. const PROPERTIES_PARAGRAPH = 'paragraph-properties';
  62. /**
  63. * May be contained in <style:style> for the family "ruby".
  64. */
  65. const PROPERTIES_RUBY_TEXT = 'ruby-properties';
  66. /**
  67. * May be contained in <style:style> for the family "section".
  68. */
  69. const PROPERTIES_SECTION = 'section-properties';
  70. /**
  71. * May be contained in <style:style> for the family "table".
  72. */
  73. const PROPERTIES_TABLE = 'table-properties';
  74. /**
  75. * May be contained in <style:style> for the family "table-column".
  76. */
  77. const PROPERTIES_COLUMN = 'table-column-properties';
  78. /**
  79. * May be contained in <style:style> for the family "table-row".
  80. */
  81. const PROPERTIES_TABLE_ROW = 'table-row-properties';
  82. /**
  83. * May be contained in <style:style> for the family "table-cell".
  84. */
  85. const PROPERTIES_TABLE_CELL = 'table-cell-properties';
  86. /**
  87. * May be contained in <text:list-style> and others inside
  88. * <text:list-level-style-*> elements, no matter which kind.
  89. */
  90. const PROPERTIES_LIST_LEVEL = 'list-level-properties';
  91. /**
  92. * May be contained in <style:style> for the families "graphic" and "presentation".
  93. *
  94. * Note: Most graphic properties are only used to define inline graphics,
  95. * created directly in the office document (e.g. presentations) and
  96. * therefore not supported. Supported are, e.g., graphic properties that
  97. * apply to a frame.
  98. */
  99. const PROPERTIES_GRAPHIC = 'graphic-properties';
  100. /**
  101. * May be contained in <style:style> for the family "chart".
  102. *
  103. * Note: These properties are not supported!
  104. */
  105. const PROPERTIES_CHART = 'chart-properties';
  106. /**
  107. * Properties.
  108. *
  109. * @var array(string=>mixed)
  110. */
  111. protected $properties = array();
  112. /**
  113. * Creates a new property object of $type.
  114. *
  115. * $type must be one of the FAMILY_* constants.
  116. *
  117. * @param const $type
  118. */
  119. public function __construct( $type )
  120. {
  121. $this->properties['type'] = $type;
  122. parent::__construct( array(), ArrayObject::STD_PROP_LIST );
  123. }
  124. /**
  125. * Appending a new value is not allowed.
  126. *
  127. * Only {@link offsetSet()} is allowed, using a valid property type.
  128. *
  129. * @param mixed $value
  130. * @return void
  131. */
  132. public function append( $value )
  133. {
  134. throw new RuntimeException(
  135. 'Cannot append values to this object. Must provide a property type as the key.'
  136. );
  137. }
  138. /**
  139. * Exchanging the array is not allowed.
  140. *
  141. * @param array $array
  142. * @return void
  143. */
  144. public function exchangeArray( $array )
  145. {
  146. throw new RuntimeException( 'Exchanging of array not allowed.' );
  147. }
  148. /**
  149. * Sets a formatting property.
  150. *
  151. * The $offset is the name of the formatting property, the $value the
  152. * value to be assigned (usually string, but might be of different type).
  153. *
  154. * @param string $offset
  155. * @param mixed $value
  156. * @return void
  157. */
  158. public function offsetSet( $offset, $value )
  159. {
  160. if ( !is_string( $offset ) )
  161. {
  162. throw new ezcBaseValueException(
  163. 'offset',
  164. $offset,
  165. 'string'
  166. );
  167. }
  168. parent::offsetSet( $offset, $value );
  169. }
  170. /**
  171. * Sets the property $name to $value.
  172. *
  173. * @throws ezcBasePropertyNotFoundException if the property does not exist.
  174. * @param string $name
  175. * @param mixed $value
  176. * @ignore
  177. */
  178. public function __set( $name, $value )
  179. {
  180. switch ( $name )
  181. {
  182. case 'type':
  183. throw new ezcBasePropertyPermissionException( $name, ezcBasePropertyPermissionException::READ );
  184. default:
  185. throw new ezcBasePropertyNotFoundException( $name );
  186. }
  187. $this->properties[$name] = $value;
  188. }
  189. /**
  190. * Returns the value of the property $name.
  191. *
  192. * @throws ezcBasePropertyNotFoundException if the property does not exist.
  193. * @param string $name
  194. * @ignore
  195. */
  196. public function __get( $name )
  197. {
  198. if ( $this->__isset( $name ) )
  199. {
  200. return $this->properties[$name];
  201. }
  202. throw new ezcBasePropertyNotFoundException( $name );
  203. }
  204. /**
  205. * Returns true if the property $name is set, otherwise false.
  206. *
  207. * @param string $name
  208. * @return bool
  209. * @ignore
  210. */
  211. public function __isset( $name )
  212. {
  213. return array_key_exists( $name, $this->properties );
  214. }
  215. }
  216. ?>