Bind http client

@return void
427608
public function bindHttpClient()
    {
        $this->app->bind(HttpClient::class, function (Application $app) {
            $client = $app->make('ej:sdk:guzzle');
            $auth = $app->make(Authentication\Authenticator::class);

            return new HttpClient($client, $auth);
        });
    }
561395
protected function setupHttpClientSettings()
    {
        $this->httpClient->setDefaultOption('exceptions', false);
        $this->httpClient->setDefaultOption('timeout', $this->options['timeout']);
        $this->httpClient->setDefaultOption('connect_timeout', $this->options['connect_timeout']);

        $this->httpClient->setDefaultOption('headers', [
            'Content-Type' => 'application/json',
            'Authorization' => $this->auth->generateAuthorization()
        ]);
    }
655201
public function getHttpClient()
    {
        if (!is_object($this->_httpClient)) {
            $this->_httpClient = new Client([
                'baseUrl' => $this->baseUrl,
                'requestConfig' => [
                    'options' => $this->requestOptions
                ],
                'responseConfig' => [
                    'format' => Client::FORMAT_JSON
                ],
            ]);
        }
        return $this->_httpClient;
    }
955027
protected function constructHttpClient()
    {
        $hasHttpClient = (null !== $this->httpClient);

        $this->httpClient = new HttpClient($this->getOptions());

        if (!$hasHttpClient) {
            $this->httpClient->registerDefaults();
        }
    }
840987
protected function call()
    {
        // Check if the curl object is set
        if (!$this->isInit()) {
            // If it isn't, we do it right now
            $this->init();
        }

        $options = array();
        // Set basic authentication if enabled
        if ($this->authentication instanceof BasicAuthentication) {
            $options['auth'] = array(
                $this->authentication->getUsername(),
                $this->authentication->getPassword()
            );
        }

        // Set json
        if (($json = $this->getJson()) != null) {
            $options['json'] = $json;
            $this->setAccept('application/json');
        }

        if (($formParams = $this->getFormParams()) != null) {
            $options['body'] = $formParams;
            $this->setContentType('application/x-www-form-urlencoded');
        }

        $request = $this->getHttpClient()->createRequest(
            $this->getHttpMethod(),
            $this->getEndpoint(),
            array_merge(
                array('headers' => $this->getHeaders()),
                $options
            )
        );

        foreach ($this->getEndpointParameters() as $key => $value) {
            $request->getQuery()->set($key, $value);
        }

        if (($body = $this->getBody()) != null && (is_null($body))) {
            $request->setBody(Stream::factory($body));
        }

        $response = $this->getHttpClient()->send($request);

        $this->setHttpStatusCode($response->getStatusCode());

        $this->setData($response->json());
    }
438739
protected function __bindEvents()
    {
        $server = $this->swoolePort ?? $this->swooleServer;

        $server->on('handShake', function(\swoole_http_request $swooleRequest, \swoole_http_response $swooleResponse){
            try{
                $request = new Request($this, $swooleRequest);
                $response = new Response($this, $swooleResponse);
                $this->trigger('handShake', [
                    'request'   => &$request,
                    'response'  => &$response,
                ], $this, HandShakeEventParam::class);
            }
            catch(\Throwable $ex)
            {
                App::getBean('ErrorLog')->onException($ex);
            }
        });

        $server->on('message', function (\swoole_websocket_server $server, \swoole_websocket_frame $frame) {
            try{
                $this->trigger('message', [
                    'server'    => $this,
                    'frame'     => $frame,
                ], $this, MessageEventParam::class);
            }
            catch(\Throwable $ex)
            {
                App::getBean('ErrorLog')->onException($ex);
            }
        });

        $server->on('close', function(\swoole_http_server $server, $fd, $reactorID){
            try{
                $this->trigger('close', [
                    'server'    => $this,
                    'fd'        => $fd,
                    'reactorID' => $reactorID,
                ], $this, CloseEventParam::class);
            }
            catch(\Throwable $ex)
            {
                App::getBean('ErrorLog')->onException($ex);
            }
        });
    }
12495
protected function setHeaderForServer()
    {
        header($this->protocol().' '.$this->getStatusCode().' '.ResponseHeader::$httpStatus[$this->getStatusCode()]);
    }
165843
public function register()
    {
        $this->bindGuzzle();

        $this->bindAuth();

        $this->bindHttpClient();

        $this->bindApiClient();

        $this->bindTaxonomyMapper();
    }
855828
protected function registerBindings(): void
    {
        $this->app->bind('algolia.connection', function (Container $app) {
            $manager = $app['algolia'];

            return $manager->connection();
        });

        $this->app->alias('algolia.connection', SearchClient::class);
    }
818744
protected function setup() {
		$this->rs = new \HaveAPI\Client\Resource($this->client, 'token', $this->description->resources->token, array());
		$this->via = isSet($this->opts['via']) ? $this->opts['via'] : self::HTTP_HEADER;
		
		if(isSet($this->opts['token'])) {
			$this->configured = true;
			$this->token = $this->opts['token'];
			return;
		}
		
		$this->requestToken();
	}
