aboutsummaryrefslogtreecommitdiff
path: root/classes/CinIsis.php
blob: ff1de68fc92fac447f1c07f25571fd7beccf424c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

/**
 * CinIsis main class.
 */
class CinIsis {
  /**
   * @var $db
   *   Database resource.
   */  
  var $db;

  /**
   * @var $implementation
   *   Database implementation.
   */
  var $implementation;

  /**
   * Constructor.
   *
   * @param $file
   *   Optional parameter to set alternative config file.
   *
   * @todo
   *   Config check.
   */   
  function __construct($file = 'config/config.yaml') {
    try {
      // Load main configuration.
      $config = $this->config($file);

      // Load database schema.
      $schema = $this->config('schemas/'. $config['database'] .'.yaml');
    } catch (Exception $e) {
      echo '[cinisis] caught exception: ',  $e->getMessage(), "\n";
      return FALSE;
    }

    // Setup database connection.
    $this->implementation = $config['implementation'] .'Db';
    $this->db             = new $this->implementation($schema);
  }

  /**
   * Config file load.
   *
   * @param $file
   *   Config file.
   *
   * @return
   *   Array with configuration.
   */
  function config($file) {
    if (!file_exists($file)) {
      throw new Exception('Config '. $file .' not found.');
    }

    // Load configuration.
    return Spyc::YAMLLoad($file);
  }
}