Returns an instance for this spool/

@param string[] $options Configuration options.

@return CallSpoolImpl
181187
public static function getInstance(array $options = array())
    {
        if (self::$instance === false) {
            $ret = new CallSpoolImpl($options);
            self::$instance = $ret;
        } else {
            $ret = self::$instance;
        }
        return self::$instance;
    }
328547
public function createPool()
    {
        $pool = new RepositoryPool();

        foreach ($this->definitions as $definition) {
            $pool->addRepositoryDefinition($definition);
        }

        return $pool;
    }
708345
public static function getInstance($options = array())
    {
        if (is_null(static::$_instance)) {
            static::$_instance = new static($options);
            Inspector::addAnnotationClass(
                'column',
                'Slick\Orm\Annotation\Column'
            );
            Inspector::addAnnotationClass(
                'hasMany',
                'Slick\Orm\Annotation\HasMany'
            );
            Inspector::addAnnotationClass(
                'hasOne',
                'Slick\Orm\Annotation\HasOne'
            );
            Inspector::addAnnotationClass(
                'belongsTo',
                'Slick\Orm\Annotation\BelongsTo'
            );
            Inspector::addAnnotationClass(
                'hasAndBelongsToMany',
                'Slick\Orm\Annotation\HasAndBelongsToMany'
            );
        }
        return static::$_instance;
    }
1214302
public static function getInstance($options = []){
        if (is_null(self::$_instance)) {
            self::$_instance = new static($options);
        }
        return self::$_instance;
    }