281276
protected function connect()
    {
        $this->client = new Client(array(
            'host'   => $this->instance->getHost(),
            'port'   => $this->instance->getPort(),
        ));
    }
1026321
protected function registerBindings()
    {
        // TODO: Change to bind the implementation to the interface instead.
        $this->app->bind(CorsService::class, function () {
            return new CorsService(config(self::CONFIG_KEY));
        });

        $this->app->alias(CorsService::class, CorsServiceContract::class);
    }
1056116
private function httpHandler()
    {
        if (config()->loadFile('view') === true) {
            // Instantiate Http UserAgent Service
            $this->services->load(Framework\Http\UserAgent::class, 'userAgent');

            // Instantiate Http View Service
            $this->services->load(Framework\Http\Parser::class);

            // Instantiate Http View Service
            $this->services->load(Framework\Http\View::class);

            // Instantiate Http Presenter Service
            $this->services->load(Framework\Http\Presenter::class);
        }

        // Instantiate Http Router Service
        $this->services->load(Framework\Http\Router::class);

        if (profiler() !== false) {
            profiler()->watch('Parse Router Request');
        }
        router()->parseRequest();

        if (config()->loadFile('session') === true) {

            // Instantiate Session Service
            $session = new Session(config('session', true));
            $session->setLogger($this->services->get('logger'));

            if ( ! $session->isStarted()) {
                $session->start();
            }

            $this->services->add($session, 'session');

            if ($session->has('language') and $this->services->has('language')) {
                language()->setDefault($session->get('language'));
            } else {
                $session->set('language', language()->getDefault());
            }

            if (config('security')->protection[ 'csrf' ] === true) {
                $csrfProtection = new Security\Protections\Csrf();
                $this->services->add($csrfProtection, 'csrfProtection');
            }

            if (config('security')->protection[ 'xss' ] === true) {
                $xssProtection = new Security\Protections\Xss();
                $this->services->add($xssProtection, 'xssProtection');
            }
        }

        // Instantiate Http Middleware Service
        $this->services->load(Framework\Http\Middleware::class);

        if (profiler() !== false) {
            profiler()->watch('Running Middleware Service: Pre Controller');
        }
        middleware()->run();

        if ($this->services->has('controller')) {
            $controller = $this->services->get('controller');

            $controllerParameter = dash($controller->getParameter());
            $controllerRequestMethod = dash($controller->getRequestMethod());

            $modules = $this->modules->getArrayCopy();
            
            // Run Module Autoloader
            foreach ($modules as $module) {
                if (in_array($module->getType(), ['KERNEL', 'FRAMEWORK'])) {
                    continue;
                }

                // Autoload Module Language
                if ($this->services->has('language')) {
                    language()->loadFile($module->getParameter());
                }

                // Autoload Module Model
                $module->loadModel();

                // Add View Resource Directory
                if($this->services->has('view')) {
                    view()->addFilePath($module->getResourcesDir());
                    presenter()->assets->pushFilePath($module->getResourcesDir());
                }
            }
            
            if ($this->services->has('view')) {
                presenter()->initialize();
            }

            // Autoload Language
            if ($this->services->has('language')) {
                language()->loadFile($controller->getParameter());
                language()->loadFile($controller->getRequestMethod());
                language()->loadFile($controller->getParameter() . '/' . $controller->getRequestMethod());
            }

            // Autoload Model
            $modelClassName = str_replace(['Controllers', 'Presenters'], 'Models', $controller->getName());

            if (class_exists($modelClassName)) {
                $this->models->load($modelClassName, 'controller');
            }

            if ($this->services->has('view')) {
                // Autoload Presenter
                $presenterClassName = str_replace('Controllers', 'Presenters', $controller->getName());

                if (class_exists($presenterClassName)) {
                    $presenterClassObject = new $presenterClassName();
                    if ($presenterClassObject instanceof Framework\Http\Presenter) {
                        $this->services->add($presenterClassObject, 'presenter');
                    }
                }
            }

            // Initialize Controller
            if (profiler() !== false) {
                profiler()->watch('Calling Hooks Service: Pre Controller');
            }

            hooks()->callEvent(Framework\Services\Hooks::PRE_CONTROLLER);

            if (profiler() !== false) {
                profiler()->watch('Instantiating Requested Controller: ' . $controller->getClass());
            }
            $requestController = $controller->getInstance();

            if (method_exists($requestController, '__reconstruct')) {
                $requestController->__reconstruct();
            }

            if (profiler() !== false) {
                profiler()->watch('Calling Hooks Service: Post Controller');
            }
            hooks()->callEvent(Framework\Services\Hooks::POST_CONTROLLER);

            if (profiler() !== false) {
                profiler()->watch('Calling Middleware Service: Post Controller');
            }
            middleware()->run();

            $requestMethod = $controller->getRequestMethod();
            $requestMethodArgs = $controller->getRequestMethodArgs();

            // Call the requested controller method
            if (profiler() !== false) {
                profiler()->watch('Execute Requested Controller Method');
            }

            ob_start();
            $requestController->__call($requestMethod, $requestMethodArgs);
            $requestControllerOutput = ob_get_contents();
            ob_end_clean();

            if (is_numeric($requestControllerOutput)) {
                output()->sendError($requestControllerOutput);
            } elseif (is_bool($requestControllerOutput)) {
                if ($requestControllerOutput === true) {
                    output()->sendError(200);
                } elseif ($requestControllerOutput === false) {
                    output()->sendError(204);
                }
            } elseif (is_array($requestControllerOutput) or is_object($requestControllerOutput)) {
                output()->sendPayload($requestControllerOutput);
            } elseif ($requestController instanceof Framework\Http\Controllers\Restful) {
                if (empty($requestControllerOutput)) {
                    $requestController->sendError(204);
                } elseif (is_string($requestControllerOutput)) {
                    if (is_json($requestControllerOutput)) {
                        output()->setContentType('application/json');
                    } else {
                        output()->setContentType('text/plain');
                    }

                    echo $requestControllerOutput;
                }
            } elseif (is_string($requestControllerOutput)) {
                if (is_json($requestControllerOutput)) {
                    output()->setContentType('application/json');
                    echo $requestControllerOutput;
                } elseif ($this->services->has('view')) {
                    if (empty($requestControllerOutput)) {
                        $filenames = [
                            $controllerRequestMethod,
                            $controllerParameter . DIRECTORY_SEPARATOR . $controllerRequestMethod,
                        ];

                        if ($controllerRequestMethod === 'index') {
                            array_unshift($filenames, $controllerParameter);
                        }

                        foreach ($filenames as $filename) {
                            if (false !== ($filePath = view()->getFilePath($filename))) {
                                view()->load($filePath);
                                break;
                            }
                        }
                    } else {
                        presenter()->partials->offsetSet('content', $requestControllerOutput);
                    }

                    if (presenter()->partials->offsetExists('content')) {
                        if(is_ajax()) {
                            echo presenter()->partials->content;
                        } else {
                            $htmlOutput = view()->render();

                            if (empty($htmlOutput)) {
                                output()->sendError(204);
                            } else {
                                output()->setContentType('text/html');
                                output()->send($htmlOutput);
                            }
                        }
                    } else {
                        output()->sendError(204);
                    }
                } elseif (empty($requestControllerOutput) or $requestControllerOutput === '') {
                    output()->sendError(204);
                } else {
                    output()->setContentType('text/plain');
                    output()->send($requestControllerOutput);
                }
            }
        } else {
            // Show Error (404) Page Not Found
            output()->sendError(404);
        }
    }
