[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/library/ezc/Graph/src/interfaces/ -> dataset_property.php (source)

   1  <?php
   2  /**
   3   * File containing the abstract ezcGraphDataSetProperty class
   4   *
   5   * @package Graph
   6   * @version 1.5
   7   * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
   8   * @license http://ez.no/licenses/new_bsd New BSD License
   9   */
  10  /**
  11   * Abstract class for properties of datasets
  12   *
  13   * This class is used to extends datasets with additional properties, and
  14   * stores only non default values for each data point in a data set.
  15   * 
  16   * The class is extended by property implementations including simple value
  17   * validators, like:
  18   *
  19   * - ezcGraphDataSetAxisProperty
  20   * - ezcGraphDataSetBooleanProperty
  21   * - ezcGraphDataSetColorProperty
  22   * - ezcGraphDataSetIntProperty
  23   * - ezcGraphDataSetStringProperty
  24   *
  25   * The color property can for example be accessed in a chart like:
  26   *
  27   * <code>
  28   *  $graph = new ezcGraphLineChart();
  29   *  $graph->data['example'] = new ezcGraphArrayDataSet( array(
  30   *      'Foo' => 23,
  31   *      'Bar' => 42,
  32   *  ) );
  33   *
  34   *  // Set color for all data points in this data set
  35   *  $graph->data['example']->color = '#a40000';
  36   *
  37   *  // Set different color for one special datapoint
  38   *  $graph->data['example']->color['Foo'] = '#2e3436';
  39   *
  40   *  $graph->render( 400, 200, 'test.svg' );
  41   * </code>
  42   *
  43   * @version 1.5
  44   * @package Graph
  45   */
  46  abstract class ezcGraphDataSetProperty implements ArrayAccess
  47  {
  48      /**
  49       * Default value for this property
  50       * 
  51       * @var mixed
  52       */
  53      protected $defaultValue;
  54  
  55      /**
  56       * Contains specified values for single dataset elements
  57       * 
  58       * @var array
  59       */
  60      protected $dataValue;
  61  
  62      /**
  63       * Contains a reference to the dataset to check for availability of data
  64       * keys
  65       * 
  66       * @var ezcGraphDataSet
  67       */
  68      protected $dataset;
  69  
  70      /**
  71       * Abstract method to contain the check for validity of the value
  72       * 
  73       * @param mixed $value 
  74       * @return void
  75       */
  76      abstract protected function checkValue( &$value );
  77  
  78      /**
  79       * Constructor
  80       * 
  81       * @param ezcGraphDataSet $dataset 
  82       * @ignore
  83       * @return void
  84       */
  85      public function __construct( ezcGraphDataSet $dataset )
  86      {
  87          $this->dataset = $dataset;
  88      }
  89  
  90      /**
  91       * Set the default value for this property
  92       * 
  93       * @param string $name Property name
  94       * @param mixed $value Property value
  95       * @return void
  96       */
  97      public function __set( $name, $value )
  98      {
  99          if ( $name === 'default' &&
 100               $this->checkValue( $value ) )
 101          {
 102              $this->defaultValue = $value;
 103          }
 104      }
 105  
 106      /**
 107       * Get the default value for this property
 108       * 
 109       * @param string $name Property name
 110       * @return mixed
 111       */
 112      public function __get( $name )
 113      {
 114          if ( $name === 'default' )
 115          {
 116              return $this->defaultValue;
 117          }
 118      }
 119  
 120      /**
 121       * Returns if an option exists.
 122       * Allows isset() using ArrayAccess.
 123       * 
 124       * @param string $key The name of the option to get.
 125       * @return bool Wether the option exists.
 126       */
 127      final public function offsetExists( $key )
 128      {
 129          return isset( $this->dataset[$key] );
 130      }
 131  
 132      /**
 133       * Returns an option value.
 134       * Get an option value by ArrayAccess.
 135       * 
 136       * @param string $key The name of the option to get.
 137       * @return mixed The option value.
 138       *
 139       * @throws ezcBasePropertyNotFoundException
 140       *         If a the value for the property options is not an instance of
 141       */
 142      final public function offsetGet( $key )
 143      {
 144          if ( isset( $this->dataValue[$key] ) )
 145          {
 146              return $this->dataValue[$key];
 147          }
 148          elseif ( isset( $this->dataset[$key] ) )
 149          {
 150              return $this->defaultValue;
 151          }
 152          else
 153          {
 154              throw new ezcGraphNoSuchDataException( $key );
 155          }
 156      }
 157  
 158      /**
 159       * Set an option.
 160       * Sets an option using ArrayAccess.
 161       * 
 162       * @param string $key The option to set.
 163       * @param mixed $value The value for the option.
 164       * @return void
 165       *
 166       * @throws ezcBasePropertyNotFoundException
 167       *         If a the value for the property options is not an instance of
 168       * @throws ezcBaseValueException
 169       *         If a the value for a property is out of range.
 170       */
 171      public function offsetSet( $key, $value )
 172      {
 173          if ( isset( $this->dataset[$key] ) &&
 174               $this->checkValue( $value ) )
 175          {
 176              $this->dataValue[$key] = $value;
 177          }
 178          else
 179          {
 180              throw new ezcGraphNoSuchDataException( $key );
 181          }
 182      }
 183  
 184      /**
 185       * Unset an option.
 186       * Unsets an option using ArrayAccess.
 187       * 
 188       * @param string $key The options to unset.
 189       * @return void
 190       *
 191       * @throws ezcBasePropertyNotFoundException
 192       *         If a the value for the property options is not an instance of
 193       * @throws ezcBaseValueException
 194       *         If a the value for a property is out of range.
 195       */
 196      final public function offsetUnset( $key )
 197      {
 198          if ( isset( $this->dataset[$key] ) )
 199          {
 200              unset( $this->dataValue[$key] );
 201          }
 202          else
 203          {
 204              throw new ezcGraphNoSuchDataException( $key );
 205          }
 206      }
 207  }
 208  
 209  ?>


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7