Source of file common.php
Size: 2,626 Bytes - Last Modified: 2018-02-09T21:13:11+00:00
src/common.php
123456789101112131415161718192021222324252627282930313233
Covered by 196 test(s):
343536373839404142434445
Covered by 20 test(s):
4647
Covered by 20 test(s):
4849
Covered by 20 test(s):
505152
Covered by 20 test(s):
5354555657585960616263646566
Covered by 2 test(s):
6768
Covered by 2 test(s):
6970
Covered by 2 test(s):
7172
Covered by 2 test(s):
7374
Covered by 2 test(s):
7576
Covered by 2 test(s):
77787980
Covered by 2 test(s):
81828384858687888990919293
Covered by 46 test(s):
9495
Covered by 1 test(s):
969798
Covered by 45 test(s):
99100
Covered by 45 test(s):
101102
Covered by 45 test(s):
103104105106
Covered by 3 test(s):
107108109110111112113114115116117118119120121122
Covered by 8 test(s):
123124
Covered by 1 test(s):
125126127
Covered by 7 test(s):
128129130
Covered by 7 test(s):
131132
Covered by 4 test(s):
133134135
Covered by 3 test(s):
136137138
Covered by 3 test(s):
139140141142
| <?php declare(strict_types=1); /** * Query * * SQL Query Builder / Database Abstraction Layer * * PHP version 7 * * @package Query * @author Timothy J. Warren <tim@timshomepage.net> * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ use Query\{ ConnectionManager, QueryBuilderInterface }; /** * Global functions that don't really fit anywhere else */ /** * Multibyte-safe trim function * * @param string $string * @return string */ function mb_trim(string $string): string { return preg_replace('/(^\s+)|(\s+$)/u', '', $string); } /** * Filter out db rows into one array * * @param array $array * @param mixed $index * @return array */ function dbFilter(array $array, $index): array { $newArray = []; foreach($array as $a) { $newArray[] = $a[$index]; } return $newArray; } /** * Zip a set of arrays together on common keys * * The $zipperInput array is an array of arrays indexed by their place in the output * array. * * @param array $zipperInput * @return array */ function arrayZipper(array $zipperInput): array { $output = []; foreach($zipperInput as $appendKey => $values) { foreach($values as $index => $value) { if ( ! isset($output[$index])) { $output[$index] = []; } $output[$index][$appendKey] = $value; } } return $output; } /** * Determine whether a value in the passed array matches the pattern * passed * * @param array $array * @param string $pattern * @return bool */ function regexInArray(array $array, string $pattern): bool { if (empty($array)) { return FALSE; } foreach($array as $item) { if (is_scalar($item) && preg_match($pattern, $item)) { return TRUE; } } return FALSE; } /** * Connection function * * Send an array or object as connection parameters to create a connection. If * the array or object has an 'alias' parameter, passing that string to this * function will return that connection. Passing no parameters returns the last * connection created. * * @param string|object|array $params * @return QueryBuilderInterface|null */ function Query($params = ''): ?QueryBuilderInterface { if ($params === NULL) { return NULL; } $manager = ConnectionManager::getInstance(); // If you are getting a previously created connection if (is_scalar($params)) { return $manager->getConnection($params); } $paramsObject = (object) $params; // Otherwise, return a new connection return $manager->connect($paramsObject); } // End of common.php |