Ejemplo n.º 1
0
 public function testEquals()
 {
     $criteria = "id = 1";
     $crits = array('id = 1' => array('id', '=', 1, '`id` = 1'), 'name = foo' => array('name', '=', 'foo', "`name` = 'foo'"), 'name ~= foo' => array('name', '~=', 'foo', "`name` LIKE 'foo'"), 'id > 2' => array('id', '>', 2, '`id` > 2'));
     foreach ($crits as $criteria => $d) {
         $c = new AetherORMCriteria($criteria);
         $this->assertEquals($d[0], $c->field);
         $this->assertEquals($d[1], $c->operand);
         $this->assertEquals($d[2], $c->value);
         $this->assertEquals($d[3], $c->getSql());
     }
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }