@param ElasticaRequest      $request
@param \Elastica\Connection $connection

@return string
437641
protected function _getUri(ElasticaRequest $request, Connection $connection): string
    {
        $url = $connection->hasConfig('url') ? $connection->getConfig('url') : '';

        if (!empty($url)) {
            $baseUri = $url;
        } else {
            $baseUri = $this->_scheme.'://'.$connection->getHost().':'.$connection->getPort().'/'.$connection->getPath();
        }

        $requestPath = $request->getPath();
        if (!Util::isDateMathEscaped($requestPath)) {
            $requestPath = Util::escapeDateMath($requestPath);
        }

        $baseUri .= $requestPath;

        $query = $request->getQuery();

        if (!empty($query)) {
            $baseUri .= '?'.\http_build_query($query);
        }

        return $baseUri;
    }
17277
protected function getConnectionMask(ConnectionInterface $connection)
    {
        return strtolower(sprintf(
            '%s!%s@%s',
            $connection->getNickname(),
            $connection->getUsername(),
            $connection->getServerHostname()
        ));
    }
1230663
private function stripLinkNodeKeys($data, Connection $connection)
    {
        if (is_array($data['children']) && count($data['children'])) {
            /*
            $qb = $connection->createQueryBuilder();
            $qb
                ->select(array('id', 'sort'))
                ->from('tree', 't')
                ->where($qb->expr()->eq('t.parent_id', $data['id']))
                ->where($qb->expr()->in('t.id',array_keys($data['children'])))
                ->orderBy('t.sort');

            $sortTids = $connection->fetchAll($qb->getSQL());
            $sortedTids = [];
            foreach (array_keys($data['children']) as $tid) {
                $sortedTids[$tid] = $sortTids[$tid];
            }

            array_multisort($sortedTids, $data['children']);
            */

            $data['children'] = array_values($data['children']);

            foreach ($data['children'] as $key => $item) {
                $data['children'][$key] = $this->stripLinkNodeKeys($item, $connection);
            }
        }

        return $data;
    }
379586
protected function handle(Connection $connection, $request)
    {
        $this->loadSession($connection);
        
        return $this->Kernel->handle($request);
    }
335165
private function createBelongingToOtherEntitiesQueryBuilder(
        Connection $connection,
        QueryBuilder $parentQueryBuilder
    ) {
        $revisionFieldName = $this->configuration->getRevisionFieldName();
        $identifierColumnNames = $this->metadata->getIdentifierColumnNames();

        $queryBuilder = $connection->createQueryBuilder()
            ->select('1')
            ->from($this->configuration->getTableName($this->metadata), 'st')
            ->andWhere(sprintf('st.%1$s > t.%1$s', $revisionFieldName));

        $queryBuilder->andWhere(sprintf(
            'st.%s <= %s',
            $revisionFieldName,
            $parentQueryBuilder->createPositionalParameter($this->revision)
        ));

        //ids
        foreach ($identifierColumnNames as $name) {
            $queryBuilder->andWhere(sprintf('st.%1$s = t.%1$s', $name));
        }

        //master entity query, not equals
        $notEqualParts = $nullParts = array();
        foreach ($this->foreignKeys as $column => $value) {
            $notEqualParts[] = $column . ' <> ' . $parentQueryBuilder->createPositionalParameter($value);
            $nullParts[] = $column . ' IS NULL';
        }

        $expr = $queryBuilder->expr();
        $queryBuilder->andWhere(
            $expr->orX(
                $expr->andX(...$notEqualParts),
                $expr->andX(...$nullParts)
            )
        );

        return $queryBuilder;
    }
1333594
public function onError(ConnectionInterface $connection, \Exception $e)
    {
        return $this->decorated->onError($connection, $e);
    }
81716
protected function getPrefix(Connection $connection)
    {
        $params = $connection->getParams();

        return isset($params['prefix']) ? $params['prefix'] : null;
    }
1102457
public function onMessage(ConnectionInterface $conn, $request) {

        if(is_array($request = json_decode($request, true)) === false) {
            throw new AppServiceException('The server received an invalid data format');
        }
        if(isset($request['page']) === false) {
            throw new AppServiceException('There is no current page data');
        }

        $this->queueService->push($request, function() use ($request, $conn) {

            // process only what is necessary for the subsequent construction of stats
            return [
                'ip'        =>  $this->getIpAddress($conn),
                'hash'      =>  md5($this->getIpAddress($conn).$this->getUserAgent($conn)),
                'open'      =>  time()
            ];
        });

        // send back
        if(defined('SONAR_VERBOSE') === true) {
            echo Messenger::message(json_encode($request));
            $conn->send(json_encode($request));
        }
    }
442446
protected function createClientsTable(Connection $connection, DatabaseSchemaInterface $schema): void
    {
        $manager = $connection->getSchemaManager();

        $table = new Table($schema->getClientsTable());
        $table->addColumn($schema->getClientsIdentityColumn(), Type::STRING)->setNotnull(true);
        $table->addColumn($schema->getClientsNameColumn(), Type::STRING)->setNotnull(true);
        $table->addColumn($schema->getClientsDescriptionColumn(), Type::STRING)->setNotnull(false);
        $table->addColumn($schema->getClientsCredentialsColumn(), Type::STRING)->setNotnull(false);
        $table->addColumn($schema->getClientsIsConfidentialColumn(), Type::BOOLEAN)->setDefault(true);
        $table->addColumn($schema->getClientsIsScopeExcessAllowedColumn(), Type::BOOLEAN)->setDefault(false);
        $table->addColumn($schema->getClientsIsUseDefaultScopeColumn(), Type::BOOLEAN)->setDefault(true);
        $table->addColumn($schema->getClientsIsCodeGrantEnabledColumn(), Type::BOOLEAN)->setDefault(false);
        $table->addColumn($schema->getClientsIsImplicitGrantEnabledColumn(), Type::BOOLEAN)->setDefault(false);
        $table->addColumn($schema->getClientsIsPasswordGrantEnabledColumn(), Type::BOOLEAN)->setDefault(false);
        $table->addColumn($schema->getClientsIsClientGrantEnabledColumn(), Type::BOOLEAN)->setDefault(false);
        $table->addColumn($schema->getClientsIsRefreshGrantEnabledColumn(), Type::BOOLEAN)->setDefault(false);
        $table->addColumn($schema->getClientsCreatedAtColumn(), Type::DATETIME)->setNotnull(true);
        $table->addColumn($schema->getClientsUpdatedAtColumn(), Type::DATETIME)->setNotnull(false);
        $table->setPrimaryKey([$schema->getClientsIdentityColumn()]);
        $manager->dropAndCreateTable($table);
    }
1241092
public function col_connection( string $connection, array $args ) {

		global $post, $wp_query;

		if ( ! function_exists( 'p2p_type' ) ) {
			return;
		}

		if ( ! $this->p2p_connection_exists( $connection ) ) {
			echo esc_html( sprintf(
				/* translators: %s: The ID of the Posts 2 Posts connection type */
				__( 'Invalid connection type: %s', 'extended-cpts' ),
				$connection
			) );
			return;
		}

		$_post = $post;
		$meta  = [];
		$out   = [];
		$field = 'connected_' . $connection;

		if ( isset( $args['field'] ) && isset( $args['value'] ) ) {
			$meta = [
				'connected_meta' => [
					$args['field'] => $args['value'],
				],
			];
			$field .= sanitize_title( '_' . $args['field'] . '_' . $args['value'] );
		}

		if ( ! isset( $_post->$field ) ) {
			$type = p2p_type( $connection );
			if ( $type ) {
				$type->each_connected( [ $_post ], $meta, $field );
			} else {
				echo esc_html( sprintf(
					/* translators: %s: The ID of the Posts 2 Posts connection type */
					__( 'Invalid connection type: %s', 'extended-cpts' ),
					$connection
				) );
				return;
			}
		}

		// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
		foreach ( $_post->$field as $post ) {

			setup_postdata( $post );

			$pto = get_post_type_object( $post->post_type );
			$pso = get_post_status_object( $post->post_status );

			if ( $pso->protected && ! current_user_can( 'edit_post', $post->ID ) ) {
				continue;
			}
			if ( 'trash' === $post->post_status ) {
				continue;
			}

			if ( $args['link'] ) {

				switch ( $args['link'] ) {
					case 'view':
						if ( $pto->public ) {
							if ( $pso->protected ) {
								$out[] = sprintf(
									'<a href="%1$s">%2$s</a>',
									esc_url( get_preview_post_link() ),
									esc_html( get_the_title() )
								);
							} else {
								$out[] = sprintf(
									'<a href="%1$s">%2$s</a>',
									esc_url( get_permalink() ),
									esc_html( get_the_title() )
								);
							}
						} else {
							$out[] = esc_html( get_the_title() );
						}
						break;
					case 'edit':
						if ( current_user_can( 'edit_post', $post->ID ) ) {
							$out[] = sprintf(
								'<a href="%1$s">%2$s</a>',
								esc_url( get_edit_post_link() ),
								esc_html( get_the_title() )
							);
						} else {
							$out[] = esc_html( get_the_title() );
						}
						break;
					case 'list':
						$link = add_query_arg( array_merge( [
							'post_type'       => $_post->post_type,
							'connected_type'  => $connection,
							'connected_items' => $post->ID,
						], $meta ), admin_url( 'edit.php' ) );
						$out[] = sprintf(
							'<a href="%1$s">%2$s</a>',
							esc_url( $link ),
							esc_html( get_the_title() )
						);
						break;
				}
			} else {

				$out[] = esc_html( get_the_title() );

			}
		}

		$post = $_post; // WPCS: override ok.

		echo implode( ', ', $out ); // WPCS: XSS ok.

	}
