1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 
<?php
namespace LeanMapper;
use Closure;
use LeanMapper\Exception\InvalidArgumentException;
class Fluent extends \Dibi\Fluent
{
    
    public static $masks = [ 
        'SELECT' => [
            'SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
            'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET', 'UNION',
        ],
        'UPDATE' => ['UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'],
        'INSERT' => ['INSERT', 'INTO', 'VALUES', 'SELECT'],
        'DELETE' => ['DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'],
    ];
    
    private $relatedKeys;
    
    public function applyFilter($filter, $args = null)
    {
        $args = func_get_args();
        $args[0] = $this;
        return call_user_func_array(
            $filter instanceof Closure ? $filter : $this->getConnection()->getFilterCallback($filter),
            $args
        );
    }
    
    public function createSelect($args = null)
    {
        return call_user_func_array([$this->getConnection(), 'select'], func_get_args());
    }
    
    public function _export($clause = null, $args = null)
    {
        $args = func_get_args();
        $reflector = new \ReflectionClass(get_class($this));
        $parent = $reflector->getParentClass();
        $method = $parent->getMethod('_export');
        $method->setAccessible('true');
        return $method->invokeArgs($this, $args);
    }
    
    public function getRelatedKeys()
    {
        return $this->relatedKeys;
    }
    
    public function setRelatedKeys($keys)
    {
        if (!is_array($keys) and $keys !== null) {
            throw new InvalidArgumentException('Invalid related keys given. Expected array or null, ' . gettype($keys) . ' given.');
        }
        $this->relatedKeys = $keys;
        return $this;
    }
}