コード例 #1
0
ファイル: Request.php プロジェクト: n3b/symfony
    /**
     * Overrides the PHP global variables according to this request instance.
     *
     * It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE.
     * $_FILES is never override, see rfc1867
     *
     * @api
     */
    public function overrideGlobals()
    {
        $_GET = $this->query->all();
        $_POST = $this->request->all();
        $_SERVER = $this->server->all();
        $_COOKIE = $this->cookies->all();

        foreach ($this->headers->all() as $key => $value) {
            $key = strtoupper(str_replace('-', '_', $key));
            if (in_array($key, array('CONTENT_TYPE', 'CONTENT_LENGTH'))) {
                $_SERVER[$key] = implode(', ', $value);
            } else {
                $_SERVER['HTTP_'.$key] = implode(', ', $value);
            }
        }

        $request = array('g' => $_GET, 'p' => $_POST, 'c' => $_COOKIE);

        $requestOrder = ini_get('request_order') ?: ini_get('variable_order');
        $requestOrder = preg_replace('#[^cgp]#', '', strtolower($requestOrder)) ?: 'gp';

        $_REQUEST = array();
        foreach (str_split($requestOrder) as $order) {
            $_REQUEST = array_merge($_REQUEST, $request[$order]);
        }
    }
コード例 #2
0
 public function testReplace()
 {
     $bag = new ParameterBag(array('foo' => 'bar'));
     $bag->replace(array('FOO' => 'BAR'));
     $this->assertEquals(array('FOO' => 'BAR'), $bag->all(), '->replace() replaces the input with the argument');
     $this->assertFalse($bag->has('foo'), '->replace() overrides previously set the input');
 }
コード例 #3
0
 /**
  * Get Values by the Query String with the option of
  * Remove some of them
  *
  * @param array $valuesToRemove
  * @return array Values to Get
  */
 private function getValues(array $valuesToRemove = array())
 {
     $values = array();
     foreach (array_diff_key($this->query->all(), $valuesToRemove) as $property => $value) {
         $values[$this->resource->getProperties()->get($property)->getInternalName()] = $value;
     }
     return $values;
 }
コード例 #4
0
ファイル: Renderer.php プロジェクト: gobjila/BackBee
 /**
  * Update every helpers and every registered renderer adapters with the right AbstractRenderer;
  * this method is called everytime we unset a renderer
  */
 protected function updatesAfterUnset()
 {
     $this->updateHelpers();
     foreach ($this->rendererAdapters->all() as $ra) {
         $ra->onRestorePreviousRenderer($this);
     }
     return $this;
 }
コード例 #5
0
 public function it_throws_an_exception_for_an_invalid_request(Request $request, ParameterBag $post, ParameterBag $get)
 {
     $request->request = $post;
     $request->query = $get;
     $post->all()->willReturn([]);
     $get->all()->willReturn(['text' => 'Hello!']);
     $this->shouldThrow()->during('convert', [$request]);
 }
コード例 #6
0
 public function transform(ParameterBag $item)
 {
     foreach ($item->all() as $key => $value) {
         // if value is an array with a hash, that's a serialized node's text value
         if (is_array($value) && array_key_exists('#', $value)) {
             $item->set($key, $value['#']);
         }
     }
 }
コード例 #7
0
ファイル: Request.php プロジェクト: speedwork/core
 /**
  * Get the response header.
  *
  * @param string $key
  *
  * @return mixed
  */
 public function getResponseCookie($key = null, $default = null)
 {
     if (!isset($this->cookie)) {
         $this->cookie = new ParameterBag();
     }
     if (is_null($key)) {
         return $this->cookie->all();
     }
     return $this->cookie->get($key, $default);
 }
コード例 #8
0
ファイル: Request.php プロジェクト: roydonstharayil/sugarbox
 protected function initializeHeaders()
 {
     $headers = array();
     foreach ($this->server->all() as $key => $value) {
         if ('http_' === strtolower(substr($key, 0, 5))) {
             $headers[substr($key, 5)] = $value;
         }
     }
     return $headers;
 }
