original_string: protected function prepareProjection(array $fields)
      {
          $projection = [];
          foreach ($fields as $key => $value) {
              if (is_string($key)) {
                  if (is_bool($value)) {
                      $projection[$key] = $value;
  
                      continue;
                  }
                  if (is_int($value)) {
                      $projection[$key] = ($value >= 1);
  
                      continue;
                  }
              }
  
              if (is_int($key) && is_string($value)) {
                  $key = $value;
                  if (0 === strpos($value, '-')) {
                      $key = substr($key, 1);
                      $value = false;
                  } else {
                      $value = true;
                  }
  
                  $projection[$key] = $value;
  
                  continue;
              }
  
              throw new InvalidArgumentException(
                  sprintf(
                      "Invalid projection: '%s' => '%s'",
                      $key,
                      $value
                  )
              );
          }
  
          return $projection;
      }
code: protected function prepareProjection(array $fields)
      {
          $projection = [];
          foreach ($fields as $key => $value) {
              if (is_string($key)) {
                  if (is_bool($value)) {
                      $projection[$key] = $value;
  
                      continue;
                  }
                  if (is_int($value)) {
                      $projection[$key] = ($value >= 1);
  
                      continue;
                  }
              }
  
              if (is_int($key) && is_string($value)) {
                  $key = $value;
                  if (0 === strpos($value, '-')) {
                      $key = substr($key, 1);
                      $value = false;
                  } else {
                      $value = true;
                  }
  
                  $projection[$key] = $value;
  
                  continue;
              }
  
              throw new InvalidArgumentException(
                  sprintf(
                      "Invalid projection: '%s' => '%s'",
                      $key,
                      $value
                  )
              );
          }
  
          return $projection;
      }
code_tokens: protected function prepareProjection ( array $ fields ) { $ projection = [ ] ; foreach ( $ fields as $ key => $ value ) { if ( is_string ( $ key ) ) { if ( is_bool ( $ value ) ) { $ projection [ $ key ] = $ value ; continue ; } if ( is_int ( $ value ) ) { $ projection [ $ key ] = ( $ value >= 1 ) ; continue ; } } if ( is_int ( $ key ) && is_string ( $ value ) ) { $ key = $ value ; if ( 0 === strpos ( $ value , '-' ) ) { $ key = substr ( $ key , 1 ) ; $ value = false ; } else { $ value = true ; } $ projection [ $ key ] = $ value ; continue ; } throw new InvalidArgumentException ( sprintf ( "Invalid projection: '%s' => '%s'" , $ key , $ value ) ) ; } return $ projection ; }
docstring: Converts the given projection fields to Mongo driver format.
  
  How to use:
  As Mongo projection using boolean values:
  From: ['name' => true, '_id' => false]
  To:   ['name' => true, '_id' => false]
  As Mongo projection using integer values
  From: ['name' => 1, '_id' => -1]
  To:   ['name' => true, '_id' => false]
  As an array of string:
  From: ['name', '_id']
  To:   ['name' => true, '_id' => true]
  As an array of string to exclude some fields:
  From: ['name', '-_id']
  To:   ['name' => true, '_id' => false]
  
  @param array $fields fields to project
  
  @throws InvalidArgumentException if the given $fields are not a valid projection
  
  @return array
docstring_tokens: Converts the given projection fields to Mongo driver format .