The Run operation.

@param OperationHandlerContract $handler
@param ExtensionContract $extension
@param array $flags
@return mixed
@throws \Exception
187951
public function run(OperationHandlerContract $handler, ExtensionContract $extension, array $flags = [])
    {
        try {
            $name = $extension->getPackage()->getName();

            $handler->operationInfo(new Operation('Installing the [' . $name . '] extension.'));

            //$this->dispatcher->fire(new Installing($extension));
            $this->dispatcher->fire(new ComponentInstalling($extension));
            $this->extensionValidator->validateAssetsPath($extension);
            if (in_array('skip-composer', $flags, false) === false) {
                $command = 'composer require ' . $name . ':' . $this->componentsRepository->getTargetBranch($name);

                $process = $this->composerHandler->run($command, function(Process $process, $type, $buffer) use($handler) {
//                    if (Str::contains($buffer, ['Error Output', 'Exception'])) {
//                        throw new ExtensionException($process->getErrorOutput());
//                    }

                    $handler->operationInfo(new Operation($buffer));
                });

                if (!$process->isSuccessful()) {
                    throw new ExtensionException($process->getErrorOutput());
                }
            }

            $this->migrateManager->extension($name);
            $this->assetManager->extension(str_replace('/', '_', $name));
            $this->importSettings($handler, $extension);

            $this->extensionsRepository->save($extension, [
                'status'   => ExtensionContract::STATUS_INSTALLED,
                'options'  => $extension->getSettings()->getData(),
                'required' => $this->componentsRepository->isRequired($name),
            ]);
            //$this->dispatcher->fire(new Installed($extension));

            //$this->dispatcher->fire(new Installed($extension));
            $this->dispatcher->fire(new ComponentInstalled($extension));

            $operation = new Operation('The package [' . $name . '] has been successfully installed.');

            return $handler->operationSuccess($operation);
        } catch (\Exception $e) {
            Log::error($e);
            //$this->dispatcher->fire(new Failed($extension, $e));
            $this->dispatcher->fire(new ComponentInstallationFailed($extension, $e));

            return $handler->operationFailed(new Operation($e->getMessage()));
        }
    }
1198959
protected function handle($handler) {
	$handler_type = $this->get_handler_type($handler);
	
	// unmatched requests
	if (empty($handler) || empty($handler_type)) {
		$exception = bootstrap::get_library('exception');
		throw new $exception('no route found', response::STATUS_NOT_FOUND);
	}
	
	// default flow: matched requests
	$this->{'load_handler_as_'.$handler_type}($handler);
}
340149
public ExtensionHandler launch()
    throws TransformerException
  {
    ExtensionHandler handler = null;
    try
    {
      Class cl = ExtensionHandler.getClassForName(m_handlerClass);
      Constructor con = null;
      //System.out.println("class " + cl + " " + m_args + " " + m_args.length + " " + m_sig);
      if (m_sig != null)
        con = cl.getConstructor(m_sig);
      else // Pick the constructor based on number of args.
      {
        Constructor[] cons = cl.getConstructors();
        for (int i = 0; i < cons.length; i ++)
        {
          if (cons[i].getParameterTypes().length == m_args.length)
          {
            con = cons[i];
            break;
          }
        }
      }
      // System.out.println("constructor " + con);
      if (con != null)
        handler = (ExtensionHandler)con.newInstance(m_args);
      else
        throw new TransformerException("ExtensionHandler constructor not found");
    }
    catch (Exception e)
    {
      throw new TransformerException(e);
    }
    return handler;
  }
