Dotclear

Changeset 3749:66047a2eda22


Ignore:
Timestamp:
04/04/18 11:58:36 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Add context property and behaviours

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.sql.statement.php

    r3748 r3749  
    88 * @subpackage Core 
    99 * 
    10  * @copyright Bruno Hondelatte & Association Dotclear 
     10 * @copyright Olivier Meunier & Association Dotclear 
    1111 * @copyright GPL-2.0-only 
    1212 */ 
     
    2020    protected $con; 
    2121 
     22    protected $ctx; // Context (may be useful for behaviour's callback) 
     23 
    2224    protected $columns; 
    2325    protected $from; 
     
    3032     * 
    3133     * @param dcCore    $core   dcCore instance 
    32      * @param mixed     $from   optional from clause(s) 
    33      */ 
    34     public function __construct(&$core, $from = null) 
     34     * @param mixed     $ctx    optional context 
     35     */ 
     36    public function __construct(&$core, $ctx = null) 
    3537    { 
    3638        $this->core = &$core; 
    3739        $this->con  = &$core->con; 
     40        $this->ctx  = $ctx; 
    3841 
    3942        $this->columns = 
     
    4346        $this->sql     = 
    4447        array(); 
    45  
    46         if ($from !== null) { 
    47             if (is_array($from)) { 
    48                 $this->froms($from); 
    49             } else { 
    50                 $this->from($from); 
    51             } 
    52         } 
    5348    } 
    5449 
     
    8883 
    8984    /** 
     85     * Adds context 
     86     * 
     87     * @param mixed     $c      the context(s) 
     88     * 
     89     * @return dcSelectStatement self instance, enabling to chain calls 
     90     */ 
     91    public function ctx($c) 
     92    { 
     93        $this->ctx = $c; 
     94        return $this; 
     95    } 
     96 
     97    /** 
    9098     * Adds column(s) 
    9199     * 
     
    135143        } 
    136144        if (is_array($c)) { 
    137             $filter = function($v) { 
     145            $filter = function ($v) { 
    138146                return trim(ltrim($v, ',')); 
    139147            }; 
     
    280288        } else { 
    281289            $clause = "LIKE '" . 
    282                 $sql->escape(preg_replace(array('%', '_', '!'), array('!%', '!_', '!!'), $value)) . 
     290            $sql->escape(preg_replace(array('%', '_', '!'), array('!%', '!_', '!!'), $value)) . 
    283291                "%' ESCAPE '!'"; 
    284292        } 
     
    303311    { 
    304312        $filter = function ($s) { 
    305             $s = strtoupper($s); 
     313            $s        = strtoupper($s); 
    306314            $patterns = array( 
    307315                '\s+' => ' ', // Multiple spaces/tabs -> one space 
     
    336344     * 
    337345     * @param dcCore    $core   dcCore instance 
    338      * @param mixed     $from   optional from clause(s) 
    339      */ 
    340     public function __construct(&$core, $from = null) 
    341     { 
    342         $this->join    = 
    343         $this->having  = 
    344         $this->order   = 
    345         $this->group   = 
     346     * @param mixed     $ctx    optional context 
     347     */ 
     348    public function __construct(&$core, $ctx = null) 
     349    { 
     350        $this->join   = 
     351        $this->having = 
     352        $this->order  = 
     353        $this->group  = 
    346354        array(); 
    347355 
     
    350358        $this->distinct = false; 
    351359 
    352         parent::__construct($core, $from); 
     360        parent::__construct($core, $ctx); 
    353361    } 
    354362 
     
    496504    public function statement() 
    497505    { 
     506        # --BEHAVIOR-- coreBeforeSelectStatement 
     507        $this->core->callBehavior('coreBeforeSelectStatement', $this); 
     508 
    498509        // Check if source given 
    499510        if (!count($this->from)) { 
     
    563574        } 
    564575 
    565         return trim($query); 
     576        $query = trim($query); 
     577 
     578        # --BEHAVIOR-- coreAfertSelectStatement 
     579        $this->core->callBehavior('coreAfterSelectStatement', $this, $query); 
     580 
     581        return $query; 
    566582    } 
    567583} 
     
    579595    public function statement() 
    580596    { 
     597        # --BEHAVIOR-- coreBeforeDeleteStatement 
     598        $this->core->callBehavior('coreBeforeDeleteStatement', $this); 
     599 
    581600        // Check if source given 
    582601        if (!count($this->from)) { 
     
    609628        } 
    610629 
    611         return trim($query); 
     630        $query = trim($query); 
     631 
     632        # --BEHAVIOR-- coreAfertDeleteStatement 
     633        $this->core->callBehavior('coreAfterDeleteStatement', $this, $query); 
     634 
     635        return $query; 
    612636    } 
    613637} 
     
    624648     * 
    625649     * @param dcCore    $core   dcCore instance 
    626      * @param mixed     $from   optional from clause(s) 
    627      */ 
    628     public function __construct(&$core, $from = null) 
     650     * @param mixed     $ctx    optional context 
     651     */ 
     652    public function __construct(&$core, $ctx = null) 
    629653    { 
    630654        $this->set = array(); 
    631655 
    632         parent::__construct($core, $from); 
     656        parent::__construct($core, $ctx); 
    633657    } 
    634658 
     
    700724    public function whereStatement() 
    701725    { 
     726        # --BEHAVIOR-- coreBeforeUpdateWhereStatement 
     727        $this->core->callBehavior('coreBeforeUpdateWhereStatement', $this); 
     728 
    702729        $query = ''; 
    703730 
     
    720747        } 
    721748 
    722         return trim($query); 
     749        $query = trim($query); 
     750 
     751        # --BEHAVIOR-- coreAfertUpdateWhereStatement 
     752        $this->core->callBehavior('coreAfterUpdateWhereStatement', $this, $query); 
     753 
     754        return $query; 
    723755    } 
    724756 
     
    730762    public function statement() 
    731763    { 
     764        # --BEHAVIOR-- coreBeforeUpdateStatement 
     765        $this->core->callBehavior('coreBeforeUpdateStatement', $this); 
     766 
    732767        // Check if source given 
    733768        if (!count($this->from)) { 
     
    765800        } 
    766801 
    767         return trim($query); 
     802        $query = trim($query); 
     803 
     804        # --BEHAVIOR-- coreAfertUpdateStatement 
     805        $this->core->callBehavior('coreAfterUpdateStatement', $this, $query); 
     806 
     807        return $query; 
    768808    } 
    769809} 
     
    780820     * 
    781821     * @param dcCore    $core   dcCore instance 
    782      * @param mixed     $into   optional into clause(s) 
    783      */ 
    784     public function __construct(&$core, $into = null) 
     822     * @param mixed     $ctx    optional context 
     823     */ 
     824    public function __construct(&$core, $ctx = null) 
    785825    { 
    786826        $this->lines = array(); 
    787827 
    788         parent::__construct($core, $into); 
     828        parent::__construct($core, $ctx); 
    789829    } 
    790830 
     
    843883    public function statement() 
    844884    { 
     885        # --BEHAVIOR-- coreBeforeInsertStatement 
     886        $this->core->callBehavior('coreBeforeInsertStatement', $this); 
     887 
    845888        // Check if source given 
    846889        if (!count($this->from)) { 
     
    873916        } 
    874917 
    875         return trim($query); 
     918        $query = trim($query); 
     919 
     920        # --BEHAVIOR-- coreAfertInsertStatement 
     921        $this->core->callBehavior('coreAfterInsertStatement', $this, $query); 
     922 
     923        return $query; 
    876924    } 
    877925} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map