示例#1
0
 /**
  * Orders and returns an array of parameters for a given statement.
  * 
  * @param Statement\StatementInterface $stmt The statement to get the bound parameters for.
  * 
  * @return array
  */
 public function getParametersFromStatement(Statement\StatementInterface $stmt)
 {
     $params = [];
     // Save parameter parts.
     if ($stmt instanceof Statement\Save) {
         $data = $stmt->getData();
         array_walk_recursive($data, function ($i) use(&$params) {
             $params[] = $i;
         });
     }
     $wheres = [];
     if ($stmt instanceof Statement\Find) {
         foreach ($stmt->getJoins() as $join) {
             $wheres = array_merge($wheres, $join->getWheres());
         }
     }
     $wheres = array_merge($wheres, $stmt->getWheres());
     // Where clause parameters. Array values are merged
     // because they are part of an * operator.
     foreach ($wheres as $where) {
         $value = $where->getValue();
         if (is_array($value)) {
             $params = array_merge($params, $value);
         } elseif (!is_null($value)) {
             $params[] = $value;
         }
     }
     // Only get certain parameters for certain types of statements.
     if ($stmt instanceof Statement\Find) {
         if ($limit = $stmt->getLimit()) {
             $params = array_merge($params, [$stmt->getLimit(), $stmt->getOffset()]);
         }
     }
     // We need to convert boolean values to their driver specific value
     array_walk($params, function (&$value) {
         $value = $this->filterBool($value);
     });
     // Return a re-indexed array so that
     // positions are not out of order.
     return array_values($params);
 }