Ejemplo n.º 1
0
 public function testRetrievingWherePartsReturnsSpecificationArrayOfLeftAndRightAndArrayOfTypes()
 {
     $operator = new Operator();
     $operator->setLeft('foo')->setOperator('>=')->setRight('foo.bar')->setLeftType(Operator::TYPE_VALUE)->setRightType(Operator::TYPE_IDENTIFIER);
     $expected = array(array('%s >= %s', array('foo', 'foo.bar'), array(Operator::TYPE_VALUE, Operator::TYPE_IDENTIFIER)));
     $test = $operator->getExpressionData();
     $this->assertEquals($expected, $test, var_export($test, 1));
 }
Ejemplo n.º 2
0
 public function testCanPassAllValuesToConstructor()
 {
     $predicate = new Operator('bar', '>=', 'foo.bar', Operator::TYPE_VALUE, Operator::TYPE_IDENTIFIER);
     $this->assertEquals(Operator::OP_GTE, $predicate->getOperator());
     $this->assertEquals('bar', $predicate->getLeft());
     $this->assertEquals('foo.bar', $predicate->getRight());
     $this->assertEquals(Operator::TYPE_VALUE, $predicate->getLeftType());
     $this->assertEquals(Operator::TYPE_IDENTIFIER, $predicate->getRightType());
 }
Ejemplo n.º 3
0
 protected function convertValues($type, $data)
 {
     $type = strtoupper($type);
     $return = array();
     switch ($type) {
         case self::WHERE:
             //'string'
             //array('object')
             //array('string' => 'object')
             $association = $data[0];
             $data = $data[1];
             if (is_array($data)) {
                 foreach ($data as $k1 => $v1) {
                     if (is_int($k1)) {
                         $value = $this->convertValues($type, $v1);
                         $return = array_merge($return, $value);
                     } else {
                         $predicate = new Operator();
                         $predicate->setOperator('=');
                         $predicate->setLeft(trim($k1));
                         $predicate->setRight(new Predicate\Expression(':value' . $this->getKeyValues()));
                         $this->setFactoryValues(self::VALUES, array(':value' . $this->getKeyValues() => $v1));
                         $this->setKeyValues($this->getKeyValues() + 1);
                         array_push($return, $predicate);
                     }
                 }
             } else {
                 if (is_object($data)) {
                     array_push($return, array($data, $association));
                 } else {
                     $predicate = new Operator();
                     $operator = $this->extractOperator($data);
                     $data = explode($operator, $data);
                     $predicate->setOperator($operator);
                     $predicate->setLeft(trim($data[0]));
                     $predicate->setRight(new Predicate\Expression(':value' . $this->getKeyValues()));
                     $this->setFactoryValues(self::VALUES, array(':value' . $this->getKeyValues() => trim($data[1])));
                     $this->setKeyValues($this->getKeyValues() + 1);
                     array_push($return, array($predicate, $association));
                 }
             }
             return $return;
             break;
         case self::COLUMNS:
             $return = $data;
             if (is_object($data)) {
                 $return = array($return);
             }
             return $return;
             break;
         case self::FROM:
             $return = $data;
             if (is_object($data)) {
                 $return = array($return);
             }
             return $return;
             break;
         case self::UPDATE:
             if (is_array($data)) {
                 foreach ($data as $k1 => $v1) {
                     if (is_int($k1)) {
                         $value = $this->convertValues($type, $v1);
                         array_push($return, $value);
                     } else {
                         $expression = new Predicate\Expression(':value' . $this->getKeyValues());
                         $this->setFactoryValues(self::VALUES, array(':value' . $this->getKeyValues() => $v1));
                         $this->setKeyValues($this->getKeyValues() + 1);
                         array_push($return, array($k1 => $expression));
                     }
                 }
             } else {
                 if (is_object($data)) {
                     $return = array($data);
                 } else {
                     $expression = new Predicate\Expression(':value' . $this->getKeyValues());
                     $this->setFactoryValues(self::VALUES, array(':value' . $this->getKeyValues() => $data));
                     $this->setKeyValues($this->getKeyValues() + 1);
                     $return = $expression;
                 }
             }
             return $return;
             break;
         case self::INSERT:
             if (is_array($data)) {
                 foreach ($data as $k1 => $v1) {
                     if (is_int($k1)) {
                         $value = $this->convertValues($type, $v1);
                         array_push($return, $value);
                     } else {
                         $expression = new Predicate\Expression(':value' . $this->getKeyValues());
                         $this->setFactoryValues(self::VALUES, array(':value' . $this->getKeyValues() => $v1));
                         $this->setKeyValues($this->getKeyValues() + 1);
                         array_push($return, array($k1 => $expression));
                     }
                 }
             } else {
                 if (is_object($data)) {
                     $return = array($data);
                 } else {
                     $expression = new Predicate\Expression(':value' . $this->getKeyValues());
                     $this->setFactoryValues(self::VALUES, array(':value' . $this->getKeyValues() => $data));
                     $this->setKeyValues($this->getKeyValues() + 1);
                     $return = $expression;
                 }
             }
             return $return;
             break;
         case self::IS_NULL:
             $return = array();
             if (is_array($data)) {
                 foreach ($data as $array) {
                     foreach ($array as $key => $value) {
                         array_push($return, new isNull(trim($value)));
                     }
                 }
             }
             return $return;
             break;
         case self::IS_NOT_NULL:
             $return = array();
             if (is_array($data)) {
                 foreach ($data as $array) {
                     foreach ($array as $key => $value) {
                         array_push($return, new isNotNull(trim($value)));
                     }
                 }
             }
             return $return;
             break;
     }
 }