Пример #1
0
 public function testTable()
 {
     AetherORM::$_config = $this->config;
     $scheme = new AetherORMScheme('foo', $this->schemeResult);
     $resource = $scheme->getObject();
     $db = 'd';
     $tbl = 'foo';
     $table = new AetherORMTable($resource, $db, $tbl);
     // Forced count, fails because loaded without configinfo
     $cnt = $table->count();
     $this->assertGreaterThan(1, $cnt);
 }
 /**
  * Willy wonkas magic little factory.
  * Every method called unto Connection goes here for parsing
  * and its then delegated on to a table
  *
  * @return AetherORMTable
  * @param string $name
  * @param array $args
  */
 public function __call($func, $args)
 {
     $tableName = strtolower($func);
     $name = $this->config['name'];
     /**
      * Get scheme
      */
     if (!array_key_exists($tableName, $this->schemes)) {
         $schemeData = $this->conn->list_fields($tableName);
         $this->schemes[$tableName] = new AetherORMScheme($tableName, $schemeData);
     }
     // TODO Resource creation needs fix. Load data!
     $resource = $this->schemes[$tableName]->getObject();
     //$resource = new AetherORMResource($tableName,array());
     $table = new AetherORMTable($resource, $name, $tableName);
     if (count($args) == 0) {
         // No args means get the whole table object
         $result = $table;
     } elseif (count($args) == 1 and is_numeric($args[0])) {
         /**
          * Special case for only one integer arg.
          * This means we want to select by primary key
          */
         $primaryKey = $args[0];
         $result = $table->byId($primaryKey);
         /**
          * TODO
          * 1. Ask IM if Row object exists
          * 2. Ask identity map for scheme for table
          * 3. Load scheme (here or IM?)
          * 4. Load Row based on scheme
          */
     } else {
         /**
          * Regular criteria based search.
          * "Criteria" includes everything not being a full table
          * fetch or a single row fetch by primary key
          */
         $criterias = array();
         $where = "WHERE ";
         foreach ($args as $argument) {
             $c = new AetherORMCriteria($argument);
             $where .= $c->getSql() . " AND";
             $criterias[] = $c;
         }
         // Remove the last AND
         $where = substr($where, 0, -4);
         /**
          * TODO THis should go through a query builder, not as
          * directly typed SQL
          * TODO Support for OR-based WHERE clauses?
          */
         $result = $table->bySql("SELECT * FROM {$tableName} {$where}");
     }
     return $result;
 }