コード例 #9
0
 /**
  * @param string                                         $url
  * @param \Symfony\Component\HttpFoundation\ParameterBag $params
  *
  * @return string
  */
 private function _pageUrl($url, ParameterBag $params)
 {
     if (!$url) {
         return '';
     }
     $allParams = $params->all();
     unset($allParams['page']);
     $strParams = http_build_query($allParams);
     return $url . '&' . $strParams;
 }
コード例 #10
0
 public function it_handles_authorization_refusal(AuthorizeControllerInterface $oauth2AuthorizeController, ParameterBag $requestBag, Application $app, Request $request, TokenStorageInterface $tokenStorage)
 {
     $app->offsetGet('security.token_storage')->willReturn($tokenStorage);
     $requestBag->all()->willReturn(['authorize' => '0']);
     $responseArgument = Argument::type('OAuth2\\HttpFoundationBridge\\Response');
     $requestArgument = Argument::type('OAuth2\\HttpFoundationBridge\\Request');
     $oauth2AuthorizeController->handleAuthorizeRequest($requestArgument, $responseArgument, false, null)->shouldBeCalled();
     $response = $this->__invoke($app, $request);
     $response->shouldHaveType('OAuth2\\HttpFoundationBridge\\Response');
     $response->getStatusCode()->shouldReturn(200);
 }
コード例 #11
0
 protected function verifySignature()
 {
     $signer = new Signer($this->params->all());
     $signer->setSort($this->sort);
     $signer->setEncodePolicy($this->encodePolicy);
     $content = $signer->getContentToSign();
     $sign = $this->params->get('sign');
     $match = (new Signer())->verifyWithRSA($content, $sign, $this->getAlipayPublicKey());
     if (!$match) {
         throw new InvalidRequestException('The signature is not match');
     }
 }
コード例 #12
0
 public function it_renders_authenticated_authorize_view(UrlGeneratorInterface $urlGenerator, AuthorizeControllerInterface $oauth2AuthorizeController, AuthorizeRenderer $authorizeRenderer, Application $app, Request $request, ParameterBag $queryBag, BridgeResponse $response, TokenStorageInterface $tokenStorage, TokenInterface $token)
 {
     $responseArgument = Argument::type('OAuth2\\HttpFoundationBridge\\Response');
     $requestArgument = Argument::type('OAuth2\\HttpFoundationBridge\\Request');
     $oauth2AuthorizeController->validateAuthorizeRequest($requestArgument, $responseArgument)->willReturn(true);
     $urlGenerator->generate('oauth2_authorize_handler', Argument::any())->willReturn('/url');
     $queryBag->all()->willReturn(['client_id' => 'clientId', 'response_type' => 'responseType']);
     $app->offsetGet('security.token_storage')->willReturn($tokenStorage);
     $tokenStorage->getToken()->willReturn($token);
     $token->getUser()->willReturn('user');
     $authorizeRenderer->render('/url', 'clientId', 'responseType', 'user')->willReturn($response);
     $this->__invoke($app, $request)->shouldReturn($response);
 }
コード例 #13
0
ファイル: Request.php プロジェクト: rfc1483/symfony
 /**
  * Overrides the PHP global variables according to this request instance.
  *
  * It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE, and $_FILES.
  */
 public function overrideGlobals()
 {
     $_GET = $this->query->all();
     $_POST = $this->request->all();
     $_SERVER = $this->server->all();
     $_COOKIE = $this->cookies->all();
     // FIXME: populate $_FILES
     foreach ($this->headers->all() as $key => $value) {
         $_SERVER['HTTP_' . strtoupper(str_replace('-', '_', $key))] = implode(', ', $value);
     }
     // FIXME: should read variables_order and request_order
     // to know which globals to merge and in which order
     $_REQUEST = array_merge($_GET, $_POST);
 }
