示例#1
0
 private static function toDotted($array, $prepend = '', $counter = 1)
 {
     $results = [];
     if ($prepend !== '') {
         $results['if (typeof ' . $prepend . ' === \'undefined\' || ' . $prepend . '.constructor === Array ) {' . $prepend . ' = {}}'] = ';';
     }
     foreach ($array as $key => $value) {
         if ($counter > 1) {
             $key = '["' . $key . '"]';
         } else {
             $results['if (typeof ' . $key . ' === \'undefined\' || ' . $key . '.constructor === Array) {' . $key . ' = {}}'] = ';';
         }
         if (is_array($value) && !empty($value)) {
             // check if this is meant to be value-only array without assoc keys (P.S. assoc key = field name)
             if (is_array($value) && (count($value) === 0 || array_keys($value) === range(0, count($value) - 1))) {
                 $results[$prepend . $key] = ' = ' . json_encode($value) . ';';
             } else {
                 $results = array_merge($results, self::toDotted($value, $prepend . $key, $counter + 1));
             }
         } else {
             if (is_array($value) && count($value) === 0) {
                 $results[$prepend . $key] = ' = ' . json_encode($value) . ';';
             } else {
                 if (is_string($value)) {
                     $results[$prepend . $key] = ' = "' . Client::escape($value) . '";';
                 } else {
                     $results[$prepend . $key] = ' = ' . Client::escape($value) . ';';
                 }
             }
         }
     }
     return $results;
 }
 function it_parses_order_by_CP_FIELD()
 {
     $this->beConstructedWith(new ConnectionFaker());
     $response = $this->orderBy(Client::field("1==1"))->get();
     $response->executedQuery()->shouldReturn('SELECT * FROM database ORDER BY this["1==1"] DESC LIMIT 0, 20');
 }