Ejemplo n.º 1
0
 /**
  * @expectedException Khill\Lavacharts\Exceptions\ChartNotFound
  */
 public function testGetNonExistantLabelChart()
 {
     $v = new Volcano();
     $c = new LineChart('testchart');
     $v->storeChart($c);
     $v->getChart('LineChart', 'superduperchart');
 }
 /**
  * Creates and stores Charts
  *
  * If args contains a label and datatable, a chart will be created,
  * stored in the Volcano and returned.
  *
  * If args only contains a label, and the chart already exists in the
  * Volcano, then it will  be returned.
  *
  * @access private
  * @since  2.0.0
  * @param  string $type Type of chart to fetch or create.
  * @param  string $args Arguments from __call
  * @return \Khill\Lavacharts\Charts\Chart
  * @throws \Khill\Lavacharts\Exceptions\InvalidLabel
  * @throws \Khill\Lavacharts\Exceptions\InvalidDataTable
  * @throws \Khill\Lavacharts\Exceptions\InvalidFunctionParam
  */
 private function chartFactory($type, $args)
 {
     $chart = null;
     $datatable = null;
     if (isset($args[0]) === false) {
         throw new InvalidLabel();
     } else {
         $chartLabel = new Label($args[0]);
     }
     if ($this->volcano->checkChart($type, $chartLabel) === true) {
         return $this->volcano->getChart($type, $chartLabel);
     }
     if (isset($args[1]) === false) {
         throw new InvalidDataTable();
     }
     if ($args[1] instanceof DataTable === false) {
         throw new InvalidDataTable($args[1]);
     }
     if (isset($args[2]) === true && is_array($args[2]) === false) {
         throw new InvalidFunctionParam($args[2], __FUNCTION__, 'array');
     }
     $chartObject = __NAMESPACE__ . '\\Charts\\' . $type;
     if (isset($args[2]) === true && is_array($args[2]) === true) {
         $chart = new $chartObject($chartLabel, $args[1], $args[2]);
     } else {
         $chart = new $chartObject($chartLabel, $args[1]);
     }
     $this->volcano->storeChart($chart);
     return $chart;
 }
Ejemplo n.º 3
0
 /**
  * Creates and stores Chart Wrappers
  *
  * If the Chart is found in the Volcano, then it is returned.
  * Otherwise, a new chart is created and stored in the Volcano.
  *
  * @access private
  * @since  v2.0.0
  *
  * @uses  Chart
  * @param string $type  Type of chart to fetch or create.
  * @param string $label Label of the chart.
  *
  * @return Chart
  */
 private function chartWrapperFactory($type, $label)
 {
     $chartObject = __NAMESPACE__ . '\\Charts\\' . $type;
     if (!$this->volcano->checkChart($type, $label)) {
         $chart = new $chartObject($label);
         $this->volcano->storeChart($chart);
     }
     return $this->volcano->getChart($type, $label);
 }
Ejemplo n.º 4
0
 /**
  * Helper function to "create" for type hinting.
  *
  * @param  string $type Type of chart to create.
  * @param  \Khill\Lavacharts\DataTables\DataTable $datatable DataTable for the chart.
  * @param  \Khill\Lavacharts\Values\Label         $label Chart label.
  * @param  \Khill\Lavacharts\Configs\Options      $options Chart options.
  * @throws \Khill\Lavacharts\Exceptions\InvalidLabel
  * @throws \Khill\Lavacharts\Exceptions\InvalidLavaObject
  * @return \Khill\Lavacharts\Charts\Chart
  */
 private function createChart($type, DataTable $datatable, Label $label, Options $options)
 {
     if ($this->volcano->checkChart($type, $label) === true) {
         return $this->volcano->getChart($type, $label);
     }
     $newChart = __NAMESPACE__ . '\\' . $type;
     $chart = new $newChart($label, $datatable, $options);
     $this->volcano->storeChart($chart);
     return $chart;
 }
Ejemplo n.º 5
0
 /**
  * Stores a existing Chart or Dashboard into the volcano storage.
  *
  * @access public
  * @since  3.0.0
  * @param  Chart|Dashboard $lavaObj Chart or Dashboard.
  * @return boolean
  */
 public function store($lavaObj)
 {
     if ($lavaObj instanceof Dashboard) {
         return $this->volcano->storeDashboard($lavaObj);
     }
     if ($lavaObj instanceof Chart) {
         return $this->volcano->storeChart($lavaObj);
     }
     return false;
 }