514633
final public function get($options = []) {
		// process parameters
		$parameters = [];
		$options['where'] = $options['where'] ?? [];
		if (!empty($this->parameters)) {
			$this->parameters = \Object\Data\Common::processDomainsAndTypes($this->parameters);
			foreach ($this->parameters as $k => $v) {
				// if we have a parameter
				if (array_key_exists($k, $options['where'])) {
					if (!empty($v['multiple_column'])) {
						if (!is_array($options['where'][$k])) $options['where'][$k] = [$options['where'][$k]];
						$parameters[$k] = [];
						foreach ($options['where'][$k] as $v2) {
							$result = \Object\Table\Columns::validateSingleColumn($k, $v, $v2);
							if (!$result['success']) {
								Throw new \Exception("Datasource: " . get_called_class() . " parameter: {$k} error" . implode(', ', $result['error']));
							} else {
								$parameters[$k][] = $result['data'][$k];
							}
						}
					} else {
						$result = \Object\Table\Columns::validateSingleColumn($k, $v, $options['where'][$k]);
						if (!$result['success']) {
							Throw new \Exception("Datasource: " . get_called_class() . " parameter: {$k} error" . implode(', ', $result['error']));
						} else {
							$parameters[$k] = $result['data'][$k];
						}
					}
				}
				// required
				if (!empty($v['required']) && empty($parameters[$k])) {
					return [];
					//Throw new \Exception("Datasource: " . get_called_class() . " parameter: {$k} error" . i18n(null, \Object\Content\Messages::required_field));
				}
			}
		}
		// we need to push existing values to parameters
		if (!empty($options['existing_values']) && !empty($this->parameters['existing_values'])) {
			$parameters['existing_values'] = $options['existing_values'];
		}
		$where = $options['where'] ?? [];
		unset($options['where']);
		// process primary model
		if (!empty($this->primary_model)) {
			$model = new $this->primary_model();
			$this->db_link = $model->db_link;
			if (empty($this->pk)) $this->pk = $model->pk;
			$this->cache_tags = array_merge($this->cache_tag ?? [], $model->cache_tags);
			if (!empty($this->primary_params)) {
				$options = array_merge_hard($options, $this->primary_params);
			}
			$options['where'] = $where[$this->primary_model] ?? [];
			unset($where[$this->primary_model]);
			foreach ($where as $k => $v) {
				if (strpos($k, '\\') === 0) {
					$options['where'][$k] = $v;
				}
			}
			// query
			$this->query = call_user_func_array([$this->primary_model, 'queryBuilderStatic'], [$options])->select();
		}
		// we need to determine db link
		if (empty($this->db_link)) {
			// get from flags first
			if (!empty($this->db_link_flag)) {
				$this->db_link = \Application::get($this->db_link_flag);
			}
			// get default link
			if (empty($this->db_link)) {
				$this->db_link = \Application::get('flag.global.default_db_link');
			}
			// if we could not determine the link we throw exception
			if (empty($this->db_link)) {
				Throw new \Exception('Could not determine db link in datasource!');
			}
		}
		// create empty query object
		if (empty($this->query)) {
			$this->query = new \Object\Query\Builder($this->db_link, $options);
			$this->query->select();
		}
		// add settings to query
		$query_settings = [];
		foreach (['pk', 'columns', 'limit', 'orderby', 'single_row', 'single_value'] as $v) {
			if (array_key_exists($v, $options)) {
				$query_settings[$v] = $options[$v];
			} else if (isset($this->{$v})) {
				$query_settings[$v] = $this->{$v};
			}
		}
		if (isset($query_settings['columns'])) $this->query->columns($query_settings['columns']);
		if (isset($query_settings['limit'])) $this->query->limit($query_settings['limit']);
		if (isset($query_settings['orderby'])) $this->query->limit($query_settings['orderby']);
		if (!empty($query_settings['single_row']) || !empty($query_settings['single_value'])) $this->query->limit(1);
		// fix variables
		$query_settings['pk'] = $query_settings['pk'] ?? null;
		if (empty($this->cache_tags)) $this->cache_tags = [];
		// check if we have query method
		if (!method_exists($this, 'query')) {
			Throw new \Exception('You must specify sql in query method!');
		}
		// process query
		$sql = $this->query($parameters, $options);
		if (!empty($sql)) {
			$db_object = new \Db($this->db_link);
			$this->sql_last_query = $sql;
		} else {
			$db_object = $this->query->db_object;
			$this->sql_last_query = $this->query->sql();
			// grab cache tags from query object
			if (!empty($this->query->cache_tags)) {
				$this->cache_tags = array_unique(array_merge($this->cache_tags, $this->query->cache_tags));
			}
		}
		// determine caching strategy
		if (method_exists($this, 'process')) {
			// retrive data from the cache
			if ($this->cache && !empty($db_object->object->options['cache_link'])) {
				$cache_id = !empty($options['cache_id']) ? $options['cache_id'] : 'Db_DataSource_' . trim(sha1($this->sql_last_query . serialize($query_settings['pk'])));
				// if we cache this query
				$cache_object = new \Cache($db_object->object->options['cache_link']);
				$cached_result = $cache_object->get($cache_id, true);
				if ($cached_result !== false) {
					// if we are debugging
					if (\Debug::$debug) {
						\Debug::$data['sql'][] = $cached_result;
					}
					return $cached_result['rows'];
				}
			} else {
				$this->cache = false;
			}
		}
		$query_options = [
			'cache' => $this->cache,
			'cache_tags' => array_unique($this->cache_tags)
		];
		// if we need to return a query
		if (!empty($options['return_query_only'])) {
			if (empty($sql)) {
				$sql = $this->query->sql();
			}
			// wrap into tabs
			if ($options['return_query_only'] == 'wrap') {
				$object = new \Object\Query\Builder($this->db_link, []);
				$sql = '(' . $object->wrapSqlIntoTabs($sql) . ')';
			}
			return [
				'sql' => $sql,
				'cache_tags' => array_unique($this->cache_tags)
			];
		}
		// if we have SQL
		if (!empty($sql)) {
			$result = $db_object->query($sql, $query_settings['pk'], $query_options);
		} else { // query builder
			$result = $this->query->query($query_settings['pk'], $query_options);
		}
		if (!$result['success']) {
			Throw new \Exception(implode(", ", $result['error']));
		}
		// put parameters beck into options
		$options['parameters'] = $parameters;
		// process data
		if (method_exists($this, 'process')) {
			$data = $this->process($result['rows'], $options);
			// if we are caching
			if ($this->cache) {
				// the same cache structure as in Db classes
				$cache_data = [
					'success' => true,
					'error' => [],
					'errno' => 0,
					'rows' => $data,
					'num_rows' => is_bool($data) ? 0 : count($data),
					'affected_rows' => 0,
					'structure' => [],
					// debug attributes
					'cache' => true,
					'cache_tags' => [],
					'time' => microtime(true),
					'sql' => $this->sql_last_query,
					'key' => $query_settings['pk'],
					'backtrace' => null
				];
				if (\Debug::$debug) {
					$cache_data['backtrace']  = implode("\n", \Object\Error\Base::debugBacktraceString());
					$cache_data['cache_tags'] = $this->cache_tags;
				}
				$cache_object->set($cache_id, $cache_data, null, $this->cache_tags);
			}
		} else {
			$data = $result['rows'];
		}
		// process not cached
		if (method_exists($this, 'processNotCached')) {
			$data = $this->processNotCached($data, $options);
		}
		// single row
		if (!empty($query_settings['single_row']) && !empty($data)) {
			$data = current($data);
		}
		// single value
		if (!empty($query_settings['single_value']) && !empty($data)) {
			$data = current($data);
			if (!empty($data)) {
				$data = current($data);
			}
		}
		return $data;
	}
1182034
public static function fromArray(array $options = []): self
    {
        return new self(
            $options['authorization_code_ttl'] ?? 120,
            $options['access_token_ttl'] ?? 3600,
            $options['refresh_token_ttl'] ?? 86400,
            $options['rotate_refresh_tokens'] ?? false,
            $options['revoke_rotated_refresh_tokens'] ?? true,
            $options['owner_callable'] ?? null,
            $options['grants'] ?? [],
            $options['owner_request_attribute'] ?? 'owner',
            $options['token_request_attribute'] ?? 'oauth_token'
        );
    }
142263
public function options($options = [])
    {
        // remote options
        if (is_string($options)) {
            // reload selected
            if (class_exists($options) && in_array(Model::class, class_parents($options))) {
                return $this->model(...func_get_args());
            }

            return $this->loadRemoteOptions(...func_get_args());
        }

        if ($options instanceof Arrayable) {
            $options = $options->toArray();
        }

        if (is_callable($options)) {
            $this->options = $options;
        } else {
            $this->options = (array) $options;
        }

        return $this;
    }