124084
private function executeHandles(&$active, &$mrc, $timeout = 1)
    {
        do {
            $mrc = curl_multi_exec($this->multiHandle, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM && $active);
        $this->checkCurlResult($mrc);

        // @codeCoverageIgnoreStart
        // Select the curl handles until there is any activity on any of the open file descriptors
        // See https://github.com/php/php-src/blob/master/ext/curl/multi.c#L170
        if ($active && $mrc == CURLM_OK && curl_multi_select($this->multiHandle, $timeout) == -1) {
            // Perform a usleep if a previously executed select returned -1
            // @see https://bugs.php.net/bug.php?id=61141
            usleep(100);
        }
        // @codeCoverageIgnoreEnd
    }
703317
public function run(OperationHandlerContract $handler, array $extensionsNames)
    {
        if (count($extensionsNames) === 0) {
            return $handler->operationInfo(new Operation('No extensions to install. Skipping composer.'));
        }
        $required = (array) config('components.required', []);

        $modules = [];
        if (!empty($required)) {
            foreach ($extensionsNames as $extension) {
                list($requiredExtension) = explode(':', $extension);
                if (!in_array($requiredExtension, $required)) {
                    array_push($modules, $extension);
                }
            }
        } else {
            $modules = $extensionsNames;
        }
        $names   = implode(' ', $modules);
        $command = 'composer require ' . $names . ' --no-progress';


        try {
            $handler->operationInfo(new Operation('Running composer command.'));
            $process = $this->composerHandler->run($command, function(Process $process, $type, $buffer) use($handler) {


                $handler->operationInfo(new Operation($buffer));
            });

            if (!$process->isSuccessful()) {
                throw new ExtensionException($process->getErrorOutput());
            }

            $this->dispatcher->fire(new Success($command));

            return $handler->operationInfo(new Operation('Composer command has been finished.'));
        } catch (\Exception $e) {
            Log::error($e);
            $this->dispatcher->fire(new Failed($command, $e));

            return $handler->operationFailed(new Operation($e->getMessage()));
        }
    }
1259712
public function afterHandlerSelected(AbstractHandler $handler)
    {
        parent::afterHandlerSelected($handler);
        if (false === $this->isRequestCrossOrigin() || !($handler instanceof AbstractRequestHandler)) {
            // since the request isn't cross origin we don't need this plugin to
            // do any processing at all
            return;
        }

        $request = $handler->getRequest();
        if (null === $request) {
            // the CORS plugin only supports handlers with standard requests
            return;
        }
        $requests = array($request);
        if ($handler instanceof BatchRequestHandlerInterface) {
            $requests = $handler->getRequests();
        }
        $this->processRequestsForAccessDenial($requests);

        // let the browser know this domain can make cross origin requests
        @header(self::HEADER_ALLOW_ORIGIN.': '.$_SERVER[self::HEADER_CLIENT_ORIGIN]);
        // do not explicitly block requests that pass a cookie
        @header(self::HEADER_ALLOW_CREDENTIALS.': true');

        if ('OPTIONS' === strtoupper($request->getVerb())) {
            $this->addHeadersForOptionsRequests();
        }
    }
160616
public function process(Request $request, Handler $handler): Response
    {
        try {
            $symfonyRequest = (new HttpFoundationFactory())
                ->createRequest($request);
            $this->router->getContext()->fromRequest($symfonyRequest);
            $route = $this->router
                ->matchRequest($symfonyRequest);
        } catch (MethodNotAllowedException $e) {
            $allows = implode(', ', $e->getAllowedMethods());
            return $this->createResponse(405, $e->getMessage())
                    ->withHeader('Allow', $allows);
        } catch (NoConfigurationException $e) {
            return $this->createResponse(500, $e->getMessage());
        } catch (ResourceNotFoundException $e) {
            return $this->createResponse(404, $e->getMessage());
        }

        foreach ($route as $key => $value) {
            $request = $request->withAttribute($key, $value);
        }

        return $handler->handle($request);
    }
661458
public static function runThis(Application $app, array $handlers, ServerRequestInterface $request)
    {
        return $app->set($handlers)
            ->run($request, new Emitter());
    }
533635
public function bindHandler($commandName, $handler)
    {
        // If the $handler given is an instance of CommandHandler, simply bind that
        if ($handler instanceof CommandHandler) {
            $this->handlers[$commandName] = $handler;
            return;
        }

        // If the handler given is callable, wrap it up in a CallableCommandHandler for executing later
        if (is_callable($handler)) {
            return $this->bindHandler($commandName, new CallableCommandHandler($handler));
        }

        // If the handler given is a string, wrap it up in a LazyLoadingCommandHandler for loading later
        if (is_string($handler)) {
            return $this->bindHandler($commandName, new LazyLoadingCommandHandler($handler, $this->container));
        }

        throw new \InvalidArgumentException('Could not push handler. Command Handlers should be an
            instance of Chief\CommandHandler, a callable, or a string representing a CommandHandler class');
    }
1076578
public function handle(Manager $manager, Container $container, Composer $composer)
    {
        $output = new OperationFileOutput($this->outputFileName);

        $composer->run($output, $this->extensionsNames);

        if ($output->failed()) {
            return;
        }

        $this->flags = array_merge($this->flags, ['skip-composer']);

        foreach ($this->extensionsNames as $extensionName) {
            $extensionName = explode(':', $extensionName)[0];
            $extension     = $manager->getAvailableExtensions()->findByName($extensionName);

            foreach ($this->operationsClassNames as $operationClassName) {
                $operation = $container->make($operationClassName);

                if ($extension instanceof ExtensionContract && $operation instanceof OperationContract) {
                    $operation->run($output, $extension, $this->flags);
                }
            }
        }
    }
1044151
protected function callMulti($handler)
    {
        $running = null;

        do {
            $stat = curl_multi_exec($handler, $running);
        } while ($stat === CURLM_CALL_MULTI_PERFORM);
        if (!$running || $stat !== CURLM_OK) {
            throw new \RuntimeException('failed to initialized cURL');
        }

        do {
            curl_multi_select($handler, $this->timeout);
            do {
                $stat = curl_multi_exec($handler, $running);
            } while ($stat === CURLM_CALL_MULTI_PERFORM);
            do {
                if ($read = curl_multi_info_read($handler, $remains)) {
                    $response = curl_multi_getcontent($read['handle']);

                    if ($response === false) {
                        $info = curl_getinfo($read['handle']);
                        throw new \RuntimeException("error: {$info['url']}: {$info['http_code']}");
                    }
                    curl_multi_remove_handle($handler, $read['handle']);
                    curl_close($read['handle']);
                }
            } while ($remains);
        } while ($running);
        curl_multi_close($handler);
    }
1142490
protected void registerAddOperation(final ManagementResourceRegistration registration, final AbstractAddStepHandler handler,
                                        OperationEntry.Flag... flags) {
        registration.registerOperationHandler(getOperationDefinition(ModelDescriptionConstants.ADD,
                new DefaultResourceAddDescriptionProvider(registration, descriptionResolver, orderedChild), OperationEntry.EntryType.PUBLIC, flags)
                , handler);
    }
1213570
function onServerPreRequestHandler (ctx, err, value) {
  if (err) {
    if (err instanceof SuperError) {
      ctx._response.error = err.rootCause || err.cause || err;
    } else {
      ctx._response.error = err;
    }

    return ctx.finish();
  }

  // reply value from extension
  if (value) {
    ctx._response.payload = value;
    return ctx.finish();
  }

  // check if a handler is registered with this pattern
  if (ctx._actMeta) {
    ctx._extensions.onServerPreHandler.dispatch(ctx, (err, val) => {
      return onServerPreHandler(ctx, err, val);
    });
  } else {
    const internalError = new Errors.PatternNotFound(Constants.PATTERN_NOT_FOUND, ctx.errorDetails);
    ctx.log.error(internalError);
    ctx._response.error = internalError;

    // send error back to callee
    ctx.finish();
  }
}
1015068
private function invokeCallback ( Request $request, $handler ) {
      try {
        return call_user_func_array( $handler, array( $this, $request ) );
      } catch ( \Exception $ex ) {
        $this->exception = $ex;
        return call_user_func_array( $this->onException, array( $this, $request ) );
      }
    }
639016
public function afterHandlerSelected(AbstractHandler $handler)
    {
        parent::afterHandlerSelected($handler);

        $auth = $this->get($this->authKey);
        if (!($auth instanceof AuthenticatorInterface)) {
            throw new InternalErrorException(sprintf(
                "Implementation of AuthenticationInterface required. Please check your %s configuration.",
                $this->authKey
            ));
        }

        if (!($credentials = $this->getCredentials())) {
            throw new UnauthorizedException("Authentication is required to access this resource.");
        }

        if (!$auth->authenticate($credentials)) {
            throw new UnauthorizedException("Authentication is required to access this resource.");
        }
    }
331204
public static function forCommand(Command $command, CommandHandler $handler, string $message = ''): self
    {
        return new static(
            sprintf(
                'The command [%s] could not be handled by [%s].  %s',
                $command::schema()->getId()->toString(),
                get_class($handler),
                $message
            ),
            Code::INTERNAL
        );
    }
1026245
public function callHandler(array $command, $method, $args = array())
    {
        try {
            $handlers = $this->getHandlers();
            return Handler::call($handlers, $command['command_id'], $method, $args);
        } catch (Exception $ex) {
            return $ex->getMessage();
        }
    }