コード例 #14
0
 function it_returns_grid_data_for_non_html_requests(RequestConfiguration $requestConfiguration, RepositoryInterface $repository, Grid $gridDefinition, GridProviderInterface $gridProvider, ResourceGridViewFactoryInterface $gridViewFactory, ResourceGridView $gridView, Pagerfanta $paginator, MetadataInterface $metadata, Request $request, ParameterBag $queryParameters)
 {
     $requestConfiguration->hasGrid()->willReturn(true);
     $requestConfiguration->getGrid()->willReturn('sylius_admin_tax_category');
     $requestConfiguration->getMetadata()->willReturn($metadata);
     $requestConfiguration->isHtmlRequest()->willReturn(false);
     $requestConfiguration->getRequest()->willReturn($request);
     $request->query = $queryParameters;
     $queryParameters->all()->willReturn(['foo' => 'bar']);
     $gridProvider->get('sylius_admin_tax_category')->willReturn($gridDefinition);
     $gridViewFactory->create($gridDefinition, Argument::type(Parameters::class), $metadata, $requestConfiguration)->willReturn($gridView);
     $gridView->getData()->willReturn($paginator);
     $this->getResources($requestConfiguration, $repository)->shouldReturn($paginator);
 }
コード例 #15
0
 /**
  * @inheritdoc
  */
 public function transform(ParameterBag $item)
 {
     if (!$this->field) {
         // expand root-level attributes
         $item->replace($this->expand($item->all()));
         return;
     }
     // proceed only when the field exists and is an array
     $value = $item->get($this->field);
     if (!is_array($value)) {
         return;
     }
     $item->set($this->field, $this->expand($value));
 }
 function let(TranslatorInterface $translator, Router $router, LocaleManager $localeManager, RequestStack $requestStack, Request $request, ParameterBag $query, ParameterBag $server)
 {
     $localeManager->getLocale()->willReturn('en');
     $request->getLocale()->willReturn('en');
     $request->get('_route_params')->willReturn(array('element' => 'event', 'locale' => 'en'));
     $request->get('_route')->willReturn('admin_translatable_list');
     $requestStack->getCurrentRequest()->willReturn($request);
     $query->all()->willReturn(array('param1' => 'val1', 'redirect_uri' => '/admin/en/list/element?param=value'));
     $request->query = $query;
     $router->matchRequest(Argument::that(function ($argument) {
         return $argument->server->get('REQUEST_URI') === '/admin/en/list/element' && $argument->server->get('QUERY_STRING') === 'param=value';
     }))->willReturn(array('_route' => 'some_admin_route', 'locale' => 'en', 'element' => 'element'));
     $request->server = $server;
     $localeManager->getLocales()->willReturn(array('pl', 'en', 'de'));
     $translator->trans('admin.locale.dropdown.title', array('%locale%' => 'en'), 'FSiAdminTranslatableBundle')->willReturn('Menu label');
     $this->beConstructedWith($translator, $router, $localeManager, $requestStack);
 }
コード例 #17
0
 function it_creates_a_paginated_representation_for_pagerfanta_for_non_html_requests(ResourcesResolverInterface $resourcesResolver, RequestConfiguration $requestConfiguration, RepositoryInterface $repository, Pagerfanta $paginator, Request $request, ParameterBag $queryParameters, ParameterBag $requestAttributes, PagerfantaFactory $pagerfantaRepresentationFactory, PaginatedRepresentation $paginatedRepresentation)
 {
     $requestConfiguration->isHtmlRequest()->willReturn(false);
     $requestConfiguration->getPaginationMaxPerPage()->willReturn(8);
     $resourcesResolver->getResources($requestConfiguration, $repository)->willReturn($paginator);
     $requestConfiguration->getRequest()->willReturn($request);
     $request->query = $queryParameters;
     $queryParameters->get('page', 1)->willReturn(6);
     $queryParameters->all()->willReturn(['foo' => 2, 'bar' => 15]);
     $request->attributes = $requestAttributes;
     $requestAttributes->get('_route')->willReturn('sylius_product_index');
     $requestAttributes->get('_route_params')->willReturn(['slug' => 'foo-bar']);
     $paginator->setMaxPerPage(8)->shouldBeCalled();
     $paginator->setCurrentPage(6)->shouldBeCalled();
     $pagerfantaRepresentationFactory->createRepresentation($paginator, Argument::type(Route::class))->willReturn($paginatedRepresentation);
     $this->get($requestConfiguration, $repository)->shouldReturn($paginatedRepresentation);
 }
