Complex classes like FluentPdoModel often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FluentPdoModel, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 34 | class FluentPdoModel |
||
| 35 | { |
||
| 36 | const ACTIVE = 1; |
||
| 37 | const INACTIVE = 0; |
||
| 38 | // const ARCHIVED = -1; |
||
| 39 | const GZIP_PREFIX = 'gzipped|'; |
||
| 40 | const OPERATOR_AND = ' AND '; |
||
| 41 | const OPERATOR_OR = ' OR '; |
||
| 42 | const ORDERBY_ASC = 'ASC'; |
||
| 43 | const ORDERBY_DESC = 'DESC'; |
||
| 44 | const SAVE_INSERT = 'INSERT'; |
||
| 45 | const SAVE_UPDATE = 'UPDATE'; |
||
| 46 | const LEFT_JOIN = 'LEFT'; |
||
| 47 | const INNER_JOIN = 'INNER'; |
||
| 48 | const ONE_DAY = 86400; |
||
| 49 | const ONE_WEEK = 60480060; |
||
| 50 | const ONE_HOUR = 3600; |
||
| 51 | const TEN_MINS = 600; |
||
| 52 | const CACHE_NO = -1; |
||
| 53 | const CACHE_DEFAULT = 0; |
||
| 54 | |||
| 55 | const CREATOR_ID_FIELD = 'creator_id'; |
||
| 56 | const CREATOR_FIELD = 'creator'; |
||
| 57 | const CREATED_TS_FIELD = 'created_ts'; |
||
| 58 | const MODIFIER_ID_FIELD = 'modifier_id'; |
||
| 59 | const MODIFIER_FIELD = 'modifier'; |
||
| 60 | const MODIFIED_TS_FIELD = 'modified_ts'; |
||
| 61 | const DELETER_ID_FIELD = 'deleter_id'; |
||
| 62 | const DELETER_FIELD = 'deleter'; |
||
| 63 | const DELETED_TS_FIELD = 'deleted_ts'; |
||
| 64 | const STATUS_FIELD = 'active'; |
||
| 65 | |||
| 66 | /** @var AbstractPdo $_connection */ |
||
| 67 | protected $_connection = null; |
||
| 68 | |||
| 69 | /** @var string */ |
||
| 70 | protected $_primary_key = 'id'; |
||
| 71 | |||
| 72 | /** @var array */ |
||
| 73 | protected $_where_parameters = []; |
||
| 74 | |||
| 75 | /** @var array */ |
||
| 76 | protected $_select_fields = []; |
||
| 77 | |||
| 78 | /** @var array */ |
||
| 79 | protected $_join_sources = []; |
||
| 80 | |||
| 81 | /** @var array */ |
||
| 82 | protected $_join_aliases = []; |
||
| 83 | |||
| 84 | /** @var array $_associations */ |
||
| 85 | protected $_associations = [ |
||
| 86 | 'belongsTo' => [], |
||
| 87 | ]; |
||
| 88 | |||
| 89 | /** @var array */ |
||
| 90 | protected $_where_conditions = []; |
||
| 91 | |||
| 92 | protected $_raw_sql = ''; |
||
| 93 | |||
| 94 | /** @var int */ |
||
| 95 | protected $_limit = 0; |
||
| 96 | |||
| 97 | /** @var int */ |
||
| 98 | protected $_offset = 0; |
||
| 99 | |||
| 100 | /** @var array */ |
||
| 101 | protected $_order_by = []; |
||
| 102 | |||
| 103 | /** @var array */ |
||
| 104 | protected $_group_by = []; |
||
| 105 | |||
| 106 | /** @var string */ |
||
| 107 | protected $_and_or_operator = self::OPERATOR_AND; |
||
| 108 | |||
| 109 | /** @var array */ |
||
| 110 | protected $_having = []; |
||
| 111 | |||
| 112 | /** @var bool */ |
||
| 113 | protected $_wrap_open = false; |
||
| 114 | |||
| 115 | /** @var int */ |
||
| 116 | protected $_last_wrap_position = 0; |
||
| 117 | |||
| 118 | /** @var PDOStatement $_pdo_stmt */ |
||
| 119 | protected $_pdo_stmt = null; |
||
| 120 | |||
| 121 | /** @var bool */ |
||
| 122 | protected $_distinct = false; |
||
| 123 | |||
| 124 | /** @var null */ |
||
| 125 | protected $_requested_fields = []; |
||
| 126 | |||
| 127 | /** @var null */ |
||
| 128 | protected $_filter_meta = []; |
||
| 129 | |||
| 130 | /** @var bool */ |
||
| 131 | protected $_log_queries = false; |
||
| 132 | |||
| 133 | /** @var array */ |
||
| 134 | protected $_timer = []; |
||
| 135 | |||
| 136 | /** @var int */ |
||
| 137 | protected $_slow_query_secs = 5; |
||
| 138 | |||
| 139 | /** @var array */ |
||
| 140 | protected $_pagination_attribs = [ |
||
| 141 | '_limit', |
||
| 142 | '_offset', |
||
| 143 | '_order', |
||
| 144 | '_fields', |
||
| 145 | '_search' |
||
| 146 | ]; |
||
| 147 | |||
| 148 | /** @var string $_table_name */ |
||
| 149 | protected $_table_name = ''; |
||
| 150 | |||
| 151 | /** @var string $_table_alias */ |
||
| 152 | protected $_table_alias = ''; |
||
| 153 | |||
| 154 | /** @var string $_display_column */ |
||
| 155 | protected $_display_column = ''; |
||
| 156 | |||
| 157 | /** @var string $_connection_name */ |
||
| 158 | protected $_connection_name = ''; |
||
| 159 | |||
| 160 | /** @var array $_schema */ |
||
| 161 | protected $_schema = []; |
||
| 162 | |||
| 163 | /** @var array $_virtual_fields */ |
||
| 164 | protected $_virtual_fields = []; |
||
| 165 | |||
| 166 | /** @var array $_errors */ |
||
| 167 | protected $_errors = []; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @var int - true = connection default x days |
||
| 171 | * - false = no cache |
||
| 172 | * - int = a specific amount |
||
| 173 | */ |
||
| 174 | protected $_cache_ttl = self::CACHE_NO; |
||
| 175 | |||
| 176 | /** @var array */ |
||
| 177 | protected $_flush_cache_tables = []; |
||
| 178 | |||
| 179 | /** @var string */ |
||
| 180 | protected $_tmp_table_prefix = 'tmp_'; |
||
| 181 | |||
| 182 | /** @var null|string */ |
||
| 183 | protected $_built_query = ''; |
||
| 184 | |||
| 185 | /** @var array */ |
||
| 186 | protected $_handlers = []; |
||
| 187 | |||
| 188 | /** @var bool User want to directly specify the fields */ |
||
| 189 | protected $_explicit_select_mode = false; |
||
| 190 | |||
| 191 | /** @var string[] */ |
||
| 192 | protected $_update_raw = []; |
||
| 193 | |||
| 194 | protected $_max_callback_failures = -1; |
||
| 195 | |||
| 196 | protected $_num_callback_failures = 0; |
||
| 197 | |||
| 198 | protected $_filter_on_fetch = false; |
||
| 199 | |||
| 200 | protected $_log_filter_changes = true; |
||
| 201 | |||
| 202 | protected $_include_count = false; |
||
| 203 | |||
| 204 | /** @var string */ |
||
| 205 | static protected $_model_namespace = ''; |
||
| 206 | |||
| 207 | /** @var bool */ |
||
| 208 | protected $_validation_exceptions = true; |
||
| 209 | |||
| 210 | /** @var array */ |
||
| 211 | protected $_paging_meta = []; |
||
| 212 | |||
| 213 | /** @var bool */ |
||
| 214 | protected $_soft_deletes = true; |
||
| 215 | |||
| 216 | |||
| 217 | /** @var bool */ |
||
| 218 | protected $_allow_meta_override = false; |
||
| 219 | |||
| 220 | /** @var bool */ |
||
| 221 | protected $_skip_meta_updates = false; |
||
| 222 | |||
| 223 | /** @var bool */ |
||
| 224 | protected $_add_update_alias = false; |
||
| 225 | |||
| 226 | /** @var int */ |
||
| 227 | protected $_default_max = 250; |
||
| 228 | |||
| 229 | /** @var array */ |
||
| 230 | protected $removeUnauthorisedFields = []; |
||
| 231 | |||
| 232 | protected $_can_generic_update = true; |
||
| 233 | protected $_can_generic_add = true; |
||
| 234 | protected $_can_generic_delete = true; |
||
| 235 | |||
| 236 | /** @var array */ |
||
| 237 | protected $row_meta_data = []; |
||
| 238 | |||
| 239 | protected $excluded_search_cols = []; |
||
| 240 | |||
| 241 | |||
| 242 | /** @var array */ |
||
| 243 | protected $globalRemoveUnauthorisedFields = [ |
||
| 244 | '/global_table_meta#view' => [ |
||
| 245 | self::CREATOR_ID_FIELD, |
||
| 246 | self::CREATOR_FIELD, |
||
| 247 | self::CREATED_TS_FIELD, |
||
| 248 | self::MODIFIER_ID_FIELD, |
||
| 249 | self::MODIFIER_FIELD, |
||
| 250 | self::MODIFIED_TS_FIELD, |
||
| 251 | self::STATUS_FIELD, |
||
| 252 | ], |
||
| 253 | ]; |
||
| 254 | |||
| 255 | |||
| 256 | /** |
||
| 257 | * @param AbstractPdo|null $connection |
||
| 258 | */ |
||
| 259 | public function __construct(AbstractPdo $connection=null) |
||
| 266 | |||
| 267 | public function init() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @return AbstractPdo |
||
| 272 | * @throws Exception |
||
| 273 | */ |
||
| 274 | public function getPdo() : AbstractPdo |
||
| 278 | |||
| 279 | /** |
||
| 280 | * @return LoggerInterface |
||
| 281 | */ |
||
| 282 | public function getLogger() : LoggerInterface |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @return CacheInterface |
||
| 289 | */ |
||
| 290 | public function getCache() : CacheInterface |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Define the working table and create a new instance |
||
| 297 | * |
||
| 298 | * @param string $tableName - Table name |
||
| 299 | * @param string $alias - The table alias name |
||
| 300 | * @param string $displayColumn |
||
| 301 | * @param string $primaryKeyName |
||
| 302 | * |
||
| 303 | * @return FluentPdoModel|$this |
||
| 304 | */ |
||
| 305 | public function table(string $tableName, string $alias='', string $displayColumn='', string $primaryKeyName='id') : FluentPdoModel |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param string $primaryKeyName |
||
| 316 | * @return FluentPdoModel|$this |
||
| 317 | */ |
||
| 318 | public function primaryKeyName(string $primaryKeyName) : FluentPdoModel |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @param string $tableName |
||
| 327 | * |
||
| 328 | * @return FluentPdoModel|$this |
||
| 329 | */ |
||
| 330 | public function tableName(string $tableName) : FluentPdoModel |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @param $explicitSelect |
||
| 339 | * |
||
| 340 | * @return FluentPdoModel|$this |
||
| 341 | */ |
||
| 342 | public function explicitSelectMode(bool $explicitSelect=true) : FluentPdoModel |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @param bool $filterOnFetch |
||
| 351 | * |
||
| 352 | * @return FluentPdoModel|$this |
||
| 353 | */ |
||
| 354 | public function filterOnFetch(bool $filterOnFetch=true) : FluentPdoModel |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @param bool $logFilterChanges |
||
| 363 | * |
||
| 364 | * @return FluentPdoModel|$this |
||
| 365 | */ |
||
| 366 | public function logFilterChanges(bool $logFilterChanges=true) : FluentPdoModel |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Return the name of the table |
||
| 375 | * |
||
| 376 | * @return string |
||
| 377 | */ |
||
| 378 | public function getTableName() : string |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @return string |
||
| 385 | */ |
||
| 386 | public function getDisplayColumn() : string |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Set the display column |
||
| 393 | * |
||
| 394 | * @param string $column |
||
| 395 | * |
||
| 396 | * @return FluentPdoModel|$this |
||
| 397 | */ |
||
| 398 | public function displayColumn(string $column) : FluentPdoModel |
||
| 404 | /** |
||
| 405 | * Set the table alias |
||
| 406 | * |
||
| 407 | * @param string $alias |
||
| 408 | * |
||
| 409 | * @return FluentPdoModel|$this |
||
| 410 | */ |
||
| 411 | public function tableAlias(string $alias) : FluentPdoModel |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @param int $cacheTtl |
||
| 420 | * @return FluentPdoModel|$this |
||
| 421 | * @throws Exception |
||
| 422 | */ |
||
| 423 | protected function _cacheTtl(int $cacheTtl) : FluentPdoModel |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @return string |
||
| 437 | */ |
||
| 438 | public function getTableAlias() : string |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @param array $associations |
||
| 445 | * |
||
| 446 | * @return FluentPdoModel|$this |
||
| 447 | */ |
||
| 448 | public function associations(array $associations) : FluentPdoModel |
||
| 454 | |||
| 455 | /** |
||
| 456 | * @param string $alias |
||
| 457 | * @param array $definition |
||
| 458 | * @return FluentPdoModel|$this |
||
| 459 | */ |
||
| 460 | public function setBelongsTo(string $alias, array $definition) : FluentPdoModel |
||
| 469 | |||
| 470 | /** |
||
| 471 | * @param $alias |
||
| 472 | * @param $displayField |
||
| 473 | * @return FluentPdoModel|$this |
||
| 474 | * @throws \Terah\Assert\AssertionFailedException |
||
| 475 | */ |
||
| 476 | public function setBelongsToDisplayField(string $alias, string $displayField) : FluentPdoModel |
||
| 486 | |||
| 487 | /** |
||
| 488 | * @param PDOStatement $stmt |
||
| 489 | * @param Closure $fnCallback |
||
| 490 | * @return bool|stdClass |
||
| 491 | */ |
||
| 492 | public function fetchRow(PDOStatement $stmt, Closure $fnCallback=null) |
||
| 515 | |||
| 516 | /** |
||
| 517 | * @param PDOStatement $stmt |
||
| 518 | * @param $record |
||
| 519 | * @return array |
||
| 520 | */ |
||
| 521 | protected function getColumnMeta(PDOStatement $stmt, $record) : array |
||
| 540 | |||
| 541 | /** |
||
| 542 | * @param array $schema |
||
| 543 | * |
||
| 544 | * @return FluentPdoModel|$this |
||
| 545 | */ |
||
| 546 | public function schema(array $schema) : FluentPdoModel |
||
| 552 | |||
| 553 | /** |
||
| 554 | * @param string|array $field |
||
| 555 | * @param $type |
||
| 556 | * @return FluentPdoModel|$this |
||
| 557 | */ |
||
| 558 | public function addSchema($field, string $type) : FluentPdoModel |
||
| 574 | |||
| 575 | /** |
||
| 576 | * @param $keysOnly |
||
| 577 | * @return array |
||
| 578 | */ |
||
| 579 | public function getColumns(bool $keysOnly=true) : array |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Get the primary key name |
||
| 586 | * |
||
| 587 | * @return string |
||
| 588 | */ |
||
| 589 | public function getPrimaryKeyName() : string |
||
| 593 | |||
| 594 | /** |
||
| 595 | * @param string $query |
||
| 596 | * @param array $parameters |
||
| 597 | * |
||
| 598 | * @return bool |
||
| 599 | * @throws Exception |
||
| 600 | */ |
||
| 601 | public function execute(string $query, array $parameters=[]) : bool |
||
| 626 | |||
| 627 | /** |
||
| 628 | * @param string $query |
||
| 629 | * @param array $params |
||
| 630 | * @return FluentPdoModel|$this |
||
| 631 | */ |
||
| 632 | public function query(string $query, array $params=[]) : FluentPdoModel |
||
| 639 | |||
| 640 | /** |
||
| 641 | * @param string $sql |
||
| 642 | * @param array $params |
||
| 643 | * |
||
| 644 | * @return string |
||
| 645 | */ |
||
| 646 | public function buildQuery(string $sql, array $params=[]) : string |
||
| 674 | |||
| 675 | /** |
||
| 676 | * @param stdClass $record |
||
| 677 | * |
||
| 678 | * @return stdClass |
||
| 679 | */ |
||
| 680 | protected function _trimAndLowerCaseKeys(stdClass $record) : stdClass |
||
| 690 | |||
| 691 | /** |
||
| 692 | * Return the number of affected row by the last statement |
||
| 693 | * |
||
| 694 | * @return int |
||
| 695 | */ |
||
| 696 | public function rowCount() : int |
||
| 702 | |||
| 703 | /** |
||
| 704 | * @return PDOStatement |
||
| 705 | * @throws PDOException |
||
| 706 | */ |
||
| 707 | public function fetchStmt() |
||
| 716 | |||
| 717 | /** |
||
| 718 | * @return array |
||
| 719 | */ |
||
| 720 | public function fetchSqlQuery() : array |
||
| 730 | |||
| 731 | /** |
||
| 732 | * @param string $tableName |
||
| 733 | * @param bool $dropIfExists |
||
| 734 | * @param array $indexes |
||
| 735 | * @return boolean |
||
| 736 | * @throws Exception |
||
| 737 | */ |
||
| 738 | public function fetchIntoMemoryTable(string $tableName, bool $dropIfExists=true, array $indexes=[]) : bool |
||
| 760 | |||
| 761 | /** |
||
| 762 | * @param string $keyedOn |
||
| 763 | * @param int $cacheTtl |
||
| 764 | * @return stdClass[] |
||
| 765 | */ |
||
| 766 | public function fetch(string $keyedOn='', int $cacheTtl=self::CACHE_NO) : array |
||
| 804 | |||
| 805 | /** |
||
| 806 | * @return string |
||
| 807 | */ |
||
| 808 | protected function _parseWhereForPrimaryLookup() : string |
||
| 824 | |||
| 825 | /** |
||
| 826 | * @param string $cacheKey |
||
| 827 | * @param Closure $func |
||
| 828 | * @param int $cacheTtl - 0 for default ttl, -1 for no cache or int for custom ttl |
||
| 829 | * @return mixed |
||
| 830 | */ |
||
| 831 | protected function _cacheData(string $cacheKey, Closure $func, int $cacheTtl=self::CACHE_DEFAULT) |
||
| 869 | |||
| 870 | /** |
||
| 871 | * @param string $cacheKey |
||
| 872 | * @return bool |
||
| 873 | */ |
||
| 874 | public function clearCache(string $cacheKey) : bool |
||
| 878 | |||
| 879 | /** |
||
| 880 | * @param string $table |
||
| 881 | * @return bool |
||
| 882 | */ |
||
| 883 | public function clearCacheByTable(string $table='') : bool |
||
| 893 | |||
| 894 | /** |
||
| 895 | * @return string[] |
||
| 896 | */ |
||
| 897 | public function getFlushCacheTables() : array |
||
| 901 | |||
| 902 | /** |
||
| 903 | * @param Closure $fnCallback |
||
| 904 | * @return int |
||
| 905 | */ |
||
| 906 | public function fetchCallback(Closure $fnCallback) : int |
||
| 915 | |||
| 916 | /** |
||
| 917 | * @param Closure $fnCallback |
||
| 918 | * @param string $keyedOn |
||
| 919 | * @return array |
||
| 920 | */ |
||
| 921 | public function fetchObjectsByCallback(Closure $fnCallback, string $keyedOn='') : array |
||
| 938 | |||
| 939 | /** |
||
| 940 | * @param $numFailures |
||
| 941 | * @return FluentPdoModel|$this |
||
| 942 | */ |
||
| 943 | public function maxCallbackFailures(int $numFailures) : FluentPdoModel |
||
| 950 | |||
| 951 | /** |
||
| 952 | * @param PDOStatement $stmt |
||
| 953 | * @param Closure $fnCallback |
||
| 954 | * @param int $successCnt |
||
| 955 | * @return bool|null|stdClass |
||
| 956 | */ |
||
| 957 | protected function _tallySuccessCount(PDOStatement $stmt, Closure $fnCallback, int &$successCnt) |
||
| 990 | |||
| 991 | /** |
||
| 992 | * @return bool |
||
| 993 | */ |
||
| 994 | public function canGenericUpdate() : bool |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * @return bool |
||
| 1001 | */ |
||
| 1002 | public function canGenericAdd() : bool |
||
| 1006 | |||
| 1007 | /** |
||
| 1008 | * @return bool |
||
| 1009 | */ |
||
| 1010 | public function canGenericDelete() : bool |
||
| 1014 | |||
| 1015 | /** |
||
| 1016 | * @param string $keyedOn |
||
| 1017 | * @param string $valueField |
||
| 1018 | * @param int $cacheTtl |
||
| 1019 | * @return mixed |
||
| 1020 | */ |
||
| 1021 | public function fetchList(string $keyedOn='', string $valueField='', int $cacheTtl=self::CACHE_NO) : array |
||
| 1083 | |||
| 1084 | /** |
||
| 1085 | * @param string $column |
||
| 1086 | * @param int $cacheTtl |
||
| 1087 | * @param bool|true $unique |
||
| 1088 | * @return array |
||
| 1089 | */ |
||
| 1090 | public function fetchColumn(string $column, int $cacheTtl=self::CACHE_NO, bool $unique=true) : array |
||
| 1100 | |||
| 1101 | /** |
||
| 1102 | * @param string $field |
||
| 1103 | * @param int $itemId |
||
| 1104 | * @param int $cacheTtl |
||
| 1105 | * @return mixed|null |
||
| 1106 | */ |
||
| 1107 | public function fetchField(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) |
||
| 1130 | |||
| 1131 | /** |
||
| 1132 | * @param string $field |
||
| 1133 | * @param int $itemId |
||
| 1134 | * @param int $cacheTtl |
||
| 1135 | * @return string |
||
| 1136 | */ |
||
| 1137 | public function fetchStr(string $field='', $itemId=0, int $cacheTtl=self::CACHE_NO) : string |
||
| 1141 | |||
| 1142 | /** |
||
| 1143 | * @param int $cacheTtl |
||
| 1144 | * @return int |
||
| 1145 | */ |
||
| 1146 | public function fetchId(int $cacheTtl=self::CACHE_NO) : int |
||
| 1150 | |||
| 1151 | /** |
||
| 1152 | * @param string $field |
||
| 1153 | * @param int $itemId |
||
| 1154 | * @param int $cacheTtl |
||
| 1155 | * @return int |
||
| 1156 | */ |
||
| 1157 | public function fetchInt(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : int |
||
| 1161 | |||
| 1162 | /** |
||
| 1163 | * @param string $field |
||
| 1164 | * @param int $itemId |
||
| 1165 | * @param int $cacheTtl |
||
| 1166 | * @return float |
||
| 1167 | */ |
||
| 1168 | public function fetchFloat(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : float |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * @param string $field |
||
| 1175 | * @param int $itemId |
||
| 1176 | * @param int $cacheTtl |
||
| 1177 | * @return bool |
||
| 1178 | */ |
||
| 1179 | public function fetchBool(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : bool |
||
| 1183 | |||
| 1184 | /** |
||
| 1185 | * @param int|null $id |
||
| 1186 | * @param int $cacheTtl |
||
| 1187 | * @return stdClass|bool |
||
| 1188 | */ |
||
| 1189 | public function fetchOne(int $id=0, int $cacheTtl=self::CACHE_NO) |
||
| 1200 | |||
| 1201 | /** |
||
| 1202 | * @param int|null $id |
||
| 1203 | * @param int $cacheTtl |
||
| 1204 | * @return boolean |
||
| 1205 | */ |
||
| 1206 | public function fetchExists(int $id=0, int $cacheTtl=self::CACHE_NO) : bool |
||
| 1216 | |||
| 1217 | /*------------------------------------------------------------------------------ |
||
| 1218 | Fluent Query Builder |
||
| 1219 | *-----------------------------------------------------------------------------*/ |
||
| 1220 | |||
| 1221 | /** |
||
| 1222 | * Create the select clause |
||
| 1223 | * |
||
| 1224 | * @param mixed $columns - the column to select. Can be string or array of fields |
||
| 1225 | * @param string $alias - an alias to the column |
||
| 1226 | * @param boolean $explicitSelect |
||
| 1227 | * @return FluentPdoModel|$this |
||
| 1228 | */ |
||
| 1229 | public function select($columns='*', string $alias='', bool $explicitSelect=true) : FluentPdoModel |
||
| 1271 | |||
| 1272 | /** |
||
| 1273 | * @param string $select |
||
| 1274 | * @return FluentPdoModel|$this |
||
| 1275 | */ |
||
| 1276 | public function selectRaw(string $select) : FluentPdoModel |
||
| 1282 | |||
| 1283 | /** |
||
| 1284 | * @param bool $logQueries |
||
| 1285 | * |
||
| 1286 | * @return FluentPdoModel|$this |
||
| 1287 | */ |
||
| 1288 | public function logQueries(bool $logQueries=true) : FluentPdoModel |
||
| 1294 | |||
| 1295 | /** |
||
| 1296 | * @param bool $includeCnt |
||
| 1297 | * |
||
| 1298 | * @return FluentPdoModel|$this |
||
| 1299 | */ |
||
| 1300 | public function includeCount(bool $includeCnt=true) : FluentPdoModel |
||
| 1306 | |||
| 1307 | /** |
||
| 1308 | * @param bool $distinct |
||
| 1309 | * |
||
| 1310 | * @return FluentPdoModel|$this |
||
| 1311 | */ |
||
| 1312 | public function distinct(bool $distinct=true) : FluentPdoModel |
||
| 1318 | |||
| 1319 | /** |
||
| 1320 | * @param array $fields |
||
| 1321 | * @return FluentPdoModel|$this |
||
| 1322 | */ |
||
| 1323 | public function withBelongsTo(array $fields=[]) : FluentPdoModel |
||
| 1336 | |||
| 1337 | /** |
||
| 1338 | * @param string $alias |
||
| 1339 | * @param bool $addSelectField |
||
| 1340 | * @return FluentPdoModel |
||
| 1341 | */ |
||
| 1342 | public function autoInnerJoin(string $alias, bool $addSelectField=true) : FluentPdoModel |
||
| 1346 | |||
| 1347 | /** |
||
| 1348 | * @param string $alias |
||
| 1349 | * @param string $type |
||
| 1350 | * @param bool $addSelectField |
||
| 1351 | * @return FluentPdoModel|$this |
||
| 1352 | */ |
||
| 1353 | public function autoJoin(string $alias, string $type=self::LEFT_JOIN, bool $addSelectField=true) : FluentPdoModel |
||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * @param array $conditions |
||
| 1385 | * @return FluentPdoModel |
||
| 1386 | */ |
||
| 1387 | public function whereArr(array $conditions) : FluentPdoModel |
||
| 1396 | /** |
||
| 1397 | * Add where condition, more calls appends with AND |
||
| 1398 | * |
||
| 1399 | * @param string $condition possibly containing ? or :name |
||
| 1400 | * @param mixed $parameters accepted by PDOStatement::execute or a scalar value |
||
| 1401 | * @param mixed ... |
||
| 1402 | * @return FluentPdoModel|$this |
||
| 1403 | */ |
||
| 1404 | public function where($condition, $parameters=[]) : FluentPdoModel |
||
| 1453 | |||
| 1454 | /** |
||
| 1455 | * Create an AND operator in the where clause |
||
| 1456 | * |
||
| 1457 | * @return FluentPdoModel|$this |
||
| 1458 | */ |
||
| 1459 | public function _and() : FluentPdoModel |
||
| 1473 | |||
| 1474 | |||
| 1475 | /** |
||
| 1476 | * Create an OR operator in the where clause |
||
| 1477 | * |
||
| 1478 | * @return FluentPdoModel|$this |
||
| 1479 | */ |
||
| 1480 | public function _or() : FluentPdoModel |
||
| 1494 | |||
| 1495 | /** |
||
| 1496 | * To group multiple where clauses together. |
||
| 1497 | * |
||
| 1498 | * @return FluentPdoModel|$this |
||
| 1499 | */ |
||
| 1500 | public function wrap() : FluentPdoModel |
||
| 1510 | |||
| 1511 | /** |
||
| 1512 | * Where Primary key |
||
| 1513 | * |
||
| 1514 | * @param int $id |
||
| 1515 | * @param bool $addAlias |
||
| 1516 | * |
||
| 1517 | * @return FluentPdoModel|$this |
||
| 1518 | */ |
||
| 1519 | public function wherePk(int $id, bool $addAlias=true) : FluentPdoModel |
||
| 1525 | |||
| 1526 | /** |
||
| 1527 | * @param string $name |
||
| 1528 | * @param bool $addAlias |
||
| 1529 | * @return FluentPdoModel |
||
| 1530 | */ |
||
| 1531 | public function whereDisplayName(string $name, bool $addAlias=true) : FluentPdoModel |
||
| 1537 | |||
| 1538 | /** |
||
| 1539 | * WHERE $columnName != $value |
||
| 1540 | * |
||
| 1541 | * @param string $columnName |
||
| 1542 | * @param mixed $value |
||
| 1543 | * @return FluentPdoModel|$this |
||
| 1544 | */ |
||
| 1545 | public function whereNot(string $columnName, $value) : FluentPdoModel |
||
| 1549 | /** |
||
| 1550 | * WHERE $columnName != $value |
||
| 1551 | * |
||
| 1552 | * @param string $columnName |
||
| 1553 | * @param mixed $value |
||
| 1554 | * @return FluentPdoModel|$this |
||
| 1555 | */ |
||
| 1556 | public function whereCoercedNot(string $columnName, $value) : FluentPdoModel |
||
| 1560 | |||
| 1561 | /** |
||
| 1562 | * WHERE $columnName LIKE $value |
||
| 1563 | * |
||
| 1564 | * @param string $columnName |
||
| 1565 | * @param mixed $value |
||
| 1566 | * @return FluentPdoModel|$this |
||
| 1567 | */ |
||
| 1568 | public function whereLike(string $columnName, $value) : FluentPdoModel |
||
| 1572 | |||
| 1573 | /** |
||
| 1574 | * @param string $columnName |
||
| 1575 | * @param mixed $value1 |
||
| 1576 | * @param mixed $value2 |
||
| 1577 | * @return FluentPdoModel|$this |
||
| 1578 | */ |
||
| 1579 | public function whereBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
| 1586 | |||
| 1587 | /** |
||
| 1588 | * @param string $columnName |
||
| 1589 | * @param mixed $value1 |
||
| 1590 | * @param mixed $value2 |
||
| 1591 | * @return FluentPdoModel|$this |
||
| 1592 | */ |
||
| 1593 | public function whereNotBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
| 1600 | |||
| 1601 | /** |
||
| 1602 | * @param string $columnName |
||
| 1603 | * @param string $regex |
||
| 1604 | * @return FluentPdoModel|$this |
||
| 1605 | */ |
||
| 1606 | public function whereRegex(string $columnName, string $regex) : FluentPdoModel |
||
| 1610 | |||
| 1611 | /** |
||
| 1612 | * @param string $columnName |
||
| 1613 | * @param string $regex |
||
| 1614 | * @return FluentPdoModel|$this |
||
| 1615 | */ |
||
| 1616 | public function whereNotRegex(string $columnName, string $regex) : FluentPdoModel |
||
| 1620 | |||
| 1621 | /** |
||
| 1622 | * WHERE $columnName NOT LIKE $value |
||
| 1623 | * |
||
| 1624 | * @param string $columnName |
||
| 1625 | * @param string $value |
||
| 1626 | * @return FluentPdoModel|$this |
||
| 1627 | */ |
||
| 1628 | public function whereNotLike(string $columnName, string $value) : FluentPdoModel |
||
| 1632 | |||
| 1633 | /** |
||
| 1634 | * WHERE $columnName > $value |
||
| 1635 | * |
||
| 1636 | * @param string $columnName |
||
| 1637 | * @param mixed $value |
||
| 1638 | * @return FluentPdoModel|$this |
||
| 1639 | */ |
||
| 1640 | public function whereGt(string $columnName, $value) : FluentPdoModel |
||
| 1644 | |||
| 1645 | /** |
||
| 1646 | * WHERE $columnName >= $value |
||
| 1647 | * |
||
| 1648 | * @param string $columnName |
||
| 1649 | * @param mixed $value |
||
| 1650 | * @return FluentPdoModel|$this |
||
| 1651 | */ |
||
| 1652 | public function whereGte(string $columnName, $value) : FluentPdoModel |
||
| 1656 | |||
| 1657 | /** |
||
| 1658 | * WHERE $columnName < $value |
||
| 1659 | * |
||
| 1660 | * @param string $columnName |
||
| 1661 | * @param mixed $value |
||
| 1662 | * @return FluentPdoModel|$this |
||
| 1663 | */ |
||
| 1664 | public function whereLt(string $columnName, $value) : FluentPdoModel |
||
| 1668 | |||
| 1669 | /** |
||
| 1670 | * WHERE $columnName <= $value |
||
| 1671 | * |
||
| 1672 | * @param string $columnName |
||
| 1673 | * @param mixed $value |
||
| 1674 | * @return FluentPdoModel|$this |
||
| 1675 | */ |
||
| 1676 | public function whereLte(string $columnName, $value) : FluentPdoModel |
||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * WHERE $columnName IN (?,?,?,...) |
||
| 1683 | * |
||
| 1684 | * @param string $columnName |
||
| 1685 | * @param array $values |
||
| 1686 | * @return FluentPdoModel|$this |
||
| 1687 | */ |
||
| 1688 | public function whereIn(string $columnName, array $values) : FluentPdoModel |
||
| 1692 | |||
| 1693 | /** |
||
| 1694 | * WHERE $columnName NOT IN (?,?,?,...) |
||
| 1695 | * |
||
| 1696 | * @param string $columnName |
||
| 1697 | * @param array $values |
||
| 1698 | * @return FluentPdoModel|$this |
||
| 1699 | */ |
||
| 1700 | public function whereNotIn(string $columnName, array $values) : FluentPdoModel |
||
| 1706 | |||
| 1707 | /** |
||
| 1708 | * WHERE $columnName IS NULL |
||
| 1709 | * |
||
| 1710 | * @param string $columnName |
||
| 1711 | * @return FluentPdoModel|$this |
||
| 1712 | */ |
||
| 1713 | public function whereNull(string $columnName) : FluentPdoModel |
||
| 1717 | |||
| 1718 | /** |
||
| 1719 | * WHERE $columnName IS NOT NULL |
||
| 1720 | * |
||
| 1721 | * @param string $columnName |
||
| 1722 | * @return FluentPdoModel|$this |
||
| 1723 | */ |
||
| 1724 | public function whereNotNull(string $columnName) : FluentPdoModel |
||
| 1728 | |||
| 1729 | /** |
||
| 1730 | * @param string $statement |
||
| 1731 | * @param string $operator |
||
| 1732 | * @return FluentPdoModel|$this |
||
| 1733 | */ |
||
| 1734 | public function having(string $statement, string $operator=self::OPERATOR_AND) : FluentPdoModel |
||
| 1743 | |||
| 1744 | /** |
||
| 1745 | * ORDER BY $columnName (ASC | DESC) |
||
| 1746 | * |
||
| 1747 | * @param string $columnName - The name of the column or an expression |
||
| 1748 | * @param string $ordering (DESC | ASC) |
||
| 1749 | * @return FluentPdoModel|$this |
||
| 1750 | */ |
||
| 1751 | public function orderBy(string $columnName='', string $ordering='ASC') : FluentPdoModel |
||
| 1765 | |||
| 1766 | /** |
||
| 1767 | * GROUP BY $columnName |
||
| 1768 | * |
||
| 1769 | * @param string $columnName |
||
| 1770 | * @return FluentPdoModel|$this |
||
| 1771 | */ |
||
| 1772 | public function groupBy(string $columnName) : FluentPdoModel |
||
| 1782 | |||
| 1783 | |||
| 1784 | /** |
||
| 1785 | * LIMIT $limit |
||
| 1786 | * |
||
| 1787 | * @param int $limit |
||
| 1788 | * @param int|null $offset |
||
| 1789 | * @return FluentPdoModel|$this |
||
| 1790 | */ |
||
| 1791 | public function limit(int $limit, int $offset=0) : FluentPdoModel |
||
| 1800 | |||
| 1801 | /** |
||
| 1802 | * Return the limit |
||
| 1803 | * |
||
| 1804 | * @return integer |
||
| 1805 | */ |
||
| 1806 | public function getLimit() : int |
||
| 1810 | |||
| 1811 | /** |
||
| 1812 | * OFFSET $offset |
||
| 1813 | * |
||
| 1814 | * @param int $offset |
||
| 1815 | * @return FluentPdoModel|$this |
||
| 1816 | */ |
||
| 1817 | public function offset(int $offset) : FluentPdoModel |
||
| 1823 | |||
| 1824 | /** |
||
| 1825 | * Return the offset |
||
| 1826 | * |
||
| 1827 | * @return integer |
||
| 1828 | */ |
||
| 1829 | public function getOffset() : int |
||
| 1833 | |||
| 1834 | /** |
||
| 1835 | * Build a join |
||
| 1836 | * |
||
| 1837 | * @param string $table - The table name |
||
| 1838 | * @param string $constraint -> id = profile.user_id |
||
| 1839 | * @param string $tableAlias - The alias of the table name |
||
| 1840 | * @param string $joinOperator - LEFT | INNER | etc... |
||
| 1841 | * @return FluentPdoModel|$this |
||
| 1842 | */ |
||
| 1843 | public function join(string $table, string $constraint='', string $tableAlias='', string $joinOperator='') : FluentPdoModel |
||
| 1862 | |||
| 1863 | /** |
||
| 1864 | * Create a left join |
||
| 1865 | * |
||
| 1866 | * @param string $table |
||
| 1867 | * @param string $constraint |
||
| 1868 | * @param string $tableAlias |
||
| 1869 | * @return FluentPdoModel|$this |
||
| 1870 | */ |
||
| 1871 | public function leftJoin(string $table, string $constraint, string $tableAlias='') : FluentPdoModel |
||
| 1875 | |||
| 1876 | |||
| 1877 | /** |
||
| 1878 | * Return the build select query |
||
| 1879 | * |
||
| 1880 | * @return string |
||
| 1881 | */ |
||
| 1882 | public function getSelectQuery() : string |
||
| 1925 | |||
| 1926 | /** |
||
| 1927 | * @param string $field |
||
| 1928 | * @param string $column |
||
| 1929 | * @return string |
||
| 1930 | */ |
||
| 1931 | public function getFieldComment(string $field, string $column) : string |
||
| 1935 | |||
| 1936 | /** |
||
| 1937 | * Prepare columns to include the table alias name |
||
| 1938 | * @param array $columns |
||
| 1939 | * @return array |
||
| 1940 | */ |
||
| 1941 | protected function _prepareColumns(array $columns) : array |
||
| 1971 | |||
| 1972 | /** |
||
| 1973 | * Build the WHERE clause(s) |
||
| 1974 | * |
||
| 1975 | * @param bool $purgeAliases |
||
| 1976 | * @return string |
||
| 1977 | */ |
||
| 1978 | protected function _getWhereString(bool $purgeAliases=false) : string |
||
| 2011 | |||
| 2012 | /** |
||
| 2013 | * Return the HAVING clause |
||
| 2014 | * |
||
| 2015 | * @return string |
||
| 2016 | */ |
||
| 2017 | protected function _getHavingString() : string |
||
| 2036 | |||
| 2037 | /** |
||
| 2038 | * Return the values to be bound for where |
||
| 2039 | * |
||
| 2040 | * @param bool $purgeAliases |
||
| 2041 | * @return array |
||
| 2042 | */ |
||
| 2043 | protected function _getWhereParameters(bool $purgeAliases=false) : array |
||
| 2049 | |||
| 2050 | /** |
||
| 2051 | * @param array $record |
||
| 2052 | * @return stdClass |
||
| 2053 | */ |
||
| 2054 | public function insertArr(array $record) : stdClass |
||
| 2058 | |||
| 2059 | /** |
||
| 2060 | * Insert new rows |
||
| 2061 | * $records can be a stdClass or an array of stdClass to add a bulk insert |
||
| 2062 | * If a single row is inserted, it will return it's row instance |
||
| 2063 | * |
||
| 2064 | * @param stdClass $record |
||
| 2065 | * @return stdClass |
||
| 2066 | * @throws Exception |
||
| 2067 | */ |
||
| 2068 | public function insert(stdClass $record) : stdClass |
||
| 2091 | |||
| 2092 | /** |
||
| 2093 | * @param string $name |
||
| 2094 | * @return int |
||
| 2095 | */ |
||
| 2096 | public function getLastInsertId(string $name='') : int |
||
| 2100 | |||
| 2101 | /** |
||
| 2102 | * @param stdClass[] $records |
||
| 2103 | * @return stdClass[] |
||
| 2104 | */ |
||
| 2105 | public function insertSqlQuery(array $records) : array |
||
| 2125 | |||
| 2126 | /** |
||
| 2127 | * @param $data |
||
| 2128 | * @param array $matchOn |
||
| 2129 | * @param bool $returnObj |
||
| 2130 | * @return bool|int|stdClass |
||
| 2131 | */ |
||
| 2132 | public function upsert($data, array $matchOn=[], $returnObj=false) |
||
| 2154 | |||
| 2155 | /** |
||
| 2156 | * @param stdClass $object |
||
| 2157 | * @param array $matchOn |
||
| 2158 | * @param bool $returnObj |
||
| 2159 | * @return bool|int|stdClass |
||
| 2160 | */ |
||
| 2161 | public function upsertOne(stdClass $object, array $matchOn=[], $returnObj=false) |
||
| 2201 | |||
| 2202 | /** |
||
| 2203 | * @param array $data |
||
| 2204 | * @param array $matchOn |
||
| 2205 | * @param bool|false $returnObj |
||
| 2206 | * @return bool|int|stdClass |
||
| 2207 | */ |
||
| 2208 | public function upsertArr(array $data, array $matchOn=[], bool $returnObj=false) |
||
| 2212 | |||
| 2213 | /** |
||
| 2214 | * Update entries |
||
| 2215 | * Use the query builder to create the where clause |
||
| 2216 | * |
||
| 2217 | * @param stdClass $record |
||
| 2218 | * @param bool $updateAll |
||
| 2219 | * @return int |
||
| 2220 | * @throws Exception |
||
| 2221 | */ |
||
| 2222 | public function update(stdClass $record, $updateAll=false) : int |
||
| 2245 | |||
| 2246 | /** |
||
| 2247 | * @param array $record |
||
| 2248 | * @param bool|false $updateAll |
||
| 2249 | * @return int |
||
| 2250 | * @throws Exception |
||
| 2251 | */ |
||
| 2252 | public function updateArr(array $record, $updateAll=false) : int |
||
| 2256 | |||
| 2257 | |||
| 2258 | /** |
||
| 2259 | * @param string $field |
||
| 2260 | * @param mixed $value |
||
| 2261 | * @param int $id |
||
| 2262 | * @param bool|false $updateAll |
||
| 2263 | * @return int |
||
| 2264 | * @throws Exception |
||
| 2265 | */ |
||
| 2266 | public function updateField(string $field, $value, int $id=0, bool $updateAll=false) : int |
||
| 2280 | |||
| 2281 | /** |
||
| 2282 | * @param stdClass $record |
||
| 2283 | * @return bool|int |
||
| 2284 | * @throws Exception |
||
| 2285 | */ |
||
| 2286 | public function updateChanged(stdClass $record) : int |
||
| 2300 | |||
| 2301 | /** |
||
| 2302 | * @param string $expression |
||
| 2303 | * @param array $params |
||
| 2304 | * @return FluentPdoModel|$this |
||
| 2305 | */ |
||
| 2306 | public function updateByExpression(string $expression, array $params) : FluentPdoModel |
||
| 2312 | |||
| 2313 | /** |
||
| 2314 | * @param array $data |
||
| 2315 | * @return int |
||
| 2316 | * @throws Exception |
||
| 2317 | */ |
||
| 2318 | public function rawUpdate(array $data=[]) : int |
||
| 2327 | |||
| 2328 | /** |
||
| 2329 | * @param stdClass $record |
||
| 2330 | * @return array |
||
| 2331 | */ |
||
| 2332 | public function updateSqlQuery(stdClass $record) : array |
||
| 2342 | |||
| 2343 | /** |
||
| 2344 | * @param $record |
||
| 2345 | * @return array |
||
| 2346 | */ |
||
| 2347 | protected function updateSql(array $record) : array |
||
| 2380 | |||
| 2381 | /** |
||
| 2382 | * @param bool $deleteAll |
||
| 2383 | * @param bool $force |
||
| 2384 | * @return int |
||
| 2385 | * @throws Exception |
||
| 2386 | */ |
||
| 2387 | public function delete(bool $deleteAll=false, bool $force=false) : int |
||
| 2403 | |||
| 2404 | /** |
||
| 2405 | * @return bool |
||
| 2406 | */ |
||
| 2407 | public function isSoftDelete() : bool |
||
| 2411 | |||
| 2412 | /** |
||
| 2413 | * @param bool|false $force |
||
| 2414 | * @return FluentPdoModel|$this |
||
| 2415 | * @throws Exception |
||
| 2416 | */ |
||
| 2417 | public function truncate(bool $force=false) : FluentPdoModel |
||
| 2431 | |||
| 2432 | /** |
||
| 2433 | * @return array |
||
| 2434 | */ |
||
| 2435 | public function deleteSqlQuery() : array |
||
| 2447 | |||
| 2448 | |||
| 2449 | /** |
||
| 2450 | * Return the aggregate count of column |
||
| 2451 | * |
||
| 2452 | * @param string $column |
||
| 2453 | * @param int $cacheTtl |
||
| 2454 | * @return float |
||
| 2455 | */ |
||
| 2456 | public function count(string $column='*', int $cacheTtl=self::CACHE_NO) : float |
||
| 2476 | |||
| 2477 | |||
| 2478 | /** |
||
| 2479 | * Return the aggregate max count of column |
||
| 2480 | * |
||
| 2481 | * @param string $column |
||
| 2482 | * @param int $cacheTtl |
||
| 2483 | * @return int|float|string|null |
||
| 2484 | */ |
||
| 2485 | public function max(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2491 | |||
| 2492 | |||
| 2493 | /** |
||
| 2494 | * Return the aggregate min count of column |
||
| 2495 | * |
||
| 2496 | * @param string $column |
||
| 2497 | * @param int $cacheTtl |
||
| 2498 | * @return int|float|string|null |
||
| 2499 | */ |
||
| 2500 | public function min(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2506 | |||
| 2507 | /** |
||
| 2508 | * Return the aggregate sum count of column |
||
| 2509 | * |
||
| 2510 | * @param string $column |
||
| 2511 | * @param int $cacheTtl |
||
| 2512 | * @return int|float|string|null |
||
| 2513 | */ |
||
| 2514 | public function sum(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2520 | |||
| 2521 | /** |
||
| 2522 | * Return the aggregate average count of column |
||
| 2523 | * |
||
| 2524 | * @param string $column |
||
| 2525 | * @param int $cacheTtl |
||
| 2526 | * @return int|float|string|null |
||
| 2527 | */ |
||
| 2528 | public function avg(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2534 | |||
| 2535 | /*******************************************************************************/ |
||
| 2536 | // Utilities methods |
||
| 2537 | |||
| 2538 | /** |
||
| 2539 | * Reset fields |
||
| 2540 | * |
||
| 2541 | * @return FluentPdoModel|$this |
||
| 2542 | */ |
||
| 2543 | public function reset() : FluentPdoModel |
||
| 2571 | |||
| 2572 | |||
| 2573 | /** |
||
| 2574 | * @return FluentPdoModel|$this |
||
| 2575 | */ |
||
| 2576 | public function removeUnauthorisedFields() : FluentPdoModel |
||
| 2580 | |||
| 2581 | /** |
||
| 2582 | * @return Closure[] |
||
| 2583 | */ |
||
| 2584 | protected function _getFieldHandlers() : array |
||
| 2677 | |||
| 2678 | /** |
||
| 2679 | * @return bool |
||
| 2680 | */ |
||
| 2681 | public function begin() : bool |
||
| 2695 | |||
| 2696 | /** |
||
| 2697 | * @return bool |
||
| 2698 | */ |
||
| 2699 | public function commit() : bool |
||
| 2717 | |||
| 2718 | /** |
||
| 2719 | * @return bool |
||
| 2720 | */ |
||
| 2721 | public function rollback() : bool |
||
| 2735 | |||
| 2736 | /** |
||
| 2737 | * @param stdClass $record |
||
| 2738 | * @param string $type |
||
| 2739 | * @return stdClass |
||
| 2740 | */ |
||
| 2741 | public function applyGlobalModifiers(stdClass $record, string $type) : stdClass |
||
| 2754 | |||
| 2755 | /** |
||
| 2756 | * @param stdClass $record |
||
| 2757 | * @param string $type |
||
| 2758 | * @return stdClass |
||
| 2759 | */ |
||
| 2760 | public function removeUnneededFields(stdClass $record, string $type) : stdClass |
||
| 2789 | |||
| 2790 | |||
| 2791 | /** |
||
| 2792 | * @param array $ids |
||
| 2793 | * @param array $values |
||
| 2794 | * @param int $batch |
||
| 2795 | * @return bool |
||
| 2796 | */ |
||
| 2797 | public function setById(array $ids, array $values, int $batch=1000) : bool |
||
| 2817 | |||
| 2818 | |||
| 2819 | /** |
||
| 2820 | * @param string $displayColumnValue |
||
| 2821 | * @return int |
||
| 2822 | */ |
||
| 2823 | public function resolveId(string $displayColumnValue) : int |
||
| 2834 | |||
| 2835 | /** |
||
| 2836 | * @param int $resourceId |
||
| 2837 | * @param array $query |
||
| 2838 | * @param array $extraFields |
||
| 2839 | * @param int $cacheTtl |
||
| 2840 | * @return array |
||
| 2841 | */ |
||
| 2842 | public function fetchApiResource(int $resourceId, array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO) : array |
||
| 2855 | |||
| 2856 | /** |
||
| 2857 | * @param array $query |
||
| 2858 | * @param array $extraFields |
||
| 2859 | * @param int $cacheTtl |
||
| 2860 | * @param string $permEntity |
||
| 2861 | * @return array |
||
| 2862 | */ |
||
| 2863 | public function fetchApiResources(array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO, string $permEntity='') : array |
||
| 2885 | |||
| 2886 | |||
| 2887 | /** |
||
| 2888 | * @return array |
||
| 2889 | */ |
||
| 2890 | public function getSearchableAssociations() : array |
||
| 2897 | |||
| 2898 | /** |
||
| 2899 | * @param array $fields |
||
| 2900 | */ |
||
| 2901 | public function removeUnrequestedFields(array $fields) |
||
| 2912 | |||
| 2913 | /** |
||
| 2914 | * @param array $removeFields |
||
| 2915 | */ |
||
| 2916 | public function removeFields(array $removeFields=[]) |
||
| 2941 | |||
| 2942 | /** |
||
| 2943 | * @return FluentPdoModel|$this |
||
| 2944 | */ |
||
| 2945 | public function defaultFilters() : FluentPdoModel |
||
| 2949 | |||
| 2950 | /** |
||
| 2951 | * @param bool $allow |
||
| 2952 | * |
||
| 2953 | * @return FluentPdoModel|$this |
||
| 2954 | */ |
||
| 2955 | public function allowMetaColumnOverride(bool $allow=false) : FluentPdoModel |
||
| 2961 | |||
| 2962 | /** |
||
| 2963 | * @param bool $skip |
||
| 2964 | * |
||
| 2965 | * @return FluentPdoModel|$this |
||
| 2966 | */ |
||
| 2967 | public function skipMetaUpdates(bool $skip=true) : FluentPdoModel |
||
| 2973 | |||
| 2974 | /** |
||
| 2975 | * @param bool $add |
||
| 2976 | * |
||
| 2977 | * @return FluentPdoModel|$this |
||
| 2978 | */ |
||
| 2979 | public function addUpdateAlias(bool $add=true) : FluentPdoModel |
||
| 2985 | |||
| 2986 | /** |
||
| 2987 | * @param stdClass $record |
||
| 2988 | * @return stdClass |
||
| 2989 | */ |
||
| 2990 | public function onFetch(stdClass $record) : stdClass |
||
| 3002 | |||
| 3003 | /** |
||
| 3004 | * @param $value |
||
| 3005 | * @return string |
||
| 3006 | */ |
||
| 3007 | public function gzEncodeData(string $value) : string |
||
| 3016 | |||
| 3017 | /** |
||
| 3018 | * @param $value |
||
| 3019 | * @return mixed|string |
||
| 3020 | */ |
||
| 3021 | public function gzDecodeData(string $value) : string |
||
| 3031 | |||
| 3032 | /** |
||
| 3033 | * @param $value |
||
| 3034 | * @return bool |
||
| 3035 | */ |
||
| 3036 | protected function _hasGzipPrefix(string $value) : bool |
||
| 3040 | |||
| 3041 | /** |
||
| 3042 | * @param stdClass $record |
||
| 3043 | * @return stdClass |
||
| 3044 | */ |
||
| 3045 | public function fixTimestamps(stdClass $record) : stdClass |
||
| 3057 | |||
| 3058 | /** |
||
| 3059 | * @param int $max |
||
| 3060 | * @return FluentPdoModel|$this |
||
| 3061 | */ |
||
| 3062 | public function setMaxRecords(int $max) : FluentPdoModel |
||
| 3069 | |||
| 3070 | |||
| 3071 | /** |
||
| 3072 | * @param stdClass $record |
||
| 3073 | * @param string $type |
||
| 3074 | * @return stdClass |
||
| 3075 | */ |
||
| 3076 | public function afterSave(stdClass $record, string $type) : stdClass |
||
| 3097 | |||
| 3098 | /** |
||
| 3099 | * @param stdClass $record |
||
| 3100 | * @param string $type |
||
| 3101 | * @return stdClass |
||
| 3102 | */ |
||
| 3103 | public function addDefaultFields(stdClass $record, string $type) : stdClass |
||
| 3136 | |||
| 3137 | |||
| 3138 | /** |
||
| 3139 | * @return bool |
||
| 3140 | */ |
||
| 3141 | public function createTable() : bool |
||
| 3145 | |||
| 3146 | /** |
||
| 3147 | * @param bool|false $force |
||
| 3148 | * @return FluentPdoModel|$this |
||
| 3149 | * @throws Exception |
||
| 3150 | */ |
||
| 3151 | public function dropTable(bool $force=false) : FluentPdoModel |
||
| 3155 | |||
| 3156 | protected function _compileHandlers() |
||
| 3165 | |||
| 3166 | /** |
||
| 3167 | * @param string $viewName |
||
| 3168 | * @param int $cacheTtl |
||
| 3169 | * @return array |
||
| 3170 | */ |
||
| 3171 | public function getViewColumns($viewName, $cacheTtl=self::CACHE_NO) |
||
| 3175 | |||
| 3176 | /** |
||
| 3177 | * @param int $id |
||
| 3178 | * @return string |
||
| 3179 | */ |
||
| 3180 | public function getDisplayNameById(int $id) : string |
||
| 3190 | |||
| 3191 | /** |
||
| 3192 | * @param int $id |
||
| 3193 | * @param string $displayColumnValue |
||
| 3194 | * @return bool |
||
| 3195 | */ |
||
| 3196 | public function validIdDisplayNameCombo(int $id, $displayColumnValue) : bool |
||
| 3200 | |||
| 3201 | /** |
||
| 3202 | * @param array $toPopulate |
||
| 3203 | * @return stdClass |
||
| 3204 | */ |
||
| 3205 | protected function getEmptyObject(array $toPopulate=[]) : stdClass |
||
| 3211 | |||
| 3212 | /** |
||
| 3213 | * @param array $toPopulate |
||
| 3214 | * @return stdClass |
||
| 3215 | */ |
||
| 3216 | protected static function emptyObject(array $toPopulate=[]) : stdClass |
||
| 3222 | |||
| 3223 | /** |
||
| 3224 | * @param int $id |
||
| 3225 | * @return bool |
||
| 3226 | */ |
||
| 3227 | public static function isId(int $id) : bool |
||
| 3231 | |||
| 3232 | /** |
||
| 3233 | * @param int $cacheTtl |
||
| 3234 | * @return int |
||
| 3235 | */ |
||
| 3236 | public function activeCount(int $cacheTtl=self::CACHE_NO) : int |
||
| 3240 | |||
| 3241 | /** |
||
| 3242 | * @param string $tableAlias |
||
| 3243 | * @param string $columnName |
||
| 3244 | * @return FluentPdoModel|$this |
||
| 3245 | */ |
||
| 3246 | public function whereActive(string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3250 | |||
| 3251 | /** |
||
| 3252 | * @param string $tableAlias |
||
| 3253 | * @param string $columnName |
||
| 3254 | * @return FluentPdoModel|$this |
||
| 3255 | */ |
||
| 3256 | public function whereInactive(string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3260 | |||
| 3261 | /** |
||
| 3262 | * @param string $tableAlias |
||
| 3263 | * @param string $columnName |
||
| 3264 | * @return FluentPdoModel|$this |
||
| 3265 | */ |
||
| 3266 | public function whereArchived(string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
| 3270 | |||
| 3271 | /** |
||
| 3272 | * @param int $status |
||
| 3273 | * @param string $tableAlias |
||
| 3274 | * @param string $columnName |
||
| 3275 | * @return FluentPdoModel|$this |
||
| 3276 | */ |
||
| 3277 | public function whereStatus(int $status, string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3286 | |||
| 3287 | /** |
||
| 3288 | * @param int $id |
||
| 3289 | * @return int |
||
| 3290 | */ |
||
| 3291 | public function updateActive(int $id=0) : int |
||
| 3301 | |||
| 3302 | /** |
||
| 3303 | * @param int $id |
||
| 3304 | * @return int |
||
| 3305 | */ |
||
| 3306 | public function updateInactive(int $id=0) : int |
||
| 3315 | |||
| 3316 | /** |
||
| 3317 | * @param string $field |
||
| 3318 | * @param int $id |
||
| 3319 | * @return int |
||
| 3320 | */ |
||
| 3321 | public function updateNow(string $field, int $id=0) : int |
||
| 3327 | |||
| 3328 | /** |
||
| 3329 | * @param string $field |
||
| 3330 | * @param int $id |
||
| 3331 | * @return int |
||
| 3332 | */ |
||
| 3333 | public function updateToday($field, int $id=0) : int |
||
| 3339 | |||
| 3340 | /** |
||
| 3341 | * @param int $id |
||
| 3342 | * @return int |
||
| 3343 | */ |
||
| 3344 | public function updateDeleted(int $id=0) : int |
||
| 3357 | |||
| 3358 | /** |
||
| 3359 | * @param int $id |
||
| 3360 | * @return int |
||
| 3361 | */ |
||
| 3362 | public function updateArchived(int $id=0) : int |
||
| 3372 | |||
| 3373 | /** |
||
| 3374 | * @param int $status |
||
| 3375 | * @return int |
||
| 3376 | * @throws \Exception |
||
| 3377 | */ |
||
| 3378 | public function updateStatus(int $status) |
||
| 3384 | |||
| 3385 | /** |
||
| 3386 | * Return a YYYY-MM-DD HH:II:SS date format |
||
| 3387 | * |
||
| 3388 | * @param string $datetime - An english textual datetime description |
||
| 3389 | * now, yesterday, 3 days ago, +1 week |
||
| 3390 | * http://php.net/manual/en/function.strtotime.php |
||
| 3391 | * @return string YYYY-MM-DD HH:II:SS |
||
| 3392 | */ |
||
| 3393 | public static function NOW(string $datetime='now') : string |
||
| 3397 | |||
| 3398 | /** |
||
| 3399 | * Return a string containing the given number of question marks, |
||
| 3400 | * separated by commas. Eg '?, ?, ?' |
||
| 3401 | * |
||
| 3402 | * @param int - total of placeholder to insert |
||
| 3403 | * @return string |
||
| 3404 | */ |
||
| 3405 | protected function _makePlaceholders(int $numberOfPlaceholders=1) : string |
||
| 3409 | |||
| 3410 | /** |
||
| 3411 | * Format the table{Primary|Foreign}KeyName |
||
| 3412 | * |
||
| 3413 | * @param string $pattern |
||
| 3414 | * @param string $tableName |
||
| 3415 | * @return string |
||
| 3416 | */ |
||
| 3417 | protected function _formatKeyName(string $pattern, string $tableName) : string |
||
| 3421 | |||
| 3422 | /** |
||
| 3423 | * @param array $query |
||
| 3424 | * @param array $extraFields |
||
| 3425 | * @return array |
||
| 3426 | * @throws \Exception |
||
| 3427 | */ |
||
| 3428 | protected function _prepareApiResource(array $query=[], array $extraFields=[]) : array |
||
| 3449 | |||
| 3450 | /** |
||
| 3451 | * @param string $query |
||
| 3452 | * @param array $parameters |
||
| 3453 | * |
||
| 3454 | * @return array |
||
| 3455 | */ |
||
| 3456 | protected function _logQuery(string $query, array $parameters) : array |
||
| 3469 | |||
| 3470 | /** |
||
| 3471 | * @param string $ident |
||
| 3472 | * @param string $builtQuery |
||
| 3473 | */ |
||
| 3474 | protected function _logSlowQueries(string $ident, string $builtQuery) |
||
| 3487 | |||
| 3488 | /** |
||
| 3489 | * @return float |
||
| 3490 | */ |
||
| 3491 | public function getTimeTaken() : float |
||
| 3497 | |||
| 3498 | /** |
||
| 3499 | * @param $secs |
||
| 3500 | * @return FluentPdoModel|$this |
||
| 3501 | */ |
||
| 3502 | public function slowQuerySeconds(int $secs) : FluentPdoModel |
||
| 3509 | |||
| 3510 | |||
| 3511 | /** |
||
| 3512 | * @param $field |
||
| 3513 | * @param array $values |
||
| 3514 | * @param string $placeholderPrefix |
||
| 3515 | * |
||
| 3516 | * @return array |
||
| 3517 | */ |
||
| 3518 | public function getNamedWhereIn(string $field, array $values, string $placeholderPrefix='') : array |
||
| 3542 | |||
| 3543 | /** |
||
| 3544 | * @param string $field |
||
| 3545 | * @param string $delimiter |
||
| 3546 | * |
||
| 3547 | * @return array |
||
| 3548 | */ |
||
| 3549 | protected function _getColumnAliasParts(string $field, string $delimiter=':') : array |
||
| 3564 | |||
| 3565 | /** |
||
| 3566 | * @param string $column |
||
| 3567 | * @param string $term |
||
| 3568 | * @return FluentPdoModel|$this |
||
| 3569 | */ |
||
| 3570 | protected function _addWhereClause(string $column, string $term) : FluentPdoModel |
||
| 3623 | |||
| 3624 | /** |
||
| 3625 | * @param string $term |
||
| 3626 | * @return array |
||
| 3627 | */ |
||
| 3628 | public function parseWhereClause(string $term) : array |
||
| 3653 | |||
| 3654 | public function destroy() |
||
| 3663 | |||
| 3664 | public function __destruct() |
||
| 3668 | |||
| 3669 | /** |
||
| 3670 | * Load a model |
||
| 3671 | * |
||
| 3672 | * @param string $modelName |
||
| 3673 | * @param AbstractPdo $connection |
||
| 3674 | * @return FluentPdoModel|$this |
||
| 3675 | * @throws ModelNotFoundException |
||
| 3676 | */ |
||
| 3677 | public static function loadModel(string $modelName, AbstractPdo $connection=null) : FluentPdoModel |
||
| 3687 | |||
| 3688 | /** |
||
| 3689 | * Load a model |
||
| 3690 | * |
||
| 3691 | * @param string $tableName |
||
| 3692 | * @param AbstractPdo $connection |
||
| 3693 | * @return FluentPdoModel|$this |
||
| 3694 | */ |
||
| 3695 | public static function loadTable(string $tableName, AbstractPdo $connection=null) : FluentPdoModel |
||
| 3702 | |||
| 3703 | /** |
||
| 3704 | * @param string $columnName |
||
| 3705 | * @param int $cacheTtl |
||
| 3706 | * @param bool $flushCache |
||
| 3707 | * @return bool |
||
| 3708 | */ |
||
| 3709 | public function columnExists(string $columnName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3715 | |||
| 3716 | /** |
||
| 3717 | * @param string $foreignKeyName |
||
| 3718 | * @param int $cacheTtl |
||
| 3719 | * @param bool $flushCache |
||
| 3720 | * @return bool |
||
| 3721 | */ |
||
| 3722 | public function foreignKeyExists(string $foreignKeyName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3728 | |||
| 3729 | /** |
||
| 3730 | * @param string $indexName |
||
| 3731 | * @param int $cacheTtl |
||
| 3732 | * @param bool $flushCache |
||
| 3733 | * @return bool |
||
| 3734 | */ |
||
| 3735 | public function indexExists(string $indexName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3757 | |||
| 3758 | |||
| 3759 | |||
| 3760 | /** |
||
| 3761 | * @param int $cacheTtl |
||
| 3762 | * @param bool $flushCache |
||
| 3763 | * @return FluentPdoModel|$this |
||
| 3764 | */ |
||
| 3765 | public function loadSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : FluentPdoModel |
||
| 3772 | |||
| 3773 | /** |
||
| 3774 | * @param int $cacheTtl |
||
| 3775 | * @param bool $flushCache |
||
| 3776 | * @return Column[][] |
||
| 3777 | */ |
||
| 3778 | public function getSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3792 | |||
| 3793 | /** |
||
| 3794 | * @param int $cacheTtl |
||
| 3795 | * @param bool $flushCache |
||
| 3796 | * @return array |
||
| 3797 | */ |
||
| 3798 | public function getForeignKeysFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3811 | |||
| 3812 | /** |
||
| 3813 | * @param string $table |
||
| 3814 | * @param int $cacheTtl |
||
| 3815 | * @param bool $flushCache |
||
| 3816 | * @return Column[][] |
||
| 3817 | */ |
||
| 3818 | protected function _getColumnsByTableFromDb(string $table, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3834 | |||
| 3835 | /** |
||
| 3836 | * @param string $table |
||
| 3837 | * @param int $cacheTtl |
||
| 3838 | * @param bool $flushCache |
||
| 3839 | * @return Column[][] |
||
| 3840 | */ |
||
| 3841 | protected function _getForeignKeysByTableFromDb(string $table, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3857 | |||
| 3858 | /** |
||
| 3859 | * @param string $table |
||
| 3860 | * @return bool |
||
| 3861 | */ |
||
| 3862 | public function clearSchemaCache(string $table) : bool |
||
| 3866 | |||
| 3867 | /** |
||
| 3868 | * @param stdClass $record |
||
| 3869 | * @return stdClass |
||
| 3870 | */ |
||
| 3871 | public function cleanseRecord(stdClass $record) : stdClass |
||
| 3888 | |||
| 3889 | /** |
||
| 3890 | * @param stdClass $record |
||
| 3891 | * @param string $type |
||
| 3892 | * @return stdClass |
||
| 3893 | */ |
||
| 3894 | public function beforeSave(stdClass $record, string $type) : stdClass |
||
| 3903 | |||
| 3904 | /** |
||
| 3905 | * @param array $data |
||
| 3906 | * @param string $saveType |
||
| 3907 | * @return array |
||
| 3908 | */ |
||
| 3909 | public function cleanseWebData(array $data, string $saveType) : array |
||
| 3924 | |||
| 3925 | /** |
||
| 3926 | * @return array |
||
| 3927 | */ |
||
| 3928 | public function skeleton() : array |
||
| 3939 | |||
| 3940 | /** |
||
| 3941 | * @param bool $toString |
||
| 3942 | * @return array |
||
| 3943 | */ |
||
| 3944 | public function getErrors(bool $toString=false) : array |
||
| 3959 | |||
| 3960 | /** |
||
| 3961 | * @param bool $throw |
||
| 3962 | * @return FluentPdoModel|$this |
||
| 3963 | */ |
||
| 3964 | public function validationExceptions(bool $throw=true) : FluentPdoModel |
||
| 3970 | |||
| 3971 | /** |
||
| 3972 | * @param array $query array('_limit' => int, '_offset' => int, '_order' => string, '_fields' => string, _search) |
||
| 3973 | * |
||
| 3974 | * @return FluentPdoModel|$this |
||
| 3975 | * @throws Exception |
||
| 3976 | */ |
||
| 3977 | public function paginate(array $query=[]) : FluentPdoModel |
||
| 3991 | |||
| 3992 | /** |
||
| 3993 | * @param int $limit |
||
| 3994 | * @param int $offset |
||
| 3995 | * @return FluentPdoModel|$this |
||
| 3996 | */ |
||
| 3997 | protected function _setLimit(int $limit=0, int $offset=0) : FluentPdoModel |
||
| 4012 | |||
| 4013 | /** |
||
| 4014 | * @param array $fields |
||
| 4015 | * @return FluentPdoModel|$this |
||
| 4016 | * @throws Exception |
||
| 4017 | */ |
||
| 4018 | protected function _setFields(array $fields=[]) : FluentPdoModel |
||
| 4066 | |||
| 4067 | /** |
||
| 4068 | * @param string $orderBy |
||
| 4069 | * @return FluentPdoModel|$this|FluentPdoModel |
||
| 4070 | */ |
||
| 4071 | protected function _setOrderBy(string $orderBy='') : FluentPdoModel |
||
| 4108 | |||
| 4109 | /** |
||
| 4110 | * @return array |
||
| 4111 | */ |
||
| 4112 | public function getPagingMeta() |
||
| 4121 | |||
| 4122 | /** |
||
| 4123 | * @return FluentPdoModel|$this |
||
| 4124 | */ |
||
| 4125 | public function setPagingMeta() : FluentPdoModel |
||
| 4147 | |||
| 4148 | /** |
||
| 4149 | * Take a web request and format a query |
||
| 4150 | * |
||
| 4151 | * @param array $query |
||
| 4152 | * |
||
| 4153 | * @return FluentPdoModel|$this |
||
| 4154 | * @throws Exception |
||
| 4155 | */ |
||
| 4156 | public function filter(array $query=[]) : FluentPdoModel |
||
| 4226 | |||
| 4227 | /** |
||
| 4228 | * @param string $column |
||
| 4229 | * @param string $displayCol |
||
| 4230 | * @return string|null |
||
| 4231 | */ |
||
| 4232 | protected function _findFieldByQuery(string $column, string $displayCol) |
||
| 4279 | |||
| 4280 | /** |
||
| 4281 | * @param $keysOnly |
||
| 4282 | * @return array |
||
| 4283 | */ |
||
| 4284 | |||
| 4285 | public function columns(bool $keysOnly=true) : array |
||
| 4289 | |||
| 4290 | /** |
||
| 4291 | * @param string $field |
||
| 4292 | * @param mixed $value |
||
| 4293 | * @param array $pdoMetaData |
||
| 4294 | * @return float|int |
||
| 4295 | * @throws Exception |
||
| 4296 | */ |
||
| 4297 | protected function _fixTypeToSentinel(string $field, $value, array $pdoMetaData=[]) |
||
| 4352 | |||
| 4353 | /** |
||
| 4354 | * @param string $field |
||
| 4355 | * @param mixed $value |
||
| 4356 | * @param bool|false $permissive |
||
| 4357 | * @return float|int|null|string |
||
| 4358 | */ |
||
| 4359 | protected function _fixType(string $field, $value, bool $permissive=false) |
||
| 4410 | |||
| 4411 | /** |
||
| 4412 | * @param stdClass $record |
||
| 4413 | * @param string $type |
||
| 4414 | * @return stdClass |
||
| 4415 | */ |
||
| 4416 | public function fixTypesToSentinel(stdClass $record, string $type='') : stdClass |
||
| 4443 | |||
| 4444 | /** |
||
| 4445 | * @param stdClass $record |
||
| 4446 | * @param string $type |
||
| 4447 | * @return stdClass |
||
| 4448 | * @throws Exception |
||
| 4449 | */ |
||
| 4450 | public function applyHandlers(stdClass $record, string $type='INSERT') : stdClass |
||
| 4478 | |||
| 4479 | |||
| 4480 | /** |
||
| 4481 | * @param stdClass $record |
||
| 4482 | * @param array $fields |
||
| 4483 | * @param string $type |
||
| 4484 | * @return bool |
||
| 4485 | */ |
||
| 4486 | protected function uniqueCheck(stdClass $record, array $fields, string $type) : bool |
||
| 4499 | |||
| 4500 | /** |
||
| 4501 | * @param string $field |
||
| 4502 | * @param mixed $value |
||
| 4503 | * @param string $type |
||
| 4504 | * @param stdClass $record |
||
| 4505 | * @return null |
||
| 4506 | * @throws Exception |
||
| 4507 | */ |
||
| 4508 | protected function applyHandler(string $field, $value, string $type='', stdClass $record=null) |
||
| 4532 | |||
| 4533 | /** |
||
| 4534 | * @param string $start |
||
| 4535 | * @param string $end |
||
| 4536 | * @param string $hayStack |
||
| 4537 | * @return mixed |
||
| 4538 | */ |
||
| 4539 | public static function between(string $start, string $end, string $hayStack) : string |
||
| 4543 | |||
| 4544 | /** |
||
| 4545 | * @param string $needle |
||
| 4546 | * @param string $hayStack |
||
| 4547 | * @param bool $returnOrigIfNeedleNotExists |
||
| 4548 | * @return mixed |
||
| 4549 | */ |
||
| 4550 | public static function before(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
| 4560 | |||
| 4561 | /** |
||
| 4562 | * @param string $needle |
||
| 4563 | * @param string $hayStack |
||
| 4564 | * @param bool $returnOrigIfNeedleNotExists |
||
| 4565 | * @return string |
||
| 4566 | */ |
||
| 4567 | public static function after(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
| 4576 | |||
| 4577 | /** |
||
| 4578 | * @return int |
||
| 4579 | */ |
||
| 4580 | public function getUserId() |
||
| 4584 | |||
| 4585 | /** |
||
| 4586 | * @param string $entity |
||
| 4587 | * @param int $id |
||
| 4588 | * @return int |
||
| 4589 | */ |
||
| 4590 | public function getMaskByResourceAndId(string $entity, int $id) : int |
||
| 4594 | |||
| 4595 | /** |
||
| 4596 | * @param string|int|null $time |
||
| 4597 | * @return string |
||
| 4598 | */ |
||
| 4599 | public static function date($time=null) : string |
||
| 4603 | |||
| 4604 | /** |
||
| 4605 | * @param string|int|null $time |
||
| 4606 | * @return string |
||
| 4607 | */ |
||
| 4608 | public static function dateTime($time=null) : string |
||
| 4612 | |||
| 4613 | /** |
||
| 4614 | * @param string|int|null $time |
||
| 4615 | * @return string |
||
| 4616 | */ |
||
| 4617 | public static function atom($time=null) : string |
||
| 4621 | |||
| 4622 | /** |
||
| 4623 | * @param string|int|null $time |
||
| 4624 | * @return int |
||
| 4625 | */ |
||
| 4626 | public static function getTime($time=null) : int |
||
| 4639 | |||
| 4640 | /** |
||
| 4641 | * @param int $id |
||
| 4642 | * @param int $cacheTtl |
||
| 4643 | * @return string |
||
| 4644 | */ |
||
| 4645 | public function getCodeById(int $id, int $cacheTtl=self::ONE_DAY) : string |
||
| 4653 | |||
| 4654 | /** |
||
| 4655 | * @param array $authUserRoles |
||
| 4656 | * @param int $authUserId |
||
| 4657 | * @return FluentPdoModel |
||
| 4658 | */ |
||
| 4659 | public function applyRoleFilter(array $authUserRoles, int $authUserId) : FluentPdoModel |
||
| 4663 | |||
| 4664 | /** |
||
| 4665 | * @param int $id |
||
| 4666 | * @param string[] $authUserRoles |
||
| 4667 | * @param int $authUserId |
||
| 4668 | * @return bool |
||
| 4669 | */ |
||
| 4670 | public function canAccessIdWithRole(int $id, array $authUserRoles, int $authUserId) : bool |
||
| 4674 | } |
||
| 4675 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.