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 $primaryKey = 'id'; |
||
| 71 | |||
| 72 | /** @var array */ |
||
| 73 | protected $whereParameters = []; |
||
| 74 | |||
| 75 | /** @var array */ |
||
| 76 | protected $selectFields = []; |
||
| 77 | |||
| 78 | /** @var array */ |
||
| 79 | protected $joinSources = []; |
||
| 80 | |||
| 81 | /** @var array */ |
||
| 82 | protected $joinAliases = []; |
||
| 83 | |||
| 84 | /** @var array $associations */ |
||
| 85 | protected $associations = [ |
||
| 86 | 'belongsTo' => [], |
||
| 87 | ]; |
||
| 88 | |||
| 89 | /** @var array */ |
||
| 90 | protected $whereConditions = []; |
||
| 91 | |||
| 92 | /** @var string */ |
||
| 93 | protected $rawSql = ''; |
||
| 94 | |||
| 95 | /** @var int */ |
||
| 96 | protected $limit = 0; |
||
| 97 | |||
| 98 | /** @var int */ |
||
| 99 | protected $offset = 0; |
||
| 100 | |||
| 101 | /** @var array */ |
||
| 102 | protected $orderBy = []; |
||
| 103 | |||
| 104 | /** @var array */ |
||
| 105 | protected $groupBy = []; |
||
| 106 | |||
| 107 | /** @var string */ |
||
| 108 | protected $andOrOperator = self::OPERATOR_AND; |
||
| 109 | |||
| 110 | /** @var array */ |
||
| 111 | protected $having = []; |
||
| 112 | |||
| 113 | /** @var bool */ |
||
| 114 | protected $wrapOpen = false; |
||
| 115 | |||
| 116 | /** @var int */ |
||
| 117 | protected $lastWrapPosition = 0; |
||
| 118 | |||
| 119 | /** @var PDOStatement $pdoStmt */ |
||
| 120 | protected $pdoStmt = null; |
||
| 121 | |||
| 122 | /** @var bool */ |
||
| 123 | protected $distinct = false; |
||
| 124 | |||
| 125 | /** @var null */ |
||
| 126 | protected $requestedFields = []; |
||
| 127 | |||
| 128 | /** @var null */ |
||
| 129 | protected $filterMeta = []; |
||
| 130 | |||
| 131 | /** @var bool */ |
||
| 132 | protected $logQueries = false; |
||
| 133 | |||
| 134 | /** @var array */ |
||
| 135 | protected $timer = []; |
||
| 136 | |||
| 137 | /** @var int */ |
||
| 138 | protected $slowQuerySecs = 5; |
||
| 139 | |||
| 140 | /** @var array */ |
||
| 141 | protected $paginationAttribs = [ |
||
| 142 | '_limit', |
||
| 143 | '_offset', |
||
| 144 | '_order', |
||
| 145 | '_fields', |
||
| 146 | '_search' |
||
| 147 | ]; |
||
| 148 | |||
| 149 | /** @var string $tableName */ |
||
| 150 | protected $tableName = ''; |
||
| 151 | |||
| 152 | /** @var string $tableAlias */ |
||
| 153 | protected $tableAlias = ''; |
||
| 154 | |||
| 155 | /** @var string $displayColumn */ |
||
| 156 | protected $displayColumn = ''; |
||
| 157 | |||
| 158 | /** @var string $connectionName */ |
||
| 159 | protected $connectionName = ''; |
||
| 160 | |||
| 161 | /** @var array $schema */ |
||
| 162 | protected $schema = []; |
||
| 163 | |||
| 164 | /** @var array $virtualFields */ |
||
| 165 | protected $virtualFields = []; |
||
| 166 | |||
| 167 | /** @var array $errors */ |
||
| 168 | protected $errors = []; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @var int - true = connection default x days |
||
| 172 | * - false = no cache |
||
| 173 | * - int = a specific amount |
||
| 174 | */ |
||
| 175 | protected $cacheTtl = self::CACHE_NO; |
||
| 176 | |||
| 177 | /** @var array */ |
||
| 178 | protected $flushCacheTables = []; |
||
| 179 | |||
| 180 | /** @var string */ |
||
| 181 | protected $tmpTablePrefix = 'tmp_'; |
||
| 182 | |||
| 183 | /** @var null|string */ |
||
| 184 | protected $builtQuery = ''; |
||
| 185 | |||
| 186 | /** @var array */ |
||
| 187 | protected $handlers = []; |
||
| 188 | |||
| 189 | /** @var bool User want to directly specify the fields */ |
||
| 190 | protected $explicitSelectMode = false; |
||
| 191 | |||
| 192 | /** @var string[] */ |
||
| 193 | protected $updateRaw = []; |
||
| 194 | |||
| 195 | /** @var int */ |
||
| 196 | protected $maxCallbackFails = -1; |
||
| 197 | |||
| 198 | /** @var int */ |
||
| 199 | protected $numCallbackFails = 0; |
||
| 200 | |||
| 201 | /** @var bool */ |
||
| 202 | protected $filterOnFetch = false; |
||
| 203 | |||
| 204 | /** @var bool */ |
||
| 205 | protected $logFilterChanges = true; |
||
| 206 | |||
| 207 | /** @var bool */ |
||
| 208 | protected $includeCount = false; |
||
| 209 | |||
| 210 | /** @var string */ |
||
| 211 | static protected $modelNamespace = ''; |
||
| 212 | |||
| 213 | /** @var bool */ |
||
| 214 | protected $validationExceptions = true; |
||
| 215 | |||
| 216 | /** @var array */ |
||
| 217 | protected $pagingMeta = []; |
||
| 218 | |||
| 219 | /** @var bool */ |
||
| 220 | protected $softDeletes = true; |
||
| 221 | |||
| 222 | /** @var bool */ |
||
| 223 | protected $allowMetaOverride = false; |
||
| 224 | |||
| 225 | /** @var bool */ |
||
| 226 | protected $skipMetaUpdates = false; |
||
| 227 | |||
| 228 | /** @var bool */ |
||
| 229 | protected $addUpdateAlias = false; |
||
| 230 | |||
| 231 | /** @var int */ |
||
| 232 | protected $defaultMax = 250; |
||
| 233 | |||
| 234 | /** @var array */ |
||
| 235 | protected $removeUnauthorisedFields = []; |
||
| 236 | |||
| 237 | /** @var bool */ |
||
| 238 | protected $canGenericUpdate = true; |
||
| 239 | |||
| 240 | /** @var bool */ |
||
| 241 | protected $canGenericCreate = true; |
||
| 242 | |||
| 243 | /** @var bool */ |
||
| 244 | protected $canGenericDelete = true; |
||
| 245 | |||
| 246 | /** @var array */ |
||
| 247 | protected $rowMetaData = []; |
||
| 248 | |||
| 249 | /** @var array */ |
||
| 250 | protected $excludedSearchCols = []; |
||
| 251 | |||
| 252 | |||
| 253 | /** @var array */ |
||
| 254 | protected $globalRemoveUnauthorisedFields = [ |
||
| 255 | '/global_table_meta#view' => [ |
||
| 256 | self::CREATOR_ID_FIELD, |
||
| 257 | self::CREATOR_FIELD, |
||
| 258 | self::CREATED_TS_FIELD, |
||
| 259 | self::MODIFIER_ID_FIELD, |
||
| 260 | self::MODIFIER_FIELD, |
||
| 261 | self::MODIFIED_TS_FIELD, |
||
| 262 | self::STATUS_FIELD, |
||
| 263 | ], |
||
| 264 | ]; |
||
| 265 | |||
| 266 | |||
| 267 | /** |
||
| 268 | * @param AbstractPdo|null $connection |
||
| 269 | */ |
||
| 270 | public function __construct(AbstractPdo $connection=null) |
||
| 277 | |||
| 278 | public function init() |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @return AbstractPdo |
||
| 283 | * @throws Exception |
||
| 284 | */ |
||
| 285 | public function getPdo() : AbstractPdo |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @return LoggerInterface |
||
| 292 | */ |
||
| 293 | public function getLogger() : LoggerInterface |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @return CacheInterface |
||
| 300 | */ |
||
| 301 | public function getCache() : CacheInterface |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Define the working table and create a new instance |
||
| 308 | * |
||
| 309 | * @param string $tableName - Table name |
||
| 310 | * @param string $alias - The table alias name |
||
| 311 | * @param string $displayColumn |
||
| 312 | * @param string $primaryKeyName |
||
| 313 | * |
||
| 314 | * @return FluentPdoModel|$this |
||
| 315 | */ |
||
| 316 | public function table(string $tableName, string $alias='', string $displayColumn='', string $primaryKeyName='id') : FluentPdoModel |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @param string $primaryKeyName |
||
| 327 | * @return FluentPdoModel|$this |
||
| 328 | */ |
||
| 329 | public function primaryKeyName(string $primaryKeyName) : FluentPdoModel |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @param string $tableName |
||
| 338 | * |
||
| 339 | * @return FluentPdoModel|$this |
||
| 340 | */ |
||
| 341 | public function tableName(string $tableName) : FluentPdoModel |
||
| 347 | |||
| 348 | /** |
||
| 349 | * @param $explicitSelect |
||
| 350 | * |
||
| 351 | * @return FluentPdoModel|$this |
||
| 352 | */ |
||
| 353 | public function explicitSelectMode(bool $explicitSelect=true) : FluentPdoModel |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @param bool $filterOnFetch |
||
| 362 | * |
||
| 363 | * @return FluentPdoModel|$this |
||
| 364 | */ |
||
| 365 | public function filterOnFetch(bool $filterOnFetch=true) : FluentPdoModel |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @param bool $logFilterChanges |
||
| 374 | * |
||
| 375 | * @return FluentPdoModel|$this |
||
| 376 | */ |
||
| 377 | public function logFilterChanges(bool $logFilterChanges=true) : FluentPdoModel |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Return the name of the table |
||
| 386 | * |
||
| 387 | * @return string |
||
| 388 | */ |
||
| 389 | public function getTableName() : string |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @return string |
||
| 396 | */ |
||
| 397 | public function getDisplayColumn() : string |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Set the display column |
||
| 404 | * |
||
| 405 | * @param string $column |
||
| 406 | * |
||
| 407 | * @return FluentPdoModel|$this |
||
| 408 | */ |
||
| 409 | public function displayColumn(string $column) : FluentPdoModel |
||
| 415 | /** |
||
| 416 | * Set the table alias |
||
| 417 | * |
||
| 418 | * @param string $alias |
||
| 419 | * |
||
| 420 | * @return FluentPdoModel|$this |
||
| 421 | */ |
||
| 422 | public function tableAlias(string $alias) : FluentPdoModel |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @param int $cacheTtl |
||
| 431 | * @return FluentPdoModel|$this |
||
| 432 | * @throws Exception |
||
| 433 | */ |
||
| 434 | protected function cacheTtl(int $cacheTtl) : FluentPdoModel |
||
| 445 | |||
| 446 | /** |
||
| 447 | * @return string |
||
| 448 | */ |
||
| 449 | public function getTableAlias() : string |
||
| 453 | |||
| 454 | /** |
||
| 455 | * @param array $associations |
||
| 456 | * |
||
| 457 | * @return FluentPdoModel|$this |
||
| 458 | */ |
||
| 459 | public function associations(array $associations) : FluentPdoModel |
||
| 465 | |||
| 466 | /** |
||
| 467 | * @param string $alias |
||
| 468 | * @param array $definition |
||
| 469 | * @return FluentPdoModel|$this |
||
| 470 | */ |
||
| 471 | public function setBelongsTo(string $alias, array $definition) : FluentPdoModel |
||
| 480 | |||
| 481 | /** |
||
| 482 | * @param $alias |
||
| 483 | * @param $displayField |
||
| 484 | * @return FluentPdoModel|$this |
||
| 485 | * @throws \Terah\Assert\AssertionFailedException |
||
| 486 | */ |
||
| 487 | public function setBelongsToDisplayField(string $alias, string $displayField) : FluentPdoModel |
||
| 497 | |||
| 498 | /** |
||
| 499 | * @param PDOStatement $stmt |
||
| 500 | * @param Closure $fnCallback |
||
| 501 | * @return bool|stdClass |
||
| 502 | */ |
||
| 503 | public function fetchRow(PDOStatement $stmt, Closure $fnCallback=null) |
||
| 526 | |||
| 527 | /** |
||
| 528 | * @param PDOStatement $stmt |
||
| 529 | * @param $record |
||
| 530 | * @return array |
||
| 531 | */ |
||
| 532 | protected function getColumnMeta(PDOStatement $stmt, $record) : array |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @param array $schema |
||
| 554 | * |
||
| 555 | * @return FluentPdoModel|$this |
||
| 556 | */ |
||
| 557 | public function schema(array $schema) : FluentPdoModel |
||
| 563 | |||
| 564 | /** |
||
| 565 | * @param string|array $field |
||
| 566 | * @param $type |
||
| 567 | * @return FluentPdoModel|$this |
||
| 568 | */ |
||
| 569 | public function addSchema($field, string $type) : FluentPdoModel |
||
| 585 | |||
| 586 | /** |
||
| 587 | * @param bool $getForeign |
||
| 588 | * @return array |
||
| 589 | */ |
||
| 590 | public function getSchema(bool $getForeign=false) : array |
||
| 601 | |||
| 602 | /** |
||
| 603 | * @param $keysOnly |
||
| 604 | * @return array |
||
| 605 | */ |
||
| 606 | public function getColumns(bool $keysOnly=true) : array |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Get the primary key name |
||
| 615 | * |
||
| 616 | * @return string |
||
| 617 | */ |
||
| 618 | public function getPrimaryKeyName() : string |
||
| 622 | |||
| 623 | /** |
||
| 624 | * @param string $query |
||
| 625 | * @param array $parameters |
||
| 626 | * |
||
| 627 | * @return bool |
||
| 628 | * @throws Exception |
||
| 629 | */ |
||
| 630 | public function execute(string $query, array $parameters=[]) : bool |
||
| 666 | |||
| 667 | /** |
||
| 668 | * @param string $query |
||
| 669 | * @param array $params |
||
| 670 | * @return FluentPdoModel|$this |
||
| 671 | */ |
||
| 672 | public function query(string $query, array $params=[]) : FluentPdoModel |
||
| 679 | |||
| 680 | /** |
||
| 681 | * @param string $sql |
||
| 682 | * @param array $params |
||
| 683 | * |
||
| 684 | * @return string |
||
| 685 | */ |
||
| 686 | public function buildQuery(string $sql, array $params=[]) : string |
||
| 714 | |||
| 715 | /** |
||
| 716 | * @param stdClass $record |
||
| 717 | * |
||
| 718 | * @return stdClass |
||
| 719 | */ |
||
| 720 | protected function trimAndLowerCaseKeys(stdClass $record) : stdClass |
||
| 731 | |||
| 732 | /** |
||
| 733 | * Return the number of affected row by the last statement |
||
| 734 | * |
||
| 735 | * @return int |
||
| 736 | */ |
||
| 737 | public function rowCount() : int |
||
| 743 | |||
| 744 | /** |
||
| 745 | * @return PDOStatement |
||
| 746 | * @throws PDOException |
||
| 747 | */ |
||
| 748 | public function fetchStmt() |
||
| 757 | |||
| 758 | /** |
||
| 759 | * @return array |
||
| 760 | */ |
||
| 761 | public function fetchSqlQuery() : array |
||
| 771 | |||
| 772 | /** |
||
| 773 | * @param string $tableName |
||
| 774 | * @param bool $dropIfExists |
||
| 775 | * @param array $indexes |
||
| 776 | * @return boolean |
||
| 777 | * @throws Exception |
||
| 778 | */ |
||
| 779 | public function fetchIntoMemoryTable(string $tableName, bool $dropIfExists=true, array $indexes=[]) : bool |
||
| 801 | |||
| 802 | /** |
||
| 803 | * @param string $keyedOn |
||
| 804 | * @param int $cacheTtl |
||
| 805 | * @return stdClass[] |
||
| 806 | */ |
||
| 807 | public function fetch(string $keyedOn='', int $cacheTtl=self::CACHE_NO) : array |
||
| 845 | |||
| 846 | /** |
||
| 847 | * @return string |
||
| 848 | */ |
||
| 849 | protected function parseWhereForPrimaryLookup() : string |
||
| 865 | |||
| 866 | /** |
||
| 867 | * @param string $cacheKey |
||
| 868 | * @param Closure $func |
||
| 869 | * @param int $cacheTtl - 0 for default ttl, -1 for no cache or int for custom ttl |
||
| 870 | * @return mixed |
||
| 871 | */ |
||
| 872 | protected function cacheData(string $cacheKey, Closure $func, int $cacheTtl=self::CACHE_DEFAULT) |
||
| 910 | |||
| 911 | /** |
||
| 912 | * @param string $cacheKey |
||
| 913 | * @return bool |
||
| 914 | */ |
||
| 915 | public function clearCache(string $cacheKey) : bool |
||
| 919 | |||
| 920 | /** |
||
| 921 | * @param string $table |
||
| 922 | * @return bool |
||
| 923 | */ |
||
| 924 | public function clearCacheByTable(string $table='') : bool |
||
| 934 | |||
| 935 | /** |
||
| 936 | * @return string[] |
||
| 937 | */ |
||
| 938 | public function getFlushCacheTables() : array |
||
| 942 | |||
| 943 | /** |
||
| 944 | * @param Closure $fnCallback |
||
| 945 | * @return int |
||
| 946 | */ |
||
| 947 | public function fetchCallback(Closure $fnCallback) : int |
||
| 958 | |||
| 959 | /** |
||
| 960 | * @param Closure $fnCallback |
||
| 961 | * @param string $keyedOn |
||
| 962 | * @return array |
||
| 963 | */ |
||
| 964 | public function fetchObjectsByCallback(Closure $fnCallback, string $keyedOn='') : array |
||
| 982 | |||
| 983 | /** |
||
| 984 | * @param $numFailures |
||
| 985 | * @return FluentPdoModel|$this |
||
| 986 | */ |
||
| 987 | public function maxCallbackFailures(int $numFailures) : FluentPdoModel |
||
| 994 | |||
| 995 | /** |
||
| 996 | * @param PDOStatement $stmt |
||
| 997 | * @param Closure $fnCallback |
||
| 998 | * @param int $successCnt |
||
| 999 | * @return bool|null|stdClass |
||
| 1000 | */ |
||
| 1001 | protected function tallySuccessCount(PDOStatement $stmt, Closure $fnCallback, int &$successCnt) |
||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * @return bool |
||
| 1037 | */ |
||
| 1038 | public function canGenericUpdate() : bool |
||
| 1042 | |||
| 1043 | /** |
||
| 1044 | * @return bool |
||
| 1045 | */ |
||
| 1046 | public function canGenericCreate() : bool |
||
| 1050 | |||
| 1051 | /** |
||
| 1052 | * @return bool |
||
| 1053 | */ |
||
| 1054 | public function canGenericDelete() : bool |
||
| 1058 | |||
| 1059 | /** |
||
| 1060 | * @param string $keyedOn |
||
| 1061 | * @param string $valueField |
||
| 1062 | * @param int $cacheTtl |
||
| 1063 | * @return mixed |
||
| 1064 | */ |
||
| 1065 | public function fetchList(string $keyedOn='', string $valueField='', int $cacheTtl=self::CACHE_NO) : array |
||
| 1127 | |||
| 1128 | /** |
||
| 1129 | * @param string $column |
||
| 1130 | * @param int $cacheTtl |
||
| 1131 | * @param bool|true $unique |
||
| 1132 | * @return array |
||
| 1133 | */ |
||
| 1134 | public function fetchColumn(string $column, int $cacheTtl=self::CACHE_NO, bool $unique=true) : array |
||
| 1144 | |||
| 1145 | /** |
||
| 1146 | * @param string $field |
||
| 1147 | * @param int $itemId |
||
| 1148 | * @param int $cacheTtl |
||
| 1149 | * @return mixed|null |
||
| 1150 | */ |
||
| 1151 | public function fetchField(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * @param string $field |
||
| 1175 | * @param int $itemId |
||
| 1176 | * @param int $cacheTtl |
||
| 1177 | * @return string |
||
| 1178 | */ |
||
| 1179 | public function fetchStr(string $field='', $itemId=0, int $cacheTtl=self::CACHE_NO) : string |
||
| 1183 | |||
| 1184 | /** |
||
| 1185 | * @param int $cacheTtl |
||
| 1186 | * @return int |
||
| 1187 | */ |
||
| 1188 | public function fetchId(int $cacheTtl=self::CACHE_NO) : int |
||
| 1192 | |||
| 1193 | /** |
||
| 1194 | * @param string $field |
||
| 1195 | * @param int $itemId |
||
| 1196 | * @param int $cacheTtl |
||
| 1197 | * @return int |
||
| 1198 | */ |
||
| 1199 | public function fetchInt(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : int |
||
| 1203 | |||
| 1204 | /** |
||
| 1205 | * @param string $field |
||
| 1206 | * @param int $itemId |
||
| 1207 | * @param int $cacheTtl |
||
| 1208 | * @return float |
||
| 1209 | */ |
||
| 1210 | public function fetchFloat(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : float |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * @param string $field |
||
| 1217 | * @param int $itemId |
||
| 1218 | * @param int $cacheTtl |
||
| 1219 | * @return bool |
||
| 1220 | */ |
||
| 1221 | public function fetchBool(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : bool |
||
| 1225 | |||
| 1226 | /** |
||
| 1227 | * @param int|null $id |
||
| 1228 | * @param int $cacheTtl |
||
| 1229 | * @return stdClass|bool |
||
| 1230 | */ |
||
| 1231 | public function fetchOne(int $id=0, int $cacheTtl=self::CACHE_NO) |
||
| 1243 | |||
| 1244 | /** |
||
| 1245 | * @param int|null $id |
||
| 1246 | * @param int $cacheTtl |
||
| 1247 | * @return boolean |
||
| 1248 | */ |
||
| 1249 | public function fetchExists(int $id=0, int $cacheTtl=self::CACHE_NO) : bool |
||
| 1259 | |||
| 1260 | /*------------------------------------------------------------------------------ |
||
| 1261 | Fluent Query Builder |
||
| 1262 | *-----------------------------------------------------------------------------*/ |
||
| 1263 | |||
| 1264 | /** |
||
| 1265 | * Create the select clause |
||
| 1266 | * |
||
| 1267 | * @param mixed $columns - the column to select. Can be string or array of fields |
||
| 1268 | * @param string $alias - an alias to the column |
||
| 1269 | * @param boolean $explicitSelect |
||
| 1270 | * @return FluentPdoModel|$this |
||
| 1271 | */ |
||
| 1272 | public function select($columns='*', string $alias='', bool $explicitSelect=true) : FluentPdoModel |
||
| 1315 | |||
| 1316 | /** |
||
| 1317 | * @param string $select |
||
| 1318 | * @return FluentPdoModel|$this |
||
| 1319 | */ |
||
| 1320 | public function selectRaw(string $select) : FluentPdoModel |
||
| 1326 | |||
| 1327 | /** |
||
| 1328 | * @param bool $logQueries |
||
| 1329 | * |
||
| 1330 | * @return FluentPdoModel|$this |
||
| 1331 | */ |
||
| 1332 | public function logQueries(bool $logQueries=true) : FluentPdoModel |
||
| 1338 | |||
| 1339 | /** |
||
| 1340 | * @param bool $includeCnt |
||
| 1341 | * |
||
| 1342 | * @return FluentPdoModel|$this |
||
| 1343 | */ |
||
| 1344 | public function includeCount(bool $includeCnt=true) : FluentPdoModel |
||
| 1350 | |||
| 1351 | /** |
||
| 1352 | * @param bool $distinct |
||
| 1353 | * |
||
| 1354 | * @return FluentPdoModel|$this |
||
| 1355 | */ |
||
| 1356 | public function distinct(bool $distinct=true) : FluentPdoModel |
||
| 1362 | |||
| 1363 | /** |
||
| 1364 | * @param array $fields |
||
| 1365 | * @return FluentPdoModel|$this |
||
| 1366 | */ |
||
| 1367 | public function withBelongsTo(array $fields=[]) : FluentPdoModel |
||
| 1381 | |||
| 1382 | /** |
||
| 1383 | * @param string $alias |
||
| 1384 | * @param bool $addSelectField |
||
| 1385 | * @return FluentPdoModel |
||
| 1386 | */ |
||
| 1387 | public function autoInnerJoin(string $alias, bool $addSelectField=true) : FluentPdoModel |
||
| 1391 | |||
| 1392 | /** |
||
| 1393 | * @param string $alias |
||
| 1394 | * @param string $type |
||
| 1395 | * @param bool $addSelectField |
||
| 1396 | * @return FluentPdoModel|$this |
||
| 1397 | */ |
||
| 1398 | public function autoJoin(string $alias, string $type=self::LEFT_JOIN, bool $addSelectField=true) : FluentPdoModel |
||
| 1425 | |||
| 1426 | /** |
||
| 1427 | * @param array $conditions |
||
| 1428 | * @return FluentPdoModel |
||
| 1429 | */ |
||
| 1430 | public function whereArr(array $conditions) : FluentPdoModel |
||
| 1439 | /** |
||
| 1440 | * Add where condition, more calls appends with AND |
||
| 1441 | * |
||
| 1442 | * @param string $condition possibly containing ? or :name |
||
| 1443 | * @param mixed $parameters accepted by PDOStatement::execute or a scalar value |
||
| 1444 | * @param mixed ... |
||
| 1445 | * @return FluentPdoModel|$this |
||
| 1446 | */ |
||
| 1447 | public function where($condition, $parameters=[]) : FluentPdoModel |
||
| 1496 | |||
| 1497 | /** |
||
| 1498 | * Create an AND operator in the where clause |
||
| 1499 | * |
||
| 1500 | * @return FluentPdoModel|$this |
||
| 1501 | */ |
||
| 1502 | public function _and() : FluentPdoModel |
||
| 1516 | |||
| 1517 | |||
| 1518 | /** |
||
| 1519 | * Create an OR operator in the where clause |
||
| 1520 | * |
||
| 1521 | * @return FluentPdoModel|$this |
||
| 1522 | */ |
||
| 1523 | public function _or() : FluentPdoModel |
||
| 1537 | |||
| 1538 | /** |
||
| 1539 | * To group multiple where clauses together. |
||
| 1540 | * |
||
| 1541 | * @return FluentPdoModel|$this |
||
| 1542 | */ |
||
| 1543 | public function wrap() : FluentPdoModel |
||
| 1553 | |||
| 1554 | /** |
||
| 1555 | * Where Primary key |
||
| 1556 | * |
||
| 1557 | * @param int $id |
||
| 1558 | * @param bool $addAlias |
||
| 1559 | * |
||
| 1560 | * @return FluentPdoModel|$this |
||
| 1561 | */ |
||
| 1562 | public function wherePk(int $id, bool $addAlias=true) : FluentPdoModel |
||
| 1568 | |||
| 1569 | /** |
||
| 1570 | * @param string $name |
||
| 1571 | * @param bool $addAlias |
||
| 1572 | * @return FluentPdoModel |
||
| 1573 | */ |
||
| 1574 | public function whereDisplayName(string $name, bool $addAlias=true) : FluentPdoModel |
||
| 1580 | |||
| 1581 | /** |
||
| 1582 | * WHERE $columnName != $value |
||
| 1583 | * |
||
| 1584 | * @param string $columnName |
||
| 1585 | * @param mixed $value |
||
| 1586 | * @return FluentPdoModel|$this |
||
| 1587 | */ |
||
| 1588 | public function whereNot(string $columnName, $value) : FluentPdoModel |
||
| 1592 | /** |
||
| 1593 | * WHERE $columnName != $value |
||
| 1594 | * |
||
| 1595 | * @param string $columnName |
||
| 1596 | * @param mixed $value |
||
| 1597 | * @return FluentPdoModel|$this |
||
| 1598 | */ |
||
| 1599 | public function whereCoercedNot(string $columnName, $value) : FluentPdoModel |
||
| 1603 | |||
| 1604 | /** |
||
| 1605 | * WHERE $columnName LIKE $value |
||
| 1606 | * |
||
| 1607 | * @param string $columnName |
||
| 1608 | * @param mixed $value |
||
| 1609 | * @return FluentPdoModel|$this |
||
| 1610 | */ |
||
| 1611 | public function whereLike(string $columnName, $value) : FluentPdoModel |
||
| 1615 | |||
| 1616 | /** |
||
| 1617 | * @param string $columnName |
||
| 1618 | * @param mixed $value1 |
||
| 1619 | * @param mixed $value2 |
||
| 1620 | * @return FluentPdoModel|$this |
||
| 1621 | */ |
||
| 1622 | public function whereBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
| 1629 | |||
| 1630 | /** |
||
| 1631 | * @param string $columnName |
||
| 1632 | * @param mixed $value1 |
||
| 1633 | * @param mixed $value2 |
||
| 1634 | * @return FluentPdoModel|$this |
||
| 1635 | */ |
||
| 1636 | public function whereNotBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
| 1643 | |||
| 1644 | /** |
||
| 1645 | * @param string $columnName |
||
| 1646 | * @param string $regex |
||
| 1647 | * @return FluentPdoModel|$this |
||
| 1648 | */ |
||
| 1649 | public function whereRegex(string $columnName, string $regex) : FluentPdoModel |
||
| 1653 | |||
| 1654 | /** |
||
| 1655 | * @param string $columnName |
||
| 1656 | * @param string $regex |
||
| 1657 | * @return FluentPdoModel|$this |
||
| 1658 | */ |
||
| 1659 | public function whereNotRegex(string $columnName, string $regex) : FluentPdoModel |
||
| 1663 | |||
| 1664 | /** |
||
| 1665 | * WHERE $columnName NOT LIKE $value |
||
| 1666 | * |
||
| 1667 | * @param string $columnName |
||
| 1668 | * @param string $value |
||
| 1669 | * @return FluentPdoModel|$this |
||
| 1670 | */ |
||
| 1671 | public function whereNotLike(string $columnName, string $value) : FluentPdoModel |
||
| 1675 | |||
| 1676 | /** |
||
| 1677 | * WHERE $columnName > $value |
||
| 1678 | * |
||
| 1679 | * @param string $columnName |
||
| 1680 | * @param mixed $value |
||
| 1681 | * @return FluentPdoModel|$this |
||
| 1682 | */ |
||
| 1683 | public function whereGt(string $columnName, $value) : FluentPdoModel |
||
| 1687 | |||
| 1688 | /** |
||
| 1689 | * WHERE $columnName >= $value |
||
| 1690 | * |
||
| 1691 | * @param string $columnName |
||
| 1692 | * @param mixed $value |
||
| 1693 | * @return FluentPdoModel|$this |
||
| 1694 | */ |
||
| 1695 | public function whereGte(string $columnName, $value) : FluentPdoModel |
||
| 1699 | |||
| 1700 | /** |
||
| 1701 | * WHERE $columnName < $value |
||
| 1702 | * |
||
| 1703 | * @param string $columnName |
||
| 1704 | * @param mixed $value |
||
| 1705 | * @return FluentPdoModel|$this |
||
| 1706 | */ |
||
| 1707 | public function whereLt(string $columnName, $value) : FluentPdoModel |
||
| 1711 | |||
| 1712 | /** |
||
| 1713 | * WHERE $columnName <= $value |
||
| 1714 | * |
||
| 1715 | * @param string $columnName |
||
| 1716 | * @param mixed $value |
||
| 1717 | * @return FluentPdoModel|$this |
||
| 1718 | */ |
||
| 1719 | public function whereLte(string $columnName, $value) : FluentPdoModel |
||
| 1723 | |||
| 1724 | /** |
||
| 1725 | * WHERE $columnName IN (?,?,?,...) |
||
| 1726 | * |
||
| 1727 | * @param string $columnName |
||
| 1728 | * @param array $values |
||
| 1729 | * @return FluentPdoModel|$this |
||
| 1730 | */ |
||
| 1731 | public function whereIn(string $columnName, array $values) : FluentPdoModel |
||
| 1735 | |||
| 1736 | /** |
||
| 1737 | * WHERE $columnName NOT IN (?,?,?,...) |
||
| 1738 | * |
||
| 1739 | * @param string $columnName |
||
| 1740 | * @param array $values |
||
| 1741 | * @return FluentPdoModel|$this |
||
| 1742 | */ |
||
| 1743 | public function whereNotIn(string $columnName, array $values) : FluentPdoModel |
||
| 1749 | |||
| 1750 | /** |
||
| 1751 | * WHERE $columnName IS NULL |
||
| 1752 | * |
||
| 1753 | * @param string $columnName |
||
| 1754 | * @return FluentPdoModel|$this |
||
| 1755 | */ |
||
| 1756 | public function whereNull(string $columnName) : FluentPdoModel |
||
| 1760 | |||
| 1761 | /** |
||
| 1762 | * WHERE $columnName IS NOT NULL |
||
| 1763 | * |
||
| 1764 | * @param string $columnName |
||
| 1765 | * @return FluentPdoModel|$this |
||
| 1766 | */ |
||
| 1767 | public function whereNotNull(string $columnName) : FluentPdoModel |
||
| 1771 | |||
| 1772 | /** |
||
| 1773 | * @param string $statement |
||
| 1774 | * @param string $operator |
||
| 1775 | * @return FluentPdoModel|$this |
||
| 1776 | */ |
||
| 1777 | public function having(string $statement, string $operator=self::OPERATOR_AND) : FluentPdoModel |
||
| 1786 | |||
| 1787 | /** |
||
| 1788 | * ORDER BY $columnName (ASC | DESC) |
||
| 1789 | * |
||
| 1790 | * @param string $columnName - The name of the column or an expression |
||
| 1791 | * @param string $ordering (DESC | ASC) |
||
| 1792 | * @return FluentPdoModel|$this |
||
| 1793 | */ |
||
| 1794 | public function orderBy(string $columnName='', string $ordering='ASC') : FluentPdoModel |
||
| 1808 | |||
| 1809 | /** |
||
| 1810 | * GROUP BY $columnName |
||
| 1811 | * |
||
| 1812 | * @param string $columnName |
||
| 1813 | * @return FluentPdoModel|$this |
||
| 1814 | */ |
||
| 1815 | public function groupBy(string $columnName) : FluentPdoModel |
||
| 1825 | |||
| 1826 | |||
| 1827 | /** |
||
| 1828 | * LIMIT $limit |
||
| 1829 | * |
||
| 1830 | * @param int $limit |
||
| 1831 | * @param int|null $offset |
||
| 1832 | * @return FluentPdoModel|$this |
||
| 1833 | */ |
||
| 1834 | public function limit(int $limit, int $offset=0) : FluentPdoModel |
||
| 1843 | |||
| 1844 | /** |
||
| 1845 | * Return the limit |
||
| 1846 | * |
||
| 1847 | * @return integer |
||
| 1848 | */ |
||
| 1849 | public function getLimit() : int |
||
| 1853 | |||
| 1854 | /** |
||
| 1855 | * OFFSET $offset |
||
| 1856 | * |
||
| 1857 | * @param int $offset |
||
| 1858 | * @return FluentPdoModel|$this |
||
| 1859 | */ |
||
| 1860 | public function offset(int $offset) : FluentPdoModel |
||
| 1866 | |||
| 1867 | /** |
||
| 1868 | * Return the offset |
||
| 1869 | * |
||
| 1870 | * @return integer |
||
| 1871 | */ |
||
| 1872 | public function getOffset() : int |
||
| 1876 | |||
| 1877 | /** |
||
| 1878 | * Build a join |
||
| 1879 | * |
||
| 1880 | * @param string $table - The table name |
||
| 1881 | * @param string $constraint -> id = profile.user_id |
||
| 1882 | * @param string $tableAlias - The alias of the table name |
||
| 1883 | * @param string $joinOperator - LEFT | INNER | etc... |
||
| 1884 | * @return FluentPdoModel|$this |
||
| 1885 | */ |
||
| 1886 | public function join(string $table, string $constraint='', string $tableAlias='', string $joinOperator='') : FluentPdoModel |
||
| 1905 | |||
| 1906 | /** |
||
| 1907 | * Create a left join |
||
| 1908 | * |
||
| 1909 | * @param string $table |
||
| 1910 | * @param string $constraint |
||
| 1911 | * @param string $tableAlias |
||
| 1912 | * @return FluentPdoModel|$this |
||
| 1913 | */ |
||
| 1914 | public function leftJoin(string $table, string $constraint, string $tableAlias='') : FluentPdoModel |
||
| 1918 | |||
| 1919 | |||
| 1920 | /** |
||
| 1921 | * Return the build select query |
||
| 1922 | * |
||
| 1923 | * @return string |
||
| 1924 | */ |
||
| 1925 | public function getSelectQuery() : string |
||
| 1968 | |||
| 1969 | /** |
||
| 1970 | * @param string $field |
||
| 1971 | * @param string $column |
||
| 1972 | * @return string |
||
| 1973 | */ |
||
| 1974 | public function getFieldComment(string $field, string $column) : string |
||
| 1978 | |||
| 1979 | /** |
||
| 1980 | * Prepare columns to include the table alias name |
||
| 1981 | * @param array $columns |
||
| 1982 | * @return array |
||
| 1983 | */ |
||
| 1984 | protected function prepareColumns(array $columns) : array |
||
| 2014 | |||
| 2015 | /** |
||
| 2016 | * Build the WHERE clause(s) |
||
| 2017 | * |
||
| 2018 | * @param bool $purgeAliases |
||
| 2019 | * @return string |
||
| 2020 | */ |
||
| 2021 | protected function getWhereString(bool $purgeAliases=false) : string |
||
| 2054 | |||
| 2055 | /** |
||
| 2056 | * Return the HAVING clause |
||
| 2057 | * |
||
| 2058 | * @return string |
||
| 2059 | */ |
||
| 2060 | protected function getHavingString() : string |
||
| 2079 | |||
| 2080 | /** |
||
| 2081 | * Return the values to be bound for where |
||
| 2082 | * |
||
| 2083 | * @param bool $purgeAliases |
||
| 2084 | * @return array |
||
| 2085 | */ |
||
| 2086 | protected function getWhereParameters(bool $purgeAliases=false) : array |
||
| 2092 | |||
| 2093 | /** |
||
| 2094 | * @param array $record |
||
| 2095 | * @return stdClass |
||
| 2096 | */ |
||
| 2097 | public function insertArr(array $record) : stdClass |
||
| 2101 | |||
| 2102 | /** |
||
| 2103 | * Insert new rows |
||
| 2104 | * $records can be a stdClass or an array of stdClass to add a bulk insert |
||
| 2105 | * If a single row is inserted, it will return it's row instance |
||
| 2106 | * |
||
| 2107 | * @param stdClass $rec |
||
| 2108 | * @return stdClass |
||
| 2109 | * @throws Exception |
||
| 2110 | */ |
||
| 2111 | public function insert(stdClass $rec) : stdClass |
||
| 2134 | |||
| 2135 | /** |
||
| 2136 | * @param string $name |
||
| 2137 | * @return int |
||
| 2138 | */ |
||
| 2139 | public function getLastInsertId(string $name='') : int |
||
| 2143 | |||
| 2144 | /** |
||
| 2145 | * @param stdClass[] $records |
||
| 2146 | * @return stdClass[] |
||
| 2147 | */ |
||
| 2148 | public function insertSqlQuery(array $records) : array |
||
| 2168 | |||
| 2169 | /** |
||
| 2170 | * @param $data |
||
| 2171 | * @param array $matchOn |
||
| 2172 | * @param bool $returnObj |
||
| 2173 | * @return bool|int|stdClass |
||
| 2174 | */ |
||
| 2175 | public function upsert($data, array $matchOn=[], $returnObj=false) |
||
| 2197 | |||
| 2198 | /** |
||
| 2199 | * @param stdClass $object |
||
| 2200 | * @param array $matchOn |
||
| 2201 | * @param bool $returnObj |
||
| 2202 | * @return bool|int|stdClass |
||
| 2203 | */ |
||
| 2204 | public function upsertOne(stdClass $object, array $matchOn=[], $returnObj=false) |
||
| 2244 | |||
| 2245 | /** |
||
| 2246 | * @param array $data |
||
| 2247 | * @param array $matchOn |
||
| 2248 | * @param bool|false $returnObj |
||
| 2249 | * @return bool|int|stdClass |
||
| 2250 | */ |
||
| 2251 | public function upsertArr(array $data, array $matchOn=[], bool $returnObj=false) |
||
| 2255 | |||
| 2256 | /** |
||
| 2257 | * Update entries |
||
| 2258 | * Use the query builder to create the where clause |
||
| 2259 | * |
||
| 2260 | * @param stdClass $record |
||
| 2261 | * @param bool $updateAll |
||
| 2262 | * @return int |
||
| 2263 | * @throws Exception |
||
| 2264 | */ |
||
| 2265 | public function update(stdClass $record, $updateAll=false) : int |
||
| 2288 | |||
| 2289 | /** |
||
| 2290 | * @param array $record |
||
| 2291 | * @param bool|false $updateAll |
||
| 2292 | * @return int |
||
| 2293 | * @throws Exception |
||
| 2294 | */ |
||
| 2295 | public function updateArr(array $record, $updateAll=false) : int |
||
| 2299 | |||
| 2300 | /** |
||
| 2301 | * @param string $field |
||
| 2302 | * @param mixed $value |
||
| 2303 | * @param int $id |
||
| 2304 | * @param bool|false $updateAll |
||
| 2305 | * @return int |
||
| 2306 | * @throws Exception |
||
| 2307 | */ |
||
| 2308 | public function updateField(string $field, $value, int $id=0, bool $updateAll=false) : int |
||
| 2322 | |||
| 2323 | /** |
||
| 2324 | * @param stdClass $record |
||
| 2325 | * @return bool|int |
||
| 2326 | * @throws Exception |
||
| 2327 | */ |
||
| 2328 | public function updateChanged(stdClass $record) : int |
||
| 2342 | |||
| 2343 | /** |
||
| 2344 | * @param string $expression |
||
| 2345 | * @param array $params |
||
| 2346 | * @return FluentPdoModel|$this |
||
| 2347 | */ |
||
| 2348 | public function updateByExpression(string $expression, array $params) : FluentPdoModel |
||
| 2354 | |||
| 2355 | /** |
||
| 2356 | * @param array $data |
||
| 2357 | * @return int |
||
| 2358 | * @throws Exception |
||
| 2359 | */ |
||
| 2360 | public function rawUpdate(array $data=[]) : int |
||
| 2369 | |||
| 2370 | /** |
||
| 2371 | * @param stdClass $record |
||
| 2372 | * @return array |
||
| 2373 | */ |
||
| 2374 | public function updateSqlQuery(stdClass $record) : array |
||
| 2383 | |||
| 2384 | /** |
||
| 2385 | * @param $record |
||
| 2386 | * @return array |
||
| 2387 | */ |
||
| 2388 | protected function updateSql(array $record) : array |
||
| 2421 | |||
| 2422 | /** |
||
| 2423 | * @param bool $deleteAll |
||
| 2424 | * @param bool $force |
||
| 2425 | * @return int |
||
| 2426 | * @throws Exception |
||
| 2427 | */ |
||
| 2428 | public function delete(bool $deleteAll=false, bool $force=false) : int |
||
| 2444 | |||
| 2445 | /** |
||
| 2446 | * @return bool |
||
| 2447 | */ |
||
| 2448 | public function isSoftDelete() : bool |
||
| 2452 | |||
| 2453 | /** |
||
| 2454 | * @param bool|false $force |
||
| 2455 | * @return FluentPdoModel|$this |
||
| 2456 | * @throws Exception |
||
| 2457 | */ |
||
| 2458 | public function truncate(bool $force=false) : FluentPdoModel |
||
| 2472 | |||
| 2473 | /** |
||
| 2474 | * @return array |
||
| 2475 | */ |
||
| 2476 | public function deleteSqlQuery() : array |
||
| 2488 | |||
| 2489 | |||
| 2490 | /** |
||
| 2491 | * Return the aggregate count of column |
||
| 2492 | * |
||
| 2493 | * @param string $column |
||
| 2494 | * @param int $cacheTtl |
||
| 2495 | * @return float |
||
| 2496 | */ |
||
| 2497 | public function count(string $column='*', int $cacheTtl=self::CACHE_NO) : float |
||
| 2517 | |||
| 2518 | |||
| 2519 | /** |
||
| 2520 | * Return the aggregate max count of column |
||
| 2521 | * |
||
| 2522 | * @param string $column |
||
| 2523 | * @param int $cacheTtl |
||
| 2524 | * @return int|float|string|null |
||
| 2525 | */ |
||
| 2526 | public function max(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2532 | |||
| 2533 | |||
| 2534 | /** |
||
| 2535 | * Return the aggregate min count of column |
||
| 2536 | * |
||
| 2537 | * @param string $column |
||
| 2538 | * @param int $cacheTtl |
||
| 2539 | * @return int|float|string|null |
||
| 2540 | */ |
||
| 2541 | public function min(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2547 | |||
| 2548 | /** |
||
| 2549 | * Return the aggregate sum count of column |
||
| 2550 | * |
||
| 2551 | * @param string $column |
||
| 2552 | * @param int $cacheTtl |
||
| 2553 | * @return int|float|string|null |
||
| 2554 | */ |
||
| 2555 | public function sum(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2561 | |||
| 2562 | /** |
||
| 2563 | * Return the aggregate average count of column |
||
| 2564 | * |
||
| 2565 | * @param string $column |
||
| 2566 | * @param int $cacheTtl |
||
| 2567 | * @return int|float|string|null |
||
| 2568 | */ |
||
| 2569 | public function avg(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2575 | |||
| 2576 | /*******************************************************************************/ |
||
| 2577 | // Utilities methods |
||
| 2578 | |||
| 2579 | /** |
||
| 2580 | * Reset fields |
||
| 2581 | * |
||
| 2582 | * @return FluentPdoModel|$this |
||
| 2583 | */ |
||
| 2584 | public function reset() : FluentPdoModel |
||
| 2612 | |||
| 2613 | |||
| 2614 | /** |
||
| 2615 | * @return FluentPdoModel|$this |
||
| 2616 | */ |
||
| 2617 | public function removeUnauthorisedFields() : FluentPdoModel |
||
| 2621 | |||
| 2622 | /** |
||
| 2623 | * @return Closure[] |
||
| 2624 | */ |
||
| 2625 | protected function getFieldHandlers() : array |
||
| 2725 | |||
| 2726 | /** |
||
| 2727 | * @return bool |
||
| 2728 | */ |
||
| 2729 | public function begin() : bool |
||
| 2743 | |||
| 2744 | /** |
||
| 2745 | * @return bool |
||
| 2746 | */ |
||
| 2747 | public function commit() : bool |
||
| 2765 | |||
| 2766 | /** |
||
| 2767 | * @return bool |
||
| 2768 | */ |
||
| 2769 | public function rollback() : bool |
||
| 2783 | |||
| 2784 | /** |
||
| 2785 | * @param stdClass $record |
||
| 2786 | * @param string $type |
||
| 2787 | * @return stdClass |
||
| 2788 | */ |
||
| 2789 | public function applyGlobalModifiers(stdClass $record, string $type) : stdClass |
||
| 2802 | |||
| 2803 | /** |
||
| 2804 | * @param stdClass $record |
||
| 2805 | * @param string $type |
||
| 2806 | * @return stdClass |
||
| 2807 | */ |
||
| 2808 | public function removeUnneededFields(stdClass $record, string $type) : stdClass |
||
| 2837 | |||
| 2838 | |||
| 2839 | /** |
||
| 2840 | * @param array $ids |
||
| 2841 | * @param array $values |
||
| 2842 | * @param int $batch |
||
| 2843 | * @return bool |
||
| 2844 | */ |
||
| 2845 | public function setById(array $ids, array $values, int $batch=1000) : bool |
||
| 2865 | |||
| 2866 | |||
| 2867 | /** |
||
| 2868 | * @param string $displayColumnValue |
||
| 2869 | * @return int |
||
| 2870 | */ |
||
| 2871 | public function resolveId(string $displayColumnValue) : int |
||
| 2882 | |||
| 2883 | /** |
||
| 2884 | * @param int $resourceId |
||
| 2885 | * @param array $query |
||
| 2886 | * @param array $extraFields |
||
| 2887 | * @param int $cacheTtl |
||
| 2888 | * @return array |
||
| 2889 | */ |
||
| 2890 | public function fetchApiResource(int $resourceId, array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO) : array |
||
| 2903 | |||
| 2904 | /** |
||
| 2905 | * @param array $query |
||
| 2906 | * @param array $extraFields |
||
| 2907 | * @param int $cacheTtl |
||
| 2908 | * @param string $permEntity |
||
| 2909 | * @return array |
||
| 2910 | */ |
||
| 2911 | public function fetchApiResources(array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO, string $permEntity='') : array |
||
| 2933 | |||
| 2934 | |||
| 2935 | /** |
||
| 2936 | * @return array |
||
| 2937 | */ |
||
| 2938 | public function getSearchableAssociations() : array |
||
| 2945 | |||
| 2946 | /** |
||
| 2947 | * @param array $fields |
||
| 2948 | */ |
||
| 2949 | public function removeUnrequestedFields(array $fields) |
||
| 2960 | |||
| 2961 | /** |
||
| 2962 | * @param array $removeFields |
||
| 2963 | */ |
||
| 2964 | public function removeFields(array $removeFields=[]) |
||
| 2990 | |||
| 2991 | /** |
||
| 2992 | * @return FluentPdoModel|$this |
||
| 2993 | */ |
||
| 2994 | public function defaultFilters() : FluentPdoModel |
||
| 2998 | |||
| 2999 | /** |
||
| 3000 | * @param bool $allow |
||
| 3001 | * |
||
| 3002 | * @return FluentPdoModel|$this |
||
| 3003 | */ |
||
| 3004 | public function allowMetaColumnOverride(bool $allow=false) : FluentPdoModel |
||
| 3010 | |||
| 3011 | /** |
||
| 3012 | * @param bool $skip |
||
| 3013 | * |
||
| 3014 | * @return FluentPdoModel|$this |
||
| 3015 | */ |
||
| 3016 | public function skipMetaUpdates(bool $skip=true) : FluentPdoModel |
||
| 3022 | |||
| 3023 | /** |
||
| 3024 | * @param bool $add |
||
| 3025 | * |
||
| 3026 | * @return FluentPdoModel|$this |
||
| 3027 | */ |
||
| 3028 | public function addUpdateAlias(bool $add=true) : FluentPdoModel |
||
| 3034 | |||
| 3035 | /** |
||
| 3036 | * @param stdClass $record |
||
| 3037 | * @return stdClass |
||
| 3038 | */ |
||
| 3039 | public function onFetch(stdClass $record) : stdClass |
||
| 3051 | |||
| 3052 | /** |
||
| 3053 | * @param $value |
||
| 3054 | * @return string |
||
| 3055 | */ |
||
| 3056 | public function gzEncodeData(string $value) : string |
||
| 3065 | |||
| 3066 | /** |
||
| 3067 | * @param $value |
||
| 3068 | * @return mixed|string |
||
| 3069 | */ |
||
| 3070 | public function gzDecodeData(string $value) : string |
||
| 3080 | |||
| 3081 | /** |
||
| 3082 | * @param $value |
||
| 3083 | * @return bool |
||
| 3084 | */ |
||
| 3085 | protected function hasGzipPrefix(string $value) : bool |
||
| 3089 | |||
| 3090 | /** |
||
| 3091 | * @param stdClass $record |
||
| 3092 | * @return stdClass |
||
| 3093 | */ |
||
| 3094 | public function fixTimestamps(stdClass $record) : stdClass |
||
| 3106 | |||
| 3107 | /** |
||
| 3108 | * @param int $max |
||
| 3109 | * @return FluentPdoModel|$this |
||
| 3110 | */ |
||
| 3111 | public function setMaxRecords(int $max) : FluentPdoModel |
||
| 3118 | |||
| 3119 | |||
| 3120 | /** |
||
| 3121 | * @param stdClass $record |
||
| 3122 | * @param string $type |
||
| 3123 | * @return stdClass |
||
| 3124 | */ |
||
| 3125 | public function afterSave(stdClass $record, string $type) : stdClass |
||
| 3146 | |||
| 3147 | /** |
||
| 3148 | * @param stdClass $record |
||
| 3149 | * @param string $type |
||
| 3150 | * @return stdClass |
||
| 3151 | */ |
||
| 3152 | public function addDefaultFields(stdClass $record, string $type) : stdClass |
||
| 3185 | |||
| 3186 | |||
| 3187 | /** |
||
| 3188 | * @return bool |
||
| 3189 | */ |
||
| 3190 | public function createTable() : bool |
||
| 3194 | |||
| 3195 | /** |
||
| 3196 | * @param bool|false $force |
||
| 3197 | * @return FluentPdoModel|$this |
||
| 3198 | * @throws Exception |
||
| 3199 | */ |
||
| 3200 | public function dropTable(bool $force=false) : FluentPdoModel |
||
| 3204 | |||
| 3205 | protected function compileHandlers() |
||
| 3214 | |||
| 3215 | /** |
||
| 3216 | * @param string $viewName |
||
| 3217 | * @param int $cacheTtl |
||
| 3218 | * @return array |
||
| 3219 | */ |
||
| 3220 | public function getViewColumns($viewName, $cacheTtl=self::CACHE_NO) |
||
| 3224 | |||
| 3225 | /** |
||
| 3226 | * @param int $id |
||
| 3227 | * @return string |
||
| 3228 | */ |
||
| 3229 | public function getDisplayNameById(int $id) : string |
||
| 3239 | |||
| 3240 | /** |
||
| 3241 | * @param int $id |
||
| 3242 | * @param string $displayColumnValue |
||
| 3243 | * @return bool |
||
| 3244 | */ |
||
| 3245 | public function validIdDisplayNameCombo(int $id, $displayColumnValue) : bool |
||
| 3249 | |||
| 3250 | /** |
||
| 3251 | * @param array $toPopulate |
||
| 3252 | * @return stdClass |
||
| 3253 | */ |
||
| 3254 | protected function getEmptyObject(array $toPopulate=[]) : stdClass |
||
| 3260 | |||
| 3261 | /** |
||
| 3262 | * @param array $toPopulate |
||
| 3263 | * @return stdClass |
||
| 3264 | */ |
||
| 3265 | protected static function emptyObject(array $toPopulate=[]) : stdClass |
||
| 3271 | |||
| 3272 | /** |
||
| 3273 | * @param int $id |
||
| 3274 | * @return bool |
||
| 3275 | */ |
||
| 3276 | public static function isId(int $id) : bool |
||
| 3280 | |||
| 3281 | /** |
||
| 3282 | * @param int $cacheTtl |
||
| 3283 | * @return int |
||
| 3284 | */ |
||
| 3285 | public function activeCount(int $cacheTtl=self::CACHE_NO) : int |
||
| 3289 | |||
| 3290 | /** |
||
| 3291 | * @param string $tableAlias |
||
| 3292 | * @param string $columnName |
||
| 3293 | * @return FluentPdoModel|$this |
||
| 3294 | */ |
||
| 3295 | public function whereActive(string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3299 | |||
| 3300 | /** |
||
| 3301 | * @param string $tableAlias |
||
| 3302 | * @param string $columnName |
||
| 3303 | * @return FluentPdoModel|$this |
||
| 3304 | */ |
||
| 3305 | public function whereInactive(string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3309 | |||
| 3310 | /** |
||
| 3311 | * @param string $tableAlias |
||
| 3312 | * @param string $columnName |
||
| 3313 | * @return FluentPdoModel|$this |
||
| 3314 | */ |
||
| 3315 | public function whereArchived(string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
| 3319 | |||
| 3320 | /** |
||
| 3321 | * @param int $status |
||
| 3322 | * @param string $tableAlias |
||
| 3323 | * @param string $columnName |
||
| 3324 | * @return FluentPdoModel|$this |
||
| 3325 | */ |
||
| 3326 | public function whereStatus(int $status, string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3335 | |||
| 3336 | /** |
||
| 3337 | * @param int $id |
||
| 3338 | * @return int |
||
| 3339 | */ |
||
| 3340 | public function updateActive(int $id=0) : int |
||
| 3350 | |||
| 3351 | /** |
||
| 3352 | * @param int $id |
||
| 3353 | * @return int |
||
| 3354 | */ |
||
| 3355 | public function updateInactive(int $id=0) : int |
||
| 3364 | |||
| 3365 | /** |
||
| 3366 | * @param string $field |
||
| 3367 | * @param int $id |
||
| 3368 | * @return int |
||
| 3369 | */ |
||
| 3370 | public function updateNow(string $field, int $id=0) : int |
||
| 3376 | |||
| 3377 | /** |
||
| 3378 | * @param string $field |
||
| 3379 | * @param int $id |
||
| 3380 | * @return int |
||
| 3381 | */ |
||
| 3382 | public function updateToday($field, int $id=0) : int |
||
| 3388 | |||
| 3389 | /** |
||
| 3390 | * @param int $id |
||
| 3391 | * @return int |
||
| 3392 | */ |
||
| 3393 | public function updateDeleted(int $id=0) : int |
||
| 3406 | |||
| 3407 | /** |
||
| 3408 | * @param int $id |
||
| 3409 | * @return int |
||
| 3410 | */ |
||
| 3411 | public function updateArchived(int $id=0) : int |
||
| 3421 | |||
| 3422 | /** |
||
| 3423 | * @param int $status |
||
| 3424 | * @return int |
||
| 3425 | * @throws \Exception |
||
| 3426 | */ |
||
| 3427 | public function updateStatus(int $status) |
||
| 3433 | |||
| 3434 | /** |
||
| 3435 | * Return a YYYY-MM-DD HH:II:SS date format |
||
| 3436 | * |
||
| 3437 | * @param string $datetime - An english textual datetime description |
||
| 3438 | * now, yesterday, 3 days ago, +1 week |
||
| 3439 | * http://php.net/manual/en/function.strtotime.php |
||
| 3440 | * @return string YYYY-MM-DD HH:II:SS |
||
| 3441 | */ |
||
| 3442 | public static function NOW(string $datetime='now') : string |
||
| 3446 | |||
| 3447 | /** |
||
| 3448 | * Return a string containing the given number of question marks, |
||
| 3449 | * separated by commas. Eg '?, ?, ?' |
||
| 3450 | * |
||
| 3451 | * @param int - total of placeholder to insert |
||
| 3452 | * @return string |
||
| 3453 | */ |
||
| 3454 | protected function makePlaceholders(int $numberOfPlaceholders=1) : string |
||
| 3458 | |||
| 3459 | /** |
||
| 3460 | * Format the table{Primary|Foreign}KeyName |
||
| 3461 | * |
||
| 3462 | * @param string $pattern |
||
| 3463 | * @param string $tableName |
||
| 3464 | * @return string |
||
| 3465 | */ |
||
| 3466 | protected function formatKeyName(string $pattern, string $tableName) : string |
||
| 3470 | |||
| 3471 | /** |
||
| 3472 | * @param array $query |
||
| 3473 | * @param array $extraFields |
||
| 3474 | * @return array |
||
| 3475 | * @throws \Exception |
||
| 3476 | */ |
||
| 3477 | protected function prepareApiResource(array $query=[], array $extraFields=[]) : array |
||
| 3498 | |||
| 3499 | /** |
||
| 3500 | * @param string $query |
||
| 3501 | * @param array $parameters |
||
| 3502 | * |
||
| 3503 | * @return array |
||
| 3504 | */ |
||
| 3505 | protected function logQuery(string $query, array $parameters) : array |
||
| 3518 | |||
| 3519 | /** |
||
| 3520 | * @param string $ident |
||
| 3521 | * @param string $builtQuery |
||
| 3522 | */ |
||
| 3523 | protected function logSlowQueries(string $ident, string $builtQuery) |
||
| 3536 | |||
| 3537 | /** |
||
| 3538 | * @return float |
||
| 3539 | */ |
||
| 3540 | public function getTimeTaken() : float |
||
| 3546 | |||
| 3547 | /** |
||
| 3548 | * @param $secs |
||
| 3549 | * @return FluentPdoModel|$this |
||
| 3550 | */ |
||
| 3551 | public function slowQuerySeconds(int $secs) : FluentPdoModel |
||
| 3558 | |||
| 3559 | |||
| 3560 | /** |
||
| 3561 | * @param $field |
||
| 3562 | * @param array $values |
||
| 3563 | * @param string $placeholderPrefix |
||
| 3564 | * |
||
| 3565 | * @return array |
||
| 3566 | */ |
||
| 3567 | public function getNamedWhereIn(string $field, array $values, string $placeholderPrefix='') : array |
||
| 3591 | |||
| 3592 | /** |
||
| 3593 | * @param string $field |
||
| 3594 | * @param string $delimiter |
||
| 3595 | * |
||
| 3596 | * @return array |
||
| 3597 | */ |
||
| 3598 | protected function getColumnAliasParts(string $field, string $delimiter=':') : array |
||
| 3613 | |||
| 3614 | /** |
||
| 3615 | * @param string $column |
||
| 3616 | * @param string $term |
||
| 3617 | * @return FluentPdoModel|$this |
||
| 3618 | */ |
||
| 3619 | protected function addWhereClause(string $column, string $term) : FluentPdoModel |
||
| 3671 | |||
| 3672 | /** |
||
| 3673 | * @param string $term |
||
| 3674 | * @return array |
||
| 3675 | */ |
||
| 3676 | public function parseWhereClause(string $term) : array |
||
| 3701 | |||
| 3702 | public function destroy() |
||
| 3711 | |||
| 3712 | public function __destruct() |
||
| 3716 | |||
| 3717 | /** |
||
| 3718 | * Load a model |
||
| 3719 | * |
||
| 3720 | * @param string $modelName |
||
| 3721 | * @param AbstractPdo $connection |
||
| 3722 | * @return FluentPdoModel|$this |
||
| 3723 | * @throws ModelNotFoundException |
||
| 3724 | */ |
||
| 3725 | public static function loadModel(string $modelName, AbstractPdo $connection=null) : FluentPdoModel |
||
| 3735 | |||
| 3736 | /** |
||
| 3737 | * Load a model |
||
| 3738 | * |
||
| 3739 | * @param string $tableName |
||
| 3740 | * @param AbstractPdo $connection |
||
| 3741 | * @return FluentPdoModel|$this |
||
| 3742 | */ |
||
| 3743 | public static function loadTable(string $tableName, AbstractPdo $connection=null) : FluentPdoModel |
||
| 3750 | |||
| 3751 | /** |
||
| 3752 | * @param string $columnName |
||
| 3753 | * @param int $cacheTtl |
||
| 3754 | * @param bool $flushCache |
||
| 3755 | * @return bool |
||
| 3756 | */ |
||
| 3757 | public function columnExists(string $columnName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3763 | |||
| 3764 | /** |
||
| 3765 | * @param string $foreignKeyName |
||
| 3766 | * @param int $cacheTtl |
||
| 3767 | * @param bool $flushCache |
||
| 3768 | * @return bool |
||
| 3769 | */ |
||
| 3770 | public function foreignKeyExists(string $foreignKeyName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3776 | |||
| 3777 | /** |
||
| 3778 | * @param string $indexName |
||
| 3779 | * @param int $cacheTtl |
||
| 3780 | * @param bool $flushCache |
||
| 3781 | * @return bool |
||
| 3782 | */ |
||
| 3783 | public function indexExists(string $indexName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3805 | |||
| 3806 | |||
| 3807 | |||
| 3808 | /** |
||
| 3809 | * @param int $cacheTtl |
||
| 3810 | * @param bool $flushCache |
||
| 3811 | * @return FluentPdoModel|$this |
||
| 3812 | */ |
||
| 3813 | public function loadSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : FluentPdoModel |
||
| 3820 | |||
| 3821 | /** |
||
| 3822 | * @param int $cacheTtl |
||
| 3823 | * @param bool $flushCache |
||
| 3824 | * @return Column[][] |
||
| 3825 | */ |
||
| 3826 | public function getSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3840 | |||
| 3841 | /** |
||
| 3842 | * @param int $cacheTtl |
||
| 3843 | * @param bool $flushCache |
||
| 3844 | * @return array |
||
| 3845 | */ |
||
| 3846 | public function getForeignKeysFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3859 | |||
| 3860 | /** |
||
| 3861 | * @param string $table |
||
| 3862 | * @param int $cacheTtl |
||
| 3863 | * @param bool $flushCache |
||
| 3864 | * @return Column[][] |
||
| 3865 | */ |
||
| 3866 | protected function getColumnsByTableFromDb(string $table, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3882 | |||
| 3883 | /** |
||
| 3884 | * @param string $table |
||
| 3885 | * @param int $cacheTtl |
||
| 3886 | * @param bool $flushCache |
||
| 3887 | * @return Column[][] |
||
| 3888 | */ |
||
| 3889 | protected function getForeignKeysByTableFromDb(string $table, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3905 | |||
| 3906 | /** |
||
| 3907 | * @param string $table |
||
| 3908 | * @return bool |
||
| 3909 | */ |
||
| 3910 | public function clearSchemaCache(string $table) : bool |
||
| 3914 | |||
| 3915 | /** |
||
| 3916 | * @param stdClass $record |
||
| 3917 | * @return stdClass |
||
| 3918 | */ |
||
| 3919 | public function cleanseRecord(stdClass $record) : stdClass |
||
| 3937 | |||
| 3938 | /** |
||
| 3939 | * @param stdClass $record |
||
| 3940 | * @param string $type |
||
| 3941 | * @return stdClass |
||
| 3942 | */ |
||
| 3943 | public function beforeSave(stdClass $record, string $type) : stdClass |
||
| 3952 | |||
| 3953 | /** |
||
| 3954 | * @param array $data |
||
| 3955 | * @param string $saveType |
||
| 3956 | * @return array |
||
| 3957 | */ |
||
| 3958 | public function cleanseWebData(array $data, string $saveType) : array |
||
| 3973 | |||
| 3974 | /** |
||
| 3975 | * @return array |
||
| 3976 | */ |
||
| 3977 | public function skeleton() : array |
||
| 3988 | |||
| 3989 | /** |
||
| 3990 | * @param bool $toString |
||
| 3991 | * @return array |
||
| 3992 | */ |
||
| 3993 | public function getErrors(bool $toString=false) : array |
||
| 4007 | |||
| 4008 | /** |
||
| 4009 | * @param bool $throw |
||
| 4010 | * @return FluentPdoModel|$this |
||
| 4011 | */ |
||
| 4012 | public function validationExceptions(bool $throw=true) : FluentPdoModel |
||
| 4018 | |||
| 4019 | /** |
||
| 4020 | * @param array $query array('_limit' => int, '_offset' => int, '_order' => string, '_fields' => string, _search) |
||
| 4021 | * |
||
| 4022 | * @return FluentPdoModel|$this |
||
| 4023 | * @throws Exception |
||
| 4024 | */ |
||
| 4025 | public function paginate(array $query=[]) : FluentPdoModel |
||
| 4042 | |||
| 4043 | /** |
||
| 4044 | * @param int $limit |
||
| 4045 | * @param int $offset |
||
| 4046 | * @return FluentPdoModel|$this |
||
| 4047 | */ |
||
| 4048 | protected function setLimit(int $limit=0, int $offset=0) : FluentPdoModel |
||
| 4063 | |||
| 4064 | /** |
||
| 4065 | * @param array $fields |
||
| 4066 | * @return FluentPdoModel|$this |
||
| 4067 | * @throws Exception |
||
| 4068 | */ |
||
| 4069 | protected function setFields(array $fields=[]) : FluentPdoModel |
||
| 4120 | |||
| 4121 | /** |
||
| 4122 | * @param string $orderBy |
||
| 4123 | * @return FluentPdoModel|$this|FluentPdoModel |
||
| 4124 | */ |
||
| 4125 | protected function setOrderBy(string $orderBy='') : FluentPdoModel |
||
| 4162 | |||
| 4163 | /** |
||
| 4164 | * @return array |
||
| 4165 | */ |
||
| 4166 | public function getPagingMeta() |
||
| 4175 | |||
| 4176 | /** |
||
| 4177 | * @return FluentPdoModel|$this |
||
| 4178 | */ |
||
| 4179 | public function setPagingMeta() : FluentPdoModel |
||
| 4201 | |||
| 4202 | /** |
||
| 4203 | * Take a web request and format a query |
||
| 4204 | * |
||
| 4205 | * @param array $query |
||
| 4206 | * |
||
| 4207 | * @return FluentPdoModel|$this |
||
| 4208 | * @throws Exception |
||
| 4209 | */ |
||
| 4210 | public function filter(array $query=[]) : FluentPdoModel |
||
| 4280 | |||
| 4281 | /** |
||
| 4282 | * @param string $column |
||
| 4283 | * @param string $displayCol |
||
| 4284 | * @return string|null |
||
| 4285 | */ |
||
| 4286 | protected function findFieldByQuery(string $column, string $displayCol) |
||
| 4333 | |||
| 4334 | /** |
||
| 4335 | * @param string $field |
||
| 4336 | * @param mixed $value |
||
| 4337 | * @param array $pdoMetaData |
||
| 4338 | * @return float|int |
||
| 4339 | * @throws Exception |
||
| 4340 | */ |
||
| 4341 | protected function fixTypeToSentinel(string $field, $value, array $pdoMetaData=[]) |
||
| 4397 | |||
| 4398 | /** |
||
| 4399 | * @param string $field |
||
| 4400 | * @param mixed $value |
||
| 4401 | * @param bool|false $permissive |
||
| 4402 | * @return float|int|null|string |
||
| 4403 | */ |
||
| 4404 | protected function fixType(string $field, $value, bool $permissive=false) |
||
| 4456 | |||
| 4457 | /** |
||
| 4458 | * @param stdClass $record |
||
| 4459 | * @param string $type |
||
| 4460 | * @return stdClass |
||
| 4461 | */ |
||
| 4462 | public function fixTypesToSentinel(stdClass $record, string $type='') : stdClass |
||
| 4489 | |||
| 4490 | /** |
||
| 4491 | * @param stdClass $record |
||
| 4492 | * @param string $type |
||
| 4493 | * @return stdClass |
||
| 4494 | * @throws Exception |
||
| 4495 | */ |
||
| 4496 | public function applyHandlers(stdClass $record, string $type='INSERT') : stdClass |
||
| 4524 | |||
| 4525 | |||
| 4526 | /** |
||
| 4527 | * @param stdClass $record |
||
| 4528 | * @param array $fields |
||
| 4529 | * @param string $type |
||
| 4530 | * @return bool |
||
| 4531 | */ |
||
| 4532 | protected function uniqueCheck(stdClass $record, array $fields, string $type) : bool |
||
| 4545 | |||
| 4546 | /** |
||
| 4547 | * @param string $field |
||
| 4548 | * @param mixed $value |
||
| 4549 | * @param string $type |
||
| 4550 | * @param stdClass $record |
||
| 4551 | * @return null |
||
| 4552 | * @throws Exception |
||
| 4553 | */ |
||
| 4554 | protected function applyHandler(string $field, $value, string $type='', stdClass $record=null) |
||
| 4578 | |||
| 4579 | /** |
||
| 4580 | * @param string $start |
||
| 4581 | * @param string $end |
||
| 4582 | * @param string $hayStack |
||
| 4583 | * @return mixed |
||
| 4584 | */ |
||
| 4585 | public static function between(string $start, string $end, string $hayStack) : string |
||
| 4589 | |||
| 4590 | /** |
||
| 4591 | * @param string $needle |
||
| 4592 | * @param string $hayStack |
||
| 4593 | * @param bool $returnOrigIfNeedleNotExists |
||
| 4594 | * @return mixed |
||
| 4595 | */ |
||
| 4596 | public static function before(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
| 4606 | |||
| 4607 | /** |
||
| 4608 | * @param string $needle |
||
| 4609 | * @param string $hayStack |
||
| 4610 | * @param bool $returnOrigIfNeedleNotExists |
||
| 4611 | * @return string |
||
| 4612 | */ |
||
| 4613 | public static function after(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
| 4622 | |||
| 4623 | /** |
||
| 4624 | * @return int |
||
| 4625 | */ |
||
| 4626 | public function getUserId() |
||
| 4630 | |||
| 4631 | /** |
||
| 4632 | * @param string $entity |
||
| 4633 | * @param int $id |
||
| 4634 | * @return int |
||
| 4635 | */ |
||
| 4636 | public function getMaskByResourceAndId(string $entity, int $id) : int |
||
| 4640 | |||
| 4641 | /** |
||
| 4642 | * @param string|int|null $time |
||
| 4643 | * @return string |
||
| 4644 | */ |
||
| 4645 | public static function date($time=null) : string |
||
| 4649 | |||
| 4650 | /** |
||
| 4651 | * @param string|int|null $time |
||
| 4652 | * @return string |
||
| 4653 | */ |
||
| 4654 | public static function dateTime($time=null) : string |
||
| 4658 | |||
| 4659 | /** |
||
| 4660 | * @param string|int|null $time |
||
| 4661 | * @return string |
||
| 4662 | */ |
||
| 4663 | public static function atom($time=null) : string |
||
| 4667 | |||
| 4668 | /** |
||
| 4669 | * @param string|int|null $time |
||
| 4670 | * @return int |
||
| 4671 | */ |
||
| 4672 | public static function getTime($time=null) : int |
||
| 4685 | |||
| 4686 | /** |
||
| 4687 | * @param int $id |
||
| 4688 | * @param int $cacheTtl |
||
| 4689 | * @return string |
||
| 4690 | */ |
||
| 4691 | public function getCodeById(int $id, int $cacheTtl=self::ONE_DAY) : string |
||
| 4699 | |||
| 4700 | /** |
||
| 4701 | * @param array $authUserRoles |
||
| 4702 | * @param int $authUserId |
||
| 4703 | * @return FluentPdoModel |
||
| 4704 | */ |
||
| 4705 | public function applyRoleFilter(array $authUserRoles, int $authUserId) : FluentPdoModel |
||
| 4709 | |||
| 4710 | /** |
||
| 4711 | * @param int $id |
||
| 4712 | * @param string[] $authUserRoles |
||
| 4713 | * @param int $authUserId |
||
| 4714 | * @return bool |
||
| 4715 | */ |
||
| 4716 | public function canAccessIdWithRole(int $id, array $authUserRoles, int $authUserId) : bool |
||
| 4720 | } |
||
| 4721 |
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.