コード例 #18
0
ファイル: Request.php プロジェクト: tonjoo/tiga-framework
 /**
  * Populate $input variable with Request.
  */
 private function populateInput()
 {
     // If already populate, return
     if ($this->input) {
         return;
     }
     //POST
     if ($this->isJson()) {
         $json = new ParameterBag((array) json_decode($this->getContent(), true));
         $post = $json->all();
     } else {
         $post = $this->request->all();
     }
     // GET
     $get = $this->query->all();
     $this->input = array_merge($get, $post);
 }
コード例 #19
0
ファイル: SearchManager.php プロジェクト: ojs/ojs
 /**
  * @param $aggKey
  * @param $bucketKey
  * @param bool $add
  * @return string
  */
 public function getAggLink($aggKey, $bucketKey, $add = true)
 {
     $routeParams = $this->request->attributes->get('_route_params');
     $routeParams['page'] = 1;
     $requestQueryParams = $this->requestQuery->all();
     $requestAggsBag = $this->getRequestAggsBag();
     if ($add) {
         $requestAggsBag[$aggKey][] = $bucketKey;
     } else {
         $searchBucketKey = array_search($bucketKey, $requestAggsBag[$aggKey]);
         if ($searchBucketKey !== false) {
             unset($requestAggsBag[$aggKey][$searchBucketKey]);
         }
     }
     $setupAggs['aggs'] = $requestAggsBag;
     $allRouteParams = array_merge($routeParams, $requestQueryParams, $setupAggs);
     return $this->router->generate('ojs_search_index', $allRouteParams);
 }
コード例 #20
0
 /**
  * Check if all required parameters are present
  *
  * @param ParameterBag $parameterBag
  * @param array        $parameters
  * @param bool         $deepSearch Deep search
  */
 protected function requireParameters(ParameterBag $parameterBag, array $parameters = [], $deepSearch = false)
 {
     foreach ($parameters as $parameter) {
         if (!$parameterBag->has($parameter)) {
             // search deep in the array
             // some.value looked in $input['some.value'] and $input['some']['value']
             if ($deepSearch && strstr($parameter, '.') !== -1) {
                 $input = $parameterBag->all();
                 $parts = explode('.', $parameter);
                 foreach ($parts as $part) {
                     if (!isset($input[$part])) {
                         throw new BadRequestHttpException('Missing required ' . $parameter . ' parameter');
                     }
                     $input = $input[$part];
                 }
             } else {
                 throw new BadRequestHttpException('Missing required ' . $parameter . ' parameter');
             }
         }
     }
 }
コード例 #21
0
 /**
  * Filters query parameter bag
  *
  * @param string       $filterName
  * @param ParameterBag $bag
  *
  * @return ParameterBag
  */
 public function filter($filterName, ParameterBag $bag)
 {
     $expectedParams = $this->filters[$filterName];
     // Given parameters
     foreach ($bag->all() as $name => $value) {
         if (!isset($expectedParams[$name])) {
             throw new \InvalidArgumentException(sprintf('Unknow parameter "%s"', $name));
         }
         $options = $expectedParams[$name];
         if (0 < count($options['roles']) && !$this->authorizationChecker->isGranted($options['roles'])) {
             throw new AccessDeniedException(sprintf('User has not the required role to use "%s" parameter', $name));
         }
         $this->validator->validate($name, $options, $value);
         $bag->set($name, $this->caster->cast($options, $value));
     }
     // Expected parameters
     foreach ($expectedParams as $name => $options) {
         Validator::checkMissingParameter($name, $options, $bag);
         if (!$bag->has($name) && isset($options['default'])) {
             $bag->set($name, $this->caster->getDefaultValue($options));
         }
     }
     return $bag;
 }