596316
protected function bindRoom(): void
    {
        $this->app->singleton(RoomContract::class, function (Container $container) {
            $config = $container->make('config');
            $driver = $config->get('swoole_websocket.default');
            $settings = $config->get("swoole_websocket.settings.{$driver}");
            $className = $config->get("swoole_websocket.drivers.{$driver}");

            // create room instance and initialize
            $room = $this->createRoom($className, $settings);
            $room->prepare();

            return $room;
        });

        $this->app->alias(RoomContract::class, 'swoole.room');
    }
1029779
public function connect()
    {
      if ($this->route) {
        if ($_SERVER['REQUEST_METHOD'] === $this->routeMethod[0] || $this->routeMethod[0] == 'ANY') {

          // If handler is function
          if (is_callable($this->handler)) {
            call_user_func($this->handler, (object) $this->params[0]);
          }
          // // If handler is controller and method name
          else {
            $controller_data =  explode('@', $this->handler);
            $controller = $this->namespace . '\\' . ucwords($controller_data[0]) . 'Controller';
            $action = 'action' . ucwords($controller_data[1]);

            // If class exists
            if (class_exists($controller)) {
              $controllerInstance = new $controller;
            } else {
              exit('Class Not Found');
            }

            // If method exists
            if (method_exists($controllerInstance, $action))	{
              call_user_func_array([$controllerInstance, $action], [(object) $this->params[0]]);
            }	else {
              exit('Controller Method Not Found');
            }
          }
        } else {
          exit('HTTP method not allowed');
        }
      }
      // If route not found
      elseif($this->check($this->routerCollection->getAllRoutes(), parse_url($_SERVER['REQUEST_URI'])['path'])) {
        exit('HTTP method not allowed');
      } else {
        exit('Route Not Found');
      }
    }
1184981
protected function bindWebsocket()
    {
        $this->app->bind(Websocket::class, function (App $app) {
            return new Websocket($app, $app->make(RoomContract::class));
        });

        $this->app->bind('swoole.websocket', Websocket::class);
    }
962622
public function addHttpClient($client): void
    {
        if (!$client instanceof HttpClientPoolItem) {
            $client = new HttpClientPoolItem($client);
        }

        $this->clientPool[] = $client;
    }