Esempio n. 1
0
 /**
  * Setup a database connection (to a table)
  * @param string an optional table name, optional only in PHP <= 5.3.0
  */
 public function __construct($tableName = NULL)
 {
     // db connection
     $this->db = Fari_DbPdo::getConnection();
     // table name exists?
     if (isset($tableName)) {
         $this->tableName = $tableName;
     } else {
         if (isset($this->tableName)) {
             assert('!empty($this->tableName); // table name needs to be provided');
         } else {
             // are we using high enough version of PHP for late static binding?
             try {
                 if (version_compare(phpversion(), '5.3.0', '<=') == TRUE) {
                     throw new Fari_Exception('Table name can automatically only be resolved in PHP 5.3.0.');
                 }
             } catch (Fari_Exception $exception) {
                 $exception->fire();
             }
             // ... yes, get the name of the class as the name of the table
             $this->tableName = get_called_class();
         }
     }
     // attach observers
     $this->logger = new Fari_DbLogger();
     $this->logger->attach(new Fari_ApplicationLogger());
     // attach validator
     $this->validator = $this->attachValidator();
     // prep relationships
     $this->relationships = new Fari_DbTableRelationships();
 }