Init a request

@param string|Request $request The url or a request with the url
@param null|array     $config  Options passed to the adapter

@throws \InvalidArgumentException If the class in not Embed\Request instance

@return Request
547651
private static function getRequest($request, array $config = null)
    {
        if (is_string($request)) {
            return new Request(
                $request,
                isset($config['class']) ? $config['class'] : null,
                isset($config['config']) ? $config['config'] : []
            );
        }

        if (!($request instanceof Request)) {
            throw new \InvalidArgumentException("Embed::create only accepts instances of Embed\\Request or strings");
        }

        return $request;
    }
920059
protected function getConfiguration(Request $request = null)
    {
        if (!$this->configuration) {
            if (!$request) {
                throw new \RuntimeException('The first time getConfiguration() is called, you must pass a Request.');
            }

            $this->configuration = new Configuration($request);
            $this->configure($request, $this->configuration);
            $this->configuration->validate();
        }

        return $this->configuration;
    }
1193012
protected function getAuth(Request $request) : Auth
    {
        $auth = $request->getAttribute($this->authAttribute);
        if (! $auth instanceof Auth) {
            throw new \InvalidArgumentException(
                'Auth attribute not available in request'
            );
        }
        return $auth;
    }
1275937
public function authenticate(array $config)
    {
        if (!$this->client) {
            throw new InvalidArgumentException('The client instance was not given to the token authenticator.');
        }

        if (!array_key_exists('token', $config)) {
            throw new InvalidArgumentException('The token authenticator requires a token.');
        }

        $this->client->authenticate($config['token'], Client::AUTH_HTTP_TOKEN);

        return $this->client;
    }
839718
protected function initialize(Request $request, ParamConverter $configuration): void
    {
        $this->request = $request;
        $this->configuration = $configuration;
        $this->options = new ParameterBag($configuration->getOptions());
    }
708702
public function init( $config = NULL )
    {
        parent::init( $config );
        
        if ( !isset( $config[ 'migration_path' ] ) )
        {
            throw new \InvalidArgumentException( 'Missing migration_path parameter' );
        }
        
        foreach ( $config as $key => $value )
        {
            switch( $key )
            {
                case 'migration_path':
                    $this->migrationPath = $value;
                    break;
                
                case 'migration_namespace':
                    $this->migrationNamespace = $value;
                    break;
                
                case 'namespaces':
                    $this->namespaces = $value;
                    break;
                
                case 'class_prefix':
                    $this->classPrefix = $value;
                    break;
                
                case 'migration_table':
                    $this->migrationTable = $value;
                    break;
                
                case 'class_name_style':
                    $this->migrationClassStyle = $value;
                    break;
                
                case 'overwrite':
                    $this->overwrite = $value;
                    break;
                
                case 'levels':
                    $this->levels = $value;
                    break;
                
                case 'name':
                    $this->migrationClass = $value;
                    break;
                
                case 'verbose':
                    $this->verbose = $value === 'true' ? TRUE : FALSE;
                    break;
                
                default:
                    // Do nothing
                    break;
            }
        }
        
        $this->doAction( self::ON_INIT_ACTION );
    }
1154279
public function apply(Request $request, ParamConverter $configuration)
    {
        if (null === $parameter = $configuration->getName()) {
            throw new InvalidConfigurationException(InvalidConfigurationException::MISSING_NAME);
        }

        // Check whether we need to let pass anonymous
        $allowAnonymous = false;
        $options = $configuration->getOptions();
        if ($options && isset($options['allowAnonymous']) && true === $options['allowAnonymous']) {
            $allowAnonymous = true;
        }

        $token = $this->tokenStorage->getToken();
        if ($token) {
            $user = $token->getUser();
            if ($user instanceof User) {
                $request->attributes->set($parameter, $user);

                return true;
            } elseif ($allowAnonymous) {
                $request->attributes->set($parameter, null);

                return true;
            }
        }

        throw new AccessDeniedException();
    }
659159
protected function setRequestBody($config)
    {
        
        $this->requestBody = isset($config['requestBody']) ? $config['requestBody'] : null;
        
        if (!$this->requestBody && $this->rawRequestBody) {
            $this->requestBody = file_get_contents("php://input");
            if (version_compare(PHP_VERSION, '5.6.0') < 0) {
                $_SERVER['php://input'] = $this->requestBody;
            }
        }
    }
826542
private static function executeAdapter($adapter, Request $request, array $config = null)
    {
        if (!in_array('Embed\\Adapters\\AdapterInterface', class_implements($adapter))) {
            throw new \InvalidArgumentException("The class '$adapter' must implements 'Embed\\Adapters\\AdapterInterface'");
        }

        if (call_user_func([$adapter, 'check'], $request)) {
            return new $adapter($request, $config);
        }

        return false;
    }
648411
protected function _initialize(AnConfig $config)
    {
        parent::_initialize($config);

        if ($config->request->view) {
            $config->controller = $config->request->view;
        }
    }
745903
public function setConfig($config)
    {
        if (is_string($config)) {
            // Treat the parameter as a filepath
            $this->config = $this->createConfig($config);
        } elseif (is_array($config)) {
            $this->config = $this->createConfig($config);
        } elseif ($config instanceof ConfigInterface) {
            $this->config = $config;
        } else {
            throw new InvalidArgumentException(sprintf(
                'Configset must be an associative array, a file path, or an instance of %s',
                ConfigInterface::class
            ));
        }

        return $this;
    }