965528
public function createSession($options)
    {
        $request = new Request('POST', '/session/create');
        try {
            $response = $this->client->send($request, [
                'debug' => $this->isDebug(),
                'form_params' => $this->postFieldsForOptions($options)
            ]);
            $sessionXml = $this->getResponseXml($response);
        } catch (\RuntimeException $e) {
            // TODO: test if we have a parse exception and handle it, otherwise throw again
            throw $e;
        } catch (\Exception $e) {
            $this->handleException($e);
            return;
        }
        return $sessionXml;
    }
1228319
public function createSwooleServer(array $options = array())
    {
        if (array() === $options) {
            $options = array(
                'daemonize' => false,
                'worker_num' => 1,
            );
        }

        return new SwooleServer(
            new SwooleMessageTransformer($this->getPsr7Factory()),
            new SwooleServerOptions($options)
        );
    }
1009503
public function getConnection(array $options = array()) {
        $conn =& $this->connection;
        $mutable = $this->getOption(xPDO::OPT_CONN_MUTABLE, $options, null);
        if (!($conn instanceof xPDOConnection) || ($mutable !== null && (($mutable == true && !$conn->isMutable()) || ($mutable == false && $conn->isMutable())))) {
            if (!empty($this->_connections)) {
                shuffle($this->_connections);
                $conn = reset($this->_connections);
                while ($conn) {
                    if ($mutable !== null && (($mutable == true && !$conn->isMutable()) || ($mutable == false && $conn->isMutable()))) {
                        $conn = next($this->_connections);
                        continue;
                    }
                    $this->connection =& $conn;
                    break;
                }
            } else {
                $this->log(xPDO::LOG_LEVEL_ERROR, "Could not get a valid xPDOConnection", '', __METHOD__, __FILE__, __LINE__);
            }
        }
        return $this->connection;
    }
340379
protected function execute(array $options = [])
    {
        $session = $this->createSession();
        $result = [];

        try {
            if ($session->open() === false) {
                throw new RuntimeException('Cannot initialize a cURL session');
            }

            $session->setOptions($options + $this->options);

            $result = $session->execute();

            if ($result === false) {
                throw new TransferException($session->getErrorMessage(), $session->getErrorCode());
            }

            $headerSize = $session->getInfo(CURLINFO_HEADER_SIZE);

            if (strlen($result) < $headerSize) {
                throw new TransferException(
                    'Header size(' . $headerSize . ') does not match result: ' . $result
                );
            }

            $result = [
                substr($result, $headerSize) ?: null,
                substr($result, 0, $headerSize) ?: null,
            ];
        } finally {
            $session->close();
        }

        return $result;
    }
463874
public function options($options = [])
    {
        // remote options
        if (is_string($options)) {
            return $this->loadRemoteOptions(...func_get_args());
        }

        if ($options instanceof Arrayable) {
            $options = $options->toArray();
        }

        if (is_callable($options)) {
            $this->options = $options;
        } else {
            $this->options = (array) $options;
        }

        return $this;
    }
1280647
public function getMemcacheConnection(array $options = [])
    {
        $options = array_replace(['host' => 'localhost', 'port' => 11211], $options);
        if (null !== $cache = $this->getConnection('memcache', $options)) {
            return $cache;
        }

        if (!extension_loaded('memcache')) {
            throw new RuntimeException('The Memcache cache requires the Memcache extension.');
        }

        $memcache = new \Memcache();
        $memcache->addServer($options['host'], $options['port']);

        $key = sprintf("%s:%s", $options['host'], $options['port']);
        $stats = @$memcache->getExtendedStats();

        if (!isset($stats[$key]) || false === $stats[$key]) {
            throw new RuntimeException(sprintf("Memcache instance with host '%s' and port '%s' is not reachable.", $options['host'], $options['port']));
        }

        return $this->setConnection('memcache', $options, $memcache);
    }
114140
public function selectGridFSBucket(array $options = [])
    {
        $options += [
            'readConcern' => $this->readConcern,
            'readPreference' => $this->readPreference,
            'typeMap' => $this->typeMap,
            'writeConcern' => $this->writeConcern,
        ];

        return new Bucket($this->manager, $this->databaseName, $options);
    }
451698
protected static function getBitBucketClient(array $options = [])
    {
        if (null === static::$client || static::$client->getOptions() !== $options) {
            static::$client = new BitBucketClient($options);
        }

        return static::$client;
    }
969744
protected function initArrayCallbackOption($options)
    {
        if (!isset($options['callback']) && !isset($options['groups']) && \is_callable($options)) {
            $options = ['callback' => $options];
        }

        return $options;
    }
682671
public static function use($callable)
    {
        if(Config::get('@currentServer.redis.quickFromRequestContext', true))
        {
            return $callable(RedisManager::getInstance());
        }
        else
        {
            return PoolManager::use(RedisManager::getDefaultPoolName(), function($resource, $redis) use($callable) {
                return $callable($redis);
            });
        }
    }