manage properties where they belong
authorMichael Wallner <mike@php.net>
Wed, 15 Oct 2014 15:21:42 +0000 (17:21 +0200)
committerMichael Wallner <mike@php.net>
Wed, 15 Oct 2014 15:21:42 +0000 (17:21 +0200)
lib/pq/Gateway/Cell.php
lib/pq/Query/Expressible.php

index 3c69a1294d015111db7629aee7234cb5e550dc45..ab2a46fceac95a3a97056fe78bdc4679c20ca2da 100644 (file)
@@ -11,11 +11,6 @@ class Cell extends Expressible implements \ArrayAccess
         */
        protected $row;
        
-       /**
-        * @var string
-        */
-       protected $name;
-       
        /**
         * @var bool
         */
@@ -28,9 +23,8 @@ class Cell extends Expressible implements \ArrayAccess
         * @param bool $dirty
         */
        function __construct(Row $row, $name, $data, $dirty = false) {
-               parent::__construct($data);
+               parent::__construct($name, $data);
                $this->row = $row;
-               $this->name = $name;
                $this->dirty = $dirty;
        }
        
@@ -68,6 +62,9 @@ class Cell extends Expressible implements \ArrayAccess
         * @return \pq\Gateway\Cell
         */
        function mod($data, $op = null) {
+               if (is_string($data)) {
+                       $data = $this->row->getTable()->getConnection()->quote($data);
+               }
                parent::mod($data, $op);
                $this->dirty = true;
                return $this;
index dc2db66fdfffacd62ad9bfaca65fb58850d2c167..d123d8d8cc5fc2ea0816f282f6452d217e6af6ba 100644 (file)
@@ -4,12 +4,22 @@ namespace pq\Query;
 
 class Expressible implements ExpressibleInterface
 {
+       /**
+        * @var string
+        */
+       protected $name;
+       
        /**
         * @var mixed
         */
        protected $data;
        
-       function __construct($data) {
+       /**
+        * @param string $name
+        * @param mixed $data
+        */
+       function __construct($name, $data) {
+               $this->name = $name;
                $this->data = $data;
        }
        
@@ -63,9 +73,6 @@ class Expressible implements ExpressibleInterface
                } elseif (!isset($op) && is_numeric($data)) {
                        $this->data->add(new Expr("+ $data"));
                } else {
-                       if (!is_array($data)) {
-                               $data = $this->row->getTable()->getConnection()->quote($data);
-                       }
                        $this->data->add(new Expr("%s %s", isset($op) ? $op : "||", $data));
                }