405419
public function initialize($request)
    {
        $this->_inputStream  = new Zend_Amf_Parse_InputStream($request);
        $this->_deserializer = new Zend_Amf_Parse_Amf0_Deserializer($this->_inputStream);
        $this->readMessage($this->_inputStream);
        return $this;
    }
773317
public function authenticate(array $config) {
        if (!$this->client) {
            throw new InvalidArgumentException('The client instance was not given to the application authenticator.');
        }
        if (!array_key_exists('clientId', $config) || !array_key_exists('clientSecret', $config) || !array_key_exists('redirectUri', $config)) {
            throw new InvalidArgumentException('The application authenticator requires a client id, secret and redirect uri.');
        }
        $provider = new Bitbucket([
            'clientId'     => $config['clientId'],
            'clientSecret' => $config['clientSecret'],
            'redirectUri'  => $config['redirectUri']
        ]);
        if (!isset($_GET['code'])) {
            $authUrl = $provider->getAuthorizationUrl();
            \Session::put('oauth2state', $provider->getState());
            header('Location: ' . $authUrl);
            exit;

        } elseif (empty($_GET['state']) || ($_GET['state'] !== \Session::get('oauth2state'))) {
            unset($_SESSION['oauth2state']);
            exit('Invalid state');

        } else {
            $token = $provider->getAccessToken('authorization_code', [
                'code' => $_GET['code']
            ]);
            $this->client->getClient()->addListener(
                new OAuth2Listener(
                    array('access_token' => $token->getToken())
                )
            );
        }
        return $this->client;
    }
114573
public function config(Request $request, ConfigServiceInterface $configService)
    {
        $this->denyAccessUnlessGranted('c975LEmail-config', null);

        //Defines form
        $form = $configService->createForm('c975l/email-bundle');
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            //Validates config
            $configService->setConfig($form);

            //Redirects
            return $this->redirectToRoute('email_dashboard');
        }

        //Renders the config form
        return $this->render('@c975LConfig/forms/config.html.twig', array(
            'form' => $form->createView(),
            'toolbar' => '@c975LEmail',
        ));
    }
914677
public static function verifyServices(array $config, Request $request = null)
    {
        $request = (isset($request)) ? $request : Request::createFromGlobals();
        foreach (self::getAvailableHttpDrivers() as $driver) {
            $driver = new $driver($request, $config, new Curl());
            if ($driver instanceof VerifiesService && ! is_null($driver->verifyRequest($request))) {
                return true;
            }
        }

        return false;
    }
471360
public static function create(Request $request)
	{

		if ($request->hasParameter('classUri')) {
			$classUri = tao_helpers_Uri::decode($request->getParameter('classUri'));
			$class = new core_kernel_classes_Class($classUri);
			$hideNode = true;
		} elseif ($request->hasParameter('rootNode')) {
			$class = new core_kernel_classes_Class($request->getParameter('rootNode'));
			$hideNode = false;
		} else {
			throw new common_Exception('Missing node information for ' . __FUNCTION__);
		}

		$openNodes = array($class->getUri());
		$openNodesParameter = $request->getParameter('openNodes');
		$openParentNodesParameter = $request->getParameter('openParentNodes');

		if ($request->hasParameter('openNodes') && is_array($openNodesParameter)) {
			$openNodes = array_merge($openNodes, $openNodesParameter);
		} else if ($request->hasParameter('openParentNodes') && is_array($openParentNodesParameter)) {
			$childNodes = $openParentNodesParameter;
			$openNodes = TreeHelper::getNodesToOpen($childNodes, $class);
		}

		$limit = $request->hasParameter('limit') ? $request->getParameter('limit') : self::DEFAULT_LIMIT;
		$offset = $request->hasParameter('offset') ? $request->getParameter('offset') : 0;
		$showInstance = $request->hasParameter('hideInstances') ? !$request->getParameter('hideInstances') : true;
		$orderProp = $request->hasParameter('order') ? $request->getParameter('order') : OntologyRdfs::RDFS_LABEL;
		$orderDir = $request->hasParameter('orderdir') ? $request->getParameter('orderdir') : self::DEFAULT_ORDERDIR;

        $filterProperties = [];
		if ($request->hasParameter('filterProperties')) {
		    $filterProperties = $request->getParameter('filterProperties');
		    if (!is_array($filterProperties)) {
		        $filterProperties = [];
            }
        }

		return new self(
		    $class,
            $limit,
            $offset,
            $showInstance,
            $hideNode,
            $openNodes,
            [],
            [
                'order' => [
                    $orderProp => $orderDir
                ]
            ],
            $filterProperties
        );
	}
1112782
public function addRequest(Request $request)
    {
        $attributes = $this->createAttributes($request);

        $exchange = $this->getExchange($request->server());

        $message = json_encode($request->params());

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new Exception\InvalidArgumentException('Error during json encoding');
        }

        $exchange->publish($message, $request->routingKey(), Constants::AMQP_NOPARAM, $attributes);

        if (null !== $request->id()) {
            $this->requestIds[] = $request->id();
        }

        if (0 !== $request->expiration() && ceil($request->expiration() / 1000) > $this->timeout) {
            $this->timeout = ceil($request->expiration() / 1000);
        }

        ++$this->countRequests;
    }