945010
protected function prepare(Connection $connection)
	{
		$connection->setFetchMode($this->app['config']['database.fetch']);

		if ($this->app->bound('events'))
		{
			$connection->setEventDispatcher($this->app['events']);
		}

		// Here we'll set a reconnector callback. This reconnector can be any callable
		// so we will set a Closure to reconnect from this manager with the name of
		// the connection, which will allow us to reconnect from the connections.
		$connection->setReconnector(function($connection)
		{
			$this->reconnect($connection->getName());
		});

		return $connection;
	}
1355649
public function toSql(Connection $connection, Grammar $grammar)
    {
        $this->addImpliedCommands();

        $statements = [];

        // Each type of command has a corresponding compiler function on the schema
        // grammar which is used to build the necessary SQL statements to build
        // the blueprint element, so we'll just call that compilers function.
        foreach ($this->commands as $command) {
            $method = 'compile' . ucfirst($command->name);

            if (method_exists($grammar, $method)) {
                if (!is_null($sql = $grammar->{$method}($this, $command, $connection))) {
                    $statements = array_merge($statements, (array) $sql);
                }
            }
        }

        return $statements;
    }
3450
protected function buildRequest($verb, Connection $connection, $topic, $data = [], $params = null)
    {
        $uri = [
            'protocol'  => 'ws://',
            'host'      => $connection->WebSocket->request->getHost(),
            'port'      => ':' . config('twostream.websocket.port'),
            'path'      => '/' . trim($topic->getId(), '/') . (isset($params) ? '/' . implode('/', $params) : ''),
        ];
        $cookies = $connection->WebSocket->request->getCookies();
        array_forget($cookies, config('session.cookie')); // Make sure the normal Session Facade does not contain the client's Session.
        
        return Request::createFromBase(
            SymfonyRequest::create(
                implode($uri),
                strtoupper($verb),
                ['data' => $data], // params
                $cookies, // cookies
                [], // files
                [], // server
                null // content
            )
        );
    }
967868
protected function getUser(Connection $connection)
    {
        $recaller = $connection->WebSocket->request->getCookie(Auth::getRecallerName());
        
        if (! $recaller) {
            return false;
        }
        
        try {
            $recaller = $this->Encrypter->decrypt(urldecode($recaller));
        } catch (Exception $e) {
            $recaller = $this->Encrypter->decrypt($recaller);
        }
        
        $id = explode('|', $recaller, 2)[0];
        $model = $this->getUserModel();
        
        return $model::find($id) !== null ? $id : false;
    }
186605
protected function loadSession(Connection $connection)
    {
        $sessionId = $connection->session = $this->getSessionIdFromCookie($connection);
        
        $session = clone $this->Session;
        $session->setId($sessionId);
        $session->start();
        
        $readonly = (new ReadOnly(config('session.cookie')))->initialize($session->all(), $sessionId);
        WsSession::swap($readonly);
        Session::flush();
        
        unset($session);
    }
1024959
public function queryInstruction(Instruction $object, $connection = null)
    {
        return $this->rawQuery((string)$object, $object->attributes(), $connection);
    }
1039327
public function getServerCredentials($connection = null, $server = 0)
    {
        $connection = $this->sanitizeConnection($connection);
        $servers = $this->getServersCredentials($connection);

        return (array) Arr::get($servers, $server ?: $connection->server);
    }