Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DataTables/Editor-PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanJard committed Dec 21, 2023
2 parents b028799 + bdb9477 commit 305b221
Show file tree
Hide file tree
Showing 15 changed files with 321 additions and 566 deletions.
3 changes: 2 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
->in(array(__DIR__))
->ignoreDotFiles(false)
->ignoreVCS(true)
->exclude(array('vendor'));
->exclude(array('vendor', 'HtmLawed'));

$config = new PhpCsFixer\Config();

Expand Down Expand Up @@ -66,6 +66,7 @@
'single_line_comment_style' => false,
'phpdoc_annotation_without_dot' => false,
'declare_strict_types' => false,
'static_lambda' => false, // needs PHP 5.4+
'strict_comparison' => false,
'strict_param' => false, // TODO
'final_internal_class' => false,
Expand Down
13 changes: 6 additions & 7 deletions Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function any($table, $where = null)
*
* Use with {@see Database->transaction()} and {@see Database->rollback()}.
*
* @return self
* @return $this
*/
public function commit()
{
Expand Down Expand Up @@ -146,8 +146,7 @@ public function count($table, $field = 'id', $where = null)
*
* @param bool $set Debug mode state. If not given, then used as a getter.
*
* @return bool|self Debug mode state if no parameter is given, or
* self if used as a setter.
* @return ($set is null ? bool : $this) Debug mode state if no parameter is given.
*/
public function debug($set = null)
{
Expand Down Expand Up @@ -312,7 +311,7 @@ public function resource()
*
* Use with {@see Database->transaction()} and {@see Database->commit()}.
*
* @return self
* @return $this
*/
public function rollback()
{
Expand Down Expand Up @@ -410,7 +409,7 @@ public function sql($sql)
*
* Use with {@see Database->commit()} and {@see Database->rollback()}.
*
* @return self
* @return $this
*/
public function transaction()
{
Expand Down Expand Up @@ -457,8 +456,8 @@ public function update($table, $set = null, $where = null)
/**
* Get debug query information.
*
* @return Database Information about the queries used. When this method is
* called it will reset the query cache.
* @return $this Information about the queries used. When this method is
* called it will reset the query cache.
*
* @internal
*/
Expand Down
4 changes: 2 additions & 2 deletions Database/Driver/PostgresQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ protected function _prepare($sql)

// Get the pkey field name
$pkRes = $resource->prepare(
"SELECT a.attname
'SELECT a.attname
FROM pg_index i
JOIN pg_attribute a ON a.attrelid = i.indrelid
AND a.attnum = ANY(i.indkey)
WHERE i.indrelid = (:tableName)::regclass
AND i.indisprimary"
AND i.indisprimary'
);
$pkRes->bindValue('tableName', $table[0]);
$pkRes->execute();
Expand Down
114 changes: 58 additions & 56 deletions Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ public function __construct($dbHost, $type, $table = null)
protected $_offset;

/**
* @var string
* @var bool
*
* @internal
*/
protected $_distinct = false;

/**
* @var string
* @var array{string, string}
*
* @internal
*/
Expand Down Expand Up @@ -196,7 +196,7 @@ public static function commit($dbh)
* @param string $host Host name
* @param string $db Database name
*
* @return Query
* @return \PDO
*/
public static function connect($user, $pass = '', $host = '', $port = '', $db = '', $dsn = '')
{
Expand Down Expand Up @@ -262,7 +262,7 @@ public static function dsnPostfix($dsn)
* @param mixed $type Data type. See the PHP PDO documentation:
* http://php.net/manual/en/pdo.constants.php
*
* @return Query
* @return $this
*/
public function bind($name, $value, $type = null)
{
Expand Down Expand Up @@ -291,7 +291,7 @@ public function database()
*
* @param bool $dis Optional
*
* @return Query
* @return $this
*/
public function distinct($dis)
{
Expand Down Expand Up @@ -334,7 +334,7 @@ public function exec($sql = null)
* @param string|string[] ...$get Fields to get - can be specified as
* individual fields or an array of fields.
*
* @return self
* @return $this
*/
public function get($get)
{
Expand Down Expand Up @@ -374,7 +374,7 @@ public function get($get)
* @param string $condition JOIN condition
* @param string $type JOIN type
*
* @return self
* @return $this
*/
public function join($table, $condition, $type = '', $bind = true)
{
Expand Down Expand Up @@ -402,6 +402,8 @@ public function join($table, $condition, $type = '', $bind = true)

/**
* Add a left join, with common logic for handling binding or not.
*
* @return $this
*/
public function left_join($joins)
{
Expand Down Expand Up @@ -439,7 +441,7 @@ public function left_join($joins)
*
* @param int $lim The number of records to limit the result to.
*
* @return self
* @return $this
*/
public function limit($lim)
{
Expand All @@ -453,7 +455,7 @@ public function limit($lim)
*
* @param string $group_by The field of which the values are to be grouped
*
* @return self
* @return $this
*/
public function group_by($group_by)
{
Expand All @@ -468,7 +470,7 @@ public function group_by($group_by)
*
* @param string[] $pkey Primary keys
*
* @return Query|string[]
* @return ($pkey is null ? string[] : $this)
*/
public function pkey($pkey = null)
{
Expand All @@ -488,7 +490,7 @@ public function pkey($pkey = null)
* individual names, an array of names, a string of comma separated
* names or any combination of those.
*
* @return self
* @return $this
*/
public function table($table)
{
Expand Down Expand Up @@ -518,7 +520,7 @@ public function table($table)
*
* @param int $off The number of records to offset the result by.
*
* @return self
* @return $this
*/
public function offset($off)
{
Expand All @@ -534,7 +536,7 @@ public function offset($off)
* be specified as individual names, an array of names, a string of comma
* separated names or any combination of those.
*
* @return self
* @return $this
*/
public function order($order)
{
Expand Down Expand Up @@ -577,7 +579,7 @@ public function order($order)
* name and this is the field's value.
* @param bool $bind Should the value be bound or not
*
* @return self
* @return $this
*/
public function set($set, $val = null, $bind = true)
{
Expand Down Expand Up @@ -608,17 +610,17 @@ public function set($set, $val = null, $bind = true)
* Can be used in two different ways, as where( field, value ) or as an array of
* conditions to use: where( array('fieldName', ...), array('value', ...) );
*
* @param string|string[]|callable $key Single field name, or an array of field names.
* If given as a function (i.e. a closure), the function is called, passing the
* query itself in as the only parameter, so the function can add extra conditions
* with parentheses around the additional parameters.
* @param string|string[] $value Single field value, or an array of
* values. Can be null to search for `IS NULL` or `IS NOT NULL` (depending
* on the value of `$op` which should be `=` or `!=`.
* @param string $op Condition operator: <, >, = etc
* @param bool $bind Escape the value (true, default) or not (false).
* @param string|string[]|\Closure($this): void $key Single field name, or an array of field names.
* If given as a function (i.e. a closure), the function is called, passing the
* query itself in as the only parameter, so the function can add extra conditions
* with parentheses around the additional parameters.
* @param string|int|string[]|int[] $value Single field value, or an array of
* values. Can be null to search for `IS NULL` or `IS NOT NULL` (depending
* on the value of `$op` which should be `=` or `!=`.
* @param string $op Condition operator: <, >, = etc
* @param bool $bind Escape the value (true, default) or not (false).
*
* @return self
* @return $this
*
* @example
* The following will produce
Expand All @@ -637,7 +639,7 @@ public function where($key, $value = null, $op = '=', $bind = true)
{
if ($key === null) {
return $this;
} elseif (is_callable($key) && is_object($key)) { // is a closure
} elseif ($key instanceof \Closure) {
$this->_where_group(true, 'AND');
$key($this);
$this->_where_group(false, 'OR');
Expand All @@ -659,17 +661,17 @@ public function where($key, $value = null, $op = '=', $bind = true)
* Can be used in two different ways, as where( field, value ) or as an array of
* conditions to use: where( array('fieldName', ...), array('value', ...) );
*
* @param string|string[]|callable $key Single field name, or an array of field names.
* If given as a function (i.e. a closure), the function is called, passing the
* query itself in as the only parameter, so the function can add extra conditions
* with parentheses around the additional parameters.
* @param string|string[] $value Single field value, or an array of
* values. Can be null to search for `IS NULL` or `IS NOT NULL` (depending
* on the value of `$op` which should be `=` or `!=`.
* @param string $op Condition operator: <, >, = etc
* @param bool $bind Escape the value (true, default) or not (false).
* @param string|string[]|\Closure($this): void $key Single field name, or an array of field names.
* If given as a function (i.e. a closure), the function is called, passing the
* query itself in as the only parameter, so the function can add extra conditions
* with parentheses around the additional parameters.
* @param string|int|string[]|int[] $value Single field value, or an array of
* values. Can be null to search for `IS NULL` or `IS NOT NULL` (depending
* on the value of `$op` which should be `=` or `!=`.
* @param string $op Condition operator: <, >, = etc
* @param bool $bind Escape the value (true, default) or not (false).
*
* @return self
* @return $this
*/
public function and_where($key, $value = null, $op = '=', $bind = true)
{
Expand All @@ -682,23 +684,23 @@ public function and_where($key, $value = null, $op = '=', $bind = true)
* Can be used in two different ways, as where( field, value ) or as an array of
* conditions to use: where( array('fieldName', ...), array('value', ...) );
*
* @param string|string[]|callable $key Single field name, or an array of field names.
* If given as a function (i.e. a closure), the function is called, passing the
* query itself in as the only parameter, so the function can add extra conditions
* with parentheses around the additional parameters.
* @param string|string[] $value Single field value, or an array of
* values. Can be null to search for `IS NULL` or `IS NOT NULL` (depending
* on the value of `$op` which should be `=` or `!=`.
* @param string $op Condition operator: <, >, = etc
* @param bool $bind Escape the value (true, default) or not (false).
* @param string|string[]|\Closure($this): void $key Single field name, or an array of field names.
* If given as a function (i.e. a closure), the function is called, passing the
* query itself in as the only parameter, so the function can add extra conditions
* with parentheses around the additional parameters.
* @param string|int|string[]|int[] $value Single field value, or an array of
* values. Can be null to search for `IS NULL` or `IS NOT NULL` (depending
* on the value of `$op` which should be `=` or `!=`.
* @param string $op Condition operator: <, >, = etc
* @param bool $bind Escape the value (true, default) or not (false).
*
* @return self
* @return $this
*/
public function or_where($key, $value = null, $op = '=', $bind = true)
{
if ($key === null) {
return $this;
} elseif (is_callable($key) && is_object($key)) {
} elseif ($key instanceof \Closure) {
$this->_where_group(true, 'OR');
$key($this);
$this->_where_group(false, 'OR');
Expand All @@ -725,13 +727,13 @@ public function or_where($key, $value = null, $op = '=', $bind = true)
* define if a grouping bracket should be opened or closed in the query.
* This method is not prefer.
*
* @param bool|callable $inOut If callable it will create the group
* automatically and pass the query into the called function. For
* legacy operations use `true` to open brackets, `false` to close.
* @param string $op Conditional operator to use to join to the
* preceding condition. Default `AND`.
* @param bool|\Closure($this): void $inOut If callable it will create the group
* automatically and pass the query into the called function. For
* legacy operations use `true` to open brackets, `false` to close.
* @param string $op Conditional operator to use to join to the
* preceding condition. Default `AND`.
*
* @return self
* @return $this
*
* @example
* ```php
Expand All @@ -743,7 +745,7 @@ public function or_where($key, $value = null, $op = '=', $bind = true)
*/
public function where_group($inOut, $op = 'AND')
{
if (is_callable($inOut) && is_object($inOut)) {
if ($inOut instanceof \Closure) {
$this->_where_group(true, $op);
$inOut($this);
$this->_where_group(false, $op);
Expand All @@ -766,7 +768,7 @@ public function where_group($inOut, $op = 'AND')
* @param string $operator Conditional operator to use to join to the
* preceding condition. Default `AND`.
*
* @return self
* @return $this
*/
public function where_in($field, $arr, $operator = 'AND')
{
Expand Down Expand Up @@ -1008,7 +1010,7 @@ protected function _build_where()
if ($this->_where[$i - 1]['group'] === '(') {
$condition .= '1=1';
}
// else nothing
// else nothing reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7497 is fixed
} elseif ($this->_where[$i - 1]['group'] === '(') {
// Nothing
} else {
Expand Down Expand Up @@ -1250,7 +1252,7 @@ protected function _update()
* @internal
*
* @param string|array $where
* @param string $value
* @param string|int $value
* @param string $type
* @param string $op
* @param bool $bind
Expand Down
Loading

0 comments on commit 305b221

Please sign in to comment.