コード例 #22
0
 protected function verifySignature()
 {
     $signer = new Signer($this->params->all());
     $signer->setSort($this->sort);
     $content = $signer->getContentToSign();
     $sign = $this->params->get('sign');
     $signType = strtoupper($this->params->get('sign_type'));
     if ($signType == 'MD5') {
         if (!$this->getKey()) {
             throw new InvalidRequestException('The `key` is required for `MD5` sign_type');
         }
         $match = (new Signer())->verifyWithMD5($content, $sign, $this->getKey());
     } elseif ($signType == 'RSA') {
         if (!$this->getAlipayPublicKey()) {
             throw new InvalidRequestException('The `alipay_public_key` is required for `RSA` sign_type');
         }
         $match = (new Signer())->verifyWithRSA($content, $sign, $this->getAlipayPublicKey());
     } else {
         throw new InvalidRequestException('The `sign_type` is invalid');
     }
     if (!$match) {
         throw new InvalidRequestException('The signature is not match');
     }
 }
コード例 #23
0
 protected function parseConnections($options, $defaultHost, $defaultPort)
 {
     if (isset($options['host']) || isset($options['port'])) {
         $options['connections'][] = $options;
     } elseif ($options['connection']) {
         $options['connections'][] = $options['connection'];
     }
     /** @var ParameterBag[] $toParse */
     $toParse = [];
     if (isset($options['connections'])) {
         foreach ((array) $options['connections'] as $alias => $conn) {
             if (is_string($conn)) {
                 $conn = ['host' => $conn];
             }
             $conn += ['scheme' => 'tcp', 'host' => $defaultHost, 'port' => $defaultPort];
             $conn = new ParameterBag($conn);
             if ($conn->has('password')) {
                 $conn->set('pass', $conn->get('password'));
                 $conn->remove('password');
             }
             $conn->set('uri', Uri::fromParts($conn->all()));
             $toParse[] = $conn;
         }
     } elseif (isset($options['save_path'])) {
         foreach (explode(',', $options['save_path']) as $conn) {
             $uri = new Uri($conn);
             $connBag = new ParameterBag();
             $connBag->set('uri', $uri);
             $connBag->add(parse_query($uri->getQuery()));
             $toParse[] = $connBag;
         }
     }
     $connections = [];
     foreach ($toParse as $conn) {
         /** @var Uri $uri */
         $uri = $conn->get('uri');
         $parts = explode(':', $uri->getUserInfo(), 2);
         $password = isset($parts[1]) ? $parts[1] : null;
         $connections[] = ['scheme' => $uri->getScheme(), 'host' => $uri->getHost(), 'port' => $uri->getPort(), 'path' => $uri->getPath(), 'alias' => $conn->get('alias'), 'prefix' => $conn->get('prefix'), 'password' => $password, 'database' => $conn->get('database'), 'persistent' => $conn->get('persistent'), 'weight' => $conn->get('weight'), 'timeout' => $conn->get('timeout')];
     }
     return $connections;
 }
コード例 #24
0
 /**
  * @return array
  */
 public function getParameters()
 {
     return $this->parameters->all();
 }
コード例 #25
0
ファイル: ItemBag.php プロジェクト: treehouselabs/io-bundle
 /**
  * Returns all data from the item, ordered by key.
  */
 public function all()
 {
     $all = parent::all();
     ksort($all);
     return $all;
 }
コード例 #26
0
 public function testRemoveOriginalRootAttribute()
 {
     $transformer = new ExpandAttributesTransformer(null, true);
     $transformer->transform($this->item);
     $this->assertEquals(['id' => 1234, 'img' => ['@src' => 'foo', 'bar' => 'baz']], $this->item->all());
 }
