@param resource $handle
@param array $fields
@param array $options

@return bool|int
540690
private static function fputcsv($handle, $fields, $options)
    {
        return \fputcsv($handle, $fields, $options['delimiter'], $options['enclosure'], $options['escape_char']);
    }
1142180
public function getField($table, $field, $options = array(), $start = 0)
    {
        // Get Result
        $result = $this->getRow($table, array($field), $options, $start);
        if (count($result) >= 1)
            return array_shift($result);
        else
            return false;
    }
1278907
public function read($handle)
	{
		if (!is_resource($handle) || get_resource_type($handle) !== 'stream') {
			throw new Exception('Argument must be stream resource.');
		}

		$stat = fstat($handle);

		$sql = '';
		$delimiter = ';';
		$count = $size = 0;

		while (!feof($handle)) {
			$s = fgets($handle);
			$size += strlen($s);
			if (strtoupper(substr($s, 0, 10)) === 'DELIMITER ') {
				$delimiter = trim(substr($s, 10));

			} elseif (substr($ts = rtrim($s), -strlen($delimiter)) === $delimiter) {
				$sql .= substr($ts, 0, -strlen($delimiter));
				if (!$this->connection->query($sql)) {
					throw new Exception($this->connection->error . ': ' . $sql);
				}
				$sql = '';
				$count++;
				if ($this->onProgress) {
					call_user_func($this->onProgress, $count, isset($stat['size']) ? $size * 100 / $stat['size'] : null);
				}

			} else {
				$sql .= $s;
			}
		}

		if (rtrim($sql) !== '') {
			$count++;
			if (!$this->connection->query($sql)) {
				throw new Exception($this->connection->error . ': ' . $sql);
			}
			if ($this->onProgress) {
				call_user_func($this->onProgress, $count, isset($stat['size']) ? 100 : null);
			}
		}

		return $count;
	}
1308269
private function putCsv($handle, $fields)
    {
        return fputcsv(
            $handle,
            $fields,
            $this->conversion['delimiter'],
            $this->conversion['enclosure'],
            $this->conversion['escape']
        );
    }
1083601
protected function handleRequest($method, $resource, $options)
    {
        $response = null;
        try
        {
            $response = $this->handleResponse($this->getHttpClient()->request($method, $resource, $options));
        }
        catch (RequestException $e)
        {
            $this->handleException($e);
        }

        return $response;
    }
505404
function Option(handler, options, desc) {
  Option.super_.apply(this, [handler, options, desc]);

  if (options.params && options.params.hasOwnProperty('optional')) {
    throw new Error('optional parameter is not allowed for options');
  }
}
648007
final public static function validateNumericFields (array $fields=[], string $option, string $field) : bool
	{
		$fieldsWithError 	= "";
		$field 				= static::checkGlobal($field);
		foreach ($fields as $fieldName => $length)
		{
			$value = static::setValueNull($field[$fieldName]);
			if ($value !== NULL) {
				$options = [$option => $length];
				if (!static::hasNumber($value, $options))
					$fieldsWithError .= "'".fieldNameAsText($fieldName)."', ";
			}
		}
		static::setError($fieldsWithError);
		return static::checkError();
	}
673051
protected function call($command, array $options = array())
	{
		$curl = curl_init();
		$options[CURLOPT_URL] = $this->command_url($command);
		$options[CURLOPT_RETURNTRANSFER] = TRUE;
		$options[CURLOPT_FOLLOWLOCATION] = TRUE;

		curl_setopt_array($curl, $options);

		$raw = '';

		Attempt::make(function() use ($curl, & $raw) {
			$raw = trim(curl_exec($curl));
			return curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200;
		});

		$error = curl_error($curl);
		$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);

		curl_close($curl);

		if ($error)
			throw new Exception_Driver('Curl ":command" throws exception :error', array(':command' => $command, ':error' => $error));

		if ($code != 200)
			throw new Exception_Driver('Unexpected response from the panthomjs for :command: :code', array(':command' => $command, ':code' => $code));

		$result = json_decode($raw, TRUE);

		return $result;
	}