コード例 #27
0
 function it_creates_a_pagniated_respresentation_for_pagerfanta_for_non_html_requests(RequestConfiguration $requestConfiguration, RepositoryInterface $repository, Pagerfanta $paginator, Request $request, ParameterBag $queryParameters, ParameterBag $requestAttributes, PagerfantaFactory $pagerfantaRepresentationFactory, PaginatedRepresentation $paginatedRepresentation)
 {
     $requestConfiguration->isHtmlRequest()->willReturn(false);
     $requestConfiguration->getRepositoryMethod()->willReturn(null);
     $requestConfiguration->isPaginated()->willReturn(true);
     $requestConfiguration->isLimited()->willReturn(false);
     $requestConfiguration->getCriteria()->willReturn(array());
     $requestConfiguration->getSorting()->willReturn(array());
     $repository->createPaginator(array(), array())->willReturn($paginator);
     $requestConfiguration->getRequest()->willReturn($request);
     $request->query = $queryParameters;
     $queryParameters->get('page', 1)->willReturn(6);
     $queryParameters->all()->willReturn(array('foo' => 2, 'bar' => 15));
     $request->attributes = $requestAttributes;
     $requestAttributes->get('_route')->willReturn('sylius_product_index');
     $requestAttributes->get('_route_params')->willReturn(array('slug' => 'foo-bar'));
     $paginator->setCurrentPage(6)->shouldBeCalled();
     $pagerfantaRepresentationFactory->createRepresentation($paginator, Argument::type(Route::class))->willReturn($paginatedRepresentation);
     $this->get($requestConfiguration, $repository)->shouldReturn($paginatedRepresentation);
 }
コード例 #28
0
ファイル: Coordinator.php プロジェクト: benakacha/Sylius
 /**
  * Redirect to step display action.
  *
  * @param ProcessInterface $process
  * @param StepInterface    $step
  * @param ParameterBag     $queryParameters
  *
  * @return RedirectResponse
  */
 protected function redirectToStepDisplayAction(ProcessInterface $process, StepInterface $step, ParameterBag $queryParameters = null)
 {
     $this->context->addStepToHistory($step->getName());
     if (null !== ($route = $process->getDisplayRoute())) {
         $url = $this->router->generate($route, array_merge($process->getDisplayRouteParams(), array('stepName' => $step->getName()), $queryParameters ? $queryParameters->all() : array()));
         return new RedirectResponse($url);
     }
     // Default parameters for display route
     $routeParameters = array('scenarioAlias' => $process->getScenarioAlias(), 'stepName' => $step->getName());
     if (null !== $queryParameters) {
         $routeParameters = array_merge($queryParameters->all(), $routeParameters);
     }
     return new RedirectResponse($this->router->generate('sylius_flow_display', $routeParameters));
 }
コード例 #29
0
 /**
  * @inheritdoc
  */
 public function transform(ParameterBag $item)
 {
     $parameters = $item->all();
     $this->trimValues($parameters);
     $item->replace($parameters);
 }
コード例 #30
0
ファイル: Loader.php プロジェクト: blankse/ezpublish-kernel-1
 /**
  * Builds legacy kernel handler CLI
  *
  * @return CLIHandler
  */
 public function buildLegacyKernelHandlerCLI()
 {
     $legacyRootDir = $this->legacyRootDir;
     $webrootDir = $this->webrootDir;
     $eventDispatcher = $this->eventDispatcher;
     $container = $this->container;
     $that = $this;
     return function () use($legacyRootDir, $webrootDir, $container, $eventDispatcher, $that) {
         if (!$that->getCLIHandler()) {
             chdir($legacyRootDir);
             $legacyParameters = new ParameterBag($container->getParameter('ezpublish_legacy.kernel_handler.cli.options'));
             if ($that->getBuildEventsEnabled()) {
                 $eventDispatcher->dispatch(LegacyEvents::PRE_BUILD_LEGACY_KERNEL, new PreBuildKernelEvent($legacyParameters));
             }
             $that->setCLIHandler(new CLIHandler($legacyParameters->all(), $container->get('ezpublish.siteaccess'), $container));
             chdir($webrootDir);
         }
         return $that->getCLIHandler();
     };
 }