334160
protected function stream_headers($handle, $headers) {
		// Why do we do this? cURL will send both the final response and any
		// interim responses, such as a 100 Continue. We don't need that.
		// (We may want to keep this somewhere just in case)
		if ($this->done_headers) {
			$this->headers = '';
			$this->done_headers = false;
		}
		$this->headers .= $headers;

		if ($headers === "\r\n") {
			$this->done_headers = true;
		}
		return strlen($headers);
	}
1219443
public function getByHandle($handle)
    {
        return isset($this->converters[$handle]) ? $this->converters[$handle] : null;
    }
512444
public function fetchColumn($table, $field, $where = null, $options = null)
    {
        return $this->column($table, $field, $where, $options);
    }
1229502
public function execute(ResourceNode $resourceNode, string $actionName, array $options = [], array $content = null, array $files = null): Response
    {
        $resourceAction = $this->get($resourceNode, $actionName);
        $resource = $this->resourceManager->getResourceFromNode($resourceNode);

        /** @var ResourceActionEvent $event */
        $event = $this->dispatcher->dispatch(
            static::eventName($actionName, $resourceAction->getResourceType()),
            ResourceActionEvent::class,
            [$resource, $options, $content, $files, $resourceNode]
        );

        return $event->getResponse();
    }
184163
private function createOptimizeJob(string $handle, string $filePath, array $settings)
    {
        $queue = Craft::$app->getQueue();

        $jobId = $queue->push(new OptimizeJob([
            'description' => Craft::t('imager', 'Optimizing images ('.$handle.')'),
            'optimizer' => $handle,
            'optimizerSettings' => $settings,
            'filePath' => $filePath,
        ]));

        Craft::info('Created optimize job for '.$handle.' (job id is '.$jobId.')', __METHOD__);
    }
108578
protected function doDistinct($field, array $query, array $options)
    {
        list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
            ? $this->splitCommandAndClientOptions($options)
            : [$options, []];

        $command = [];
        $command['distinct'] = $this->mongoCollection->getName();
        $command['key'] = $field;
        $command['query'] = (object) $query;
        $command = array_merge($command, $commandOptions);

        $database = $this->database;
        $result = $this->retry(function() use ($database, $command, $clientOptions) {
            return $database->command($command, $clientOptions);
        });

        if (empty($result['ok'])) {
            throw new ResultException($result);
        }

        $arrayIterator = new ArrayIterator(isset($result['values']) ? $result['values'] : []);
        $arrayIterator->setCommandResult($result);

        return $arrayIterator;
    }
550986
public function process(Job $job, ListenerOptions $options)
    {
        $this->log('[' . get_class($this) . '] MessageId=' . $job->getId() . ', Payload=' . $job->getPayload());

        $res = $this->handle($job, $options);

        $this->log('[' . get_class($this) . '] MessageId=' . $job->getId() . ', Result=' . serialize($res));

        // delete handled job if successfully handled
        if ($res !== false && !$job->isDeleted()) {
            $job->delete();
        }

        return $res;
    }
962899
public function query($query, $options = [])
    {
        $url = $this->instanceURLRepo->get();
        $url .= $this->resourceRepo->get('query');
        $url .= '?q=';
        $url .= urlencode($query);

        $queryResults = $this->request($url, $options);

        return $queryResults;
    }
1167061
protected function processField($method, array $field = array(), array $options = array())
    {
        $this->field  = $field;
        $this->method = strtolower($method);

        $this->editFieldhandlerMethod();

        foreach (array('name', 'value', 'type') as $key) {
            $this->editFieldhandlerAttribute($key);
        }

        $fieldhandler_results = $this->executeConstraint($options);

        $this->processConstraintResults($fieldhandler_results);

        return $this->field_value;
    }