예제 #1
0
 /**
  * @param Request $request
  * @param int     $type
  * @param bool    $catch
  *
  * @return Response
  * @throws \Exception
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     if ($type === HttpKernelInterface::SUB_REQUEST) {
         return $this->app->handle($request, $type, $catch);
     }
     $parameters = $this->config->get('cookie_parameters');
     if (!isset($parameters[$this->config->get('current_locale')])) {
         throw new \Exception(sprintf('Domain %s not available', $this->config->get('current_locale')));
     }
     $cookieParams = $parameters[$this->config->get('current_locale')];
     $this->config->set('current_cookie_domain', $cookieParams['domain']);
     if (HttpKernelInterface::MASTER_REQUEST !== $type) {
         return $this->app->handle($request, $type, $catch);
     }
     $session = new Session();
     $request->setSession($session);
     $cookies = $request->cookies;
     if ($cookies->has($session->getName())) {
         $session->setId($cookies->get($session->getName()));
     } else {
         //starts the session if no session exists
         $session->start();
         $session->migrate(false);
     }
     $session->start();
     $response = $this->app->handle($request, $type, $catch);
     if ($session && $session->isStarted()) {
         $session->save();
         $params = array_merge(session_get_cookie_params(), $cookieParams);
         $cookie = new Cookie($session->getName(), $session->getId(), 0 === $params['lifetime'] ? 0 : $request->server->get('REQUEST_TIME') + $params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']);
         $response->headers->setCookie($cookie);
     }
     return $response;
 }
예제 #2
0
 /**
  * @covers Symfony\Component\HttpFoundation\ParameterBag::set
  */
 public function testSet()
 {
     $bag = new ParameterBag(array());
     $bag->set('foo', 'bar');
     $this->assertEquals('bar', $bag->get('foo'), '->set() sets the value of parameter');
     $bag->set('foo', 'baz');
     $this->assertEquals('baz', $bag->get('foo'), '->set() overrides previously set parameter');
 }
예제 #3
0
 protected function setParameter($key, $value)
 {
     if (null !== $this->response) {
         throw new RuntimeException('Request cannot be modified after it has been sent!');
     }
     $this->parameters->set($key, $value);
     return $this;
 }
예제 #4
0
 /**
  * Adds a parameter
  *
  * @param string $name
  * @param mixed  $value
  *
  * @return $this
  *
  * @throws \Thuata\ComponentBundle\Exception\InvalidParameterTypeException
  */
 public function addParameter(string $name, $value)
 {
     if (!is_scalar($value)) {
         throw new InvalidParameterTypeException(__CLASS__, __METHOD__, 1, 'scalar', gettype($value));
     }
     $this->parameters->set($name, $value);
     return $this;
 }
 private function addRequestParamForEvent(Notifications $notifications, $eventName, ParameterBag $params)
 {
     $event = $notifications->getNotificationEvent($eventName);
     if ($event->isActive()) {
         $params->set('events[' . $eventName . ']', 'true');
     } else {
         $params->set('events[' . $eventName . ']', 'false');
     }
 }
예제 #6
0
 /**
  * @param Request $request
  * @param int     $type
  * @param bool    $catch
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $host = $request->getHttpHost();
     $sites = $this->config->get('default_site_id');
     $site = str_replace('.', '_', $host);
     $sid = isset($sites[$site]) ? $sites[$site] : $sites['default'];
     $this->config->set('side_id', $sid);
     $this->config->set('current_site_id', $sid);
     return $this->app->handle($request, $type, $catch);
 }
예제 #7
0
 /**
  * {@inheritDoc}
  */
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     if (!$request->headers->has($this->header)) {
         $uuid = (string) ($uuid = Uuid::uuid4());
         $request->headers->set($this->header, $uuid);
         $this->config->set('request_id', $uuid);
     } else {
         $this->config->set('request_id', (string) $request->headers->get($this->header));
     }
     $response = $this->app->handle($request, $type, $catch);
     $response->headers->set($this->header, (string) $this->config->get('request_id'));
     return $response;
 }
 public function configureActionsVars(ParameterBag $actionsVars)
 {
     if ($this->container->isScopeActive('request')) {
         $actionsVars->set('batchSelector', new BatchSelector($actionsVars->get('admin_session')));
     }
     $checkIdClosure = $this->getOption('checkIdClosure');
     if (!$checkIdClosure instanceof \Closure) {
         throw new \RuntimeException('The checkIdClosure is not a closure.');
     }
     $container = $this->container;
     $actionsVars->set('batchCheckIdClosure', function ($id) use($checkIdClosure, $container) {
         return call_user_func_array($checkIdClosure, array($id, $container));
     });
 }
예제 #9
0
 /**
  * @param ParameterBag $item
  *
  * @throws TransformationFailedException
  */
 public function transform(ParameterBag $item)
 {
     if (!$item->has($this->field)) {
         return;
     }
     $value = $item->get($this->field);
     try {
         $newValue = $this->transformer->transform($value);
         $item->set($this->field, $newValue);
     } catch (TransformationFailedException $e) {
         // set the value to null as we couldn't transform it
         $item->set($this->field, null);
         throw new TransformationFailedException(sprintf('Transforming "%s" using "%s" failed with message: %s.', $this->field, get_class($this->transformer), $e->getMessage()), null, $e);
     }
 }
예제 #10
0
 public function boot()
 {
     if (true === $this->booted) {
         return;
     }
     $this->internalConfig = $this->getContainerConfiguration($this->containerConfigPath)->load();
     $this->config = new ParameterBag($this->internalConfig['parameters']);
     $this->config->set('debug', !$this->config->get('production_mode', true));
     if (null === $this->config->get('root_dir')) {
         throw new BadConfigurationException('You should define root_dir in config');
     }
     $logDir = $this->config->get('log_dir');
     if (null === $logDir) {
         $this->config->set('log_dir', $this->config->get('root_dir') . '../log');
     }
     $this->loggerFactory = new LoggerFactory($this->getConfig()->get('debug'), $this->config->get('log_dir'));
     $appLogger = $this->loggerFactory->create('app');
     if (false === $this->config->get('debug')) {
         error_reporting(E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_NOTICE);
         ini_set('display_errors', 'Off');
     } else {
         error_reporting(E_ALL);
         ini_set('display_errors', 'On');
     }
     ErrorHandler::register($appLogger, $this->errorLevelMap);
     $this->booted = true;
 }
 /**
  * Tests redirection.
  *
  * @covers ::execute
  */
 public function testRedirect()
 {
     $this->currentPathStack->getPath()->willReturn('some/random/test/path');
     $this->action->setContextValue('url', '/test/url');
     $this->action->execute();
     $this->parameterBag->set('_rules_redirect_action_url', '/test/url')->shouldHaveBeenCalled();
 }
예제 #12
0
 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function set($key, $value)
 {
     if (!is_array($value) && !$value instanceof Registry) {
         throw new \InvalidArgumentException('Must be an array or an instance of Registry.');
     }
     parent::set($key, $value);
 }
예제 #13
0
 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function set($key, $value)
 {
     if (!is_array($value) && !$value instanceof UploadedFile) {
         throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.');
     }
     parent::set($key, $this->convertFileInformation($value));
 }
 public function configureActionsVars(ParameterBag $actionsVars)
 {
     if ($this->container->isScopeActive('request')) {
         $adminSession = new AdminSession($this->container->get('request'), $this->container->get('session'), $this->getOption('sessionParameter'));
         $actionsVars->set('admin_session', $adminSession);
     }
 }
 public function __construct(ParameterBag $parameters = null)
 {
     if (is_null($parameters)) {
         $parameters = new ParameterBag();
     }
     $parameters->set('Session_Type', self::SESSION_TYPE_RUNTIME)->set('Function', $this->getFunction());
     parent::__construct($parameters);
 }
예제 #16
0
파일: Request.php 프로젝트: speedwork/core
 /**
  * Sets a cookie.
  *
  * @param Cookie $cookie
  */
 public function setCookie(Cookie $cookie)
 {
     if (!isset($this->cookie)) {
         $this->cookie = new ParameterBag();
     }
     $this->cookie->set($cookie->getName(), $cookie);
     return $this;
 }
예제 #17
0
 /**
  * Create a new helper if class exists.
  *
  * @param string $method
  * @param array  $argv
  *
  * @return AHelper|null
  */
 public function createHelper($method, $argv)
 {
     //        @todo gvf tag services and name them with a prefix such as bbweb or bbapp
     $helper = $this->serviceContainer->get($method);
     $helper->setRenderer($this);
     $this->helpers->set($method, $helper);
     return $helper;
 }
 function it_calls_the_service_with_configured_arguments(ContainerInterface $container, Request $request, ParameterBag $attributes)
 {
     $container->get('my_service')->willReturn(new MyService());
     $configuration = new ParamConverter(['name' => 'foo', 'class' => MyArgument::class, 'options' => ['service' => 'my_service', 'method' => 'myMethod', 'arguments' => ['id', 'name']]]);
     $attributes->get('id')->willReturn(42);
     $attributes->get('name')->willReturn('Bob');
     $attributes->set('foo', new MyArgument(42, 'Bob'))->shouldBeCalled();
     $this->apply($request, $configuration);
 }
예제 #19
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['#']);
         }
     }
 }
예제 #20
0
 /**
  * Create a new helper if class exists.
  *
  * @param string $method
  * @param array  $argv
  *
  * @return AHelper|null
  */
 public function createHelper($method, $argv)
 {
     $helper = null;
     $helperClass = 'BackBee\\Renderer\\Helper\\' . $method;
     if (true === class_exists($helperClass)) {
         $this->helpers->set($method, new $helperClass($this, $argv));
         $helper = $this->helpers->get($method);
     }
     return $helper;
 }
 protected function process(array $detectors, $useragent)
 {
     $bag = new ParameterBag();
     foreach ($detectors as $detector) {
         if ($detector[0] instanceof DetectorInterface) {
             $bag->set($detector[1], $detector[0]->detect($useragent));
         }
     }
     return $bag;
 }
 /**
  * Copies billing address to shipping address
  *
  * @param ParameterBag $parameters
  */
 private function copyShippingAddress(ParameterBag $parameters)
 {
     $billingAddress = $parameters->get('billingAddress');
     $shippingAddress = [];
     foreach ($billingAddress as $key => $value) {
         list(, $fieldName) = explode('.', $key);
         $shippingAddress['shippingAddress.' . $fieldName] = $value;
     }
     $parameters->set('shippingAddress', $shippingAddress);
 }
예제 #23
0
 public function testParseCookies()
 {
     $cookies = new ParameterBag();
     $cookies->set('__utmz', '1.1386025859.5.5.utmcsr=apis.google.com|utmccn=(referral)|utmcmd=referral|utmcct=/u/0/wm/4/_/widget/render/comments');
     $cookies->set('__utma', '187139004.1145570274.1387294774.1387294774.1387294774.1');
     $cookies->set('__utmb', '187139004.1.10.1387294774');
     $parser = new GoogleCookieParser();
     $utm = $parser->parseCookies($cookies);
     $this->assertEquals('apis.google.com', $utm->getCampaignSource(), 'Campaign Source');
     $this->assertEquals('(referral)', $utm->getCampaignName(), 'Campaign Name');
     $this->assertEquals('referral', $utm->getCampaignMedium(), 'Campaign Medium');
     $this->assertEquals('/u/0/wm/4/_/widget/render/comments', $utm->getCampaignContent(), 'Campaign Content');
     $this->assertNull($utm->getCampaignTerm(), 'Campaign Term');
     $this->assertEquals('1', $utm->getTimesVisited(), 'Times visited');
     $this->assertEquals('1', $utm->getPagesViewed(), 'Page Viewed');
     $this->assertEquals('2013-12-17 16:39:34', $utm->getFirstVisit()->format('Y-m-d H:i:s'), 'First visit');
     $this->assertEquals('2013-12-17 16:39:34', $utm->getPreviousVisit()->format('Y-m-d H:i:s'), 'Previous visit');
     $this->assertEquals('2013-12-17 16:39:34', $utm->getCurrentVisitStarted()->format('Y-m-d H:i:s'), 'Previous visit');
 }
예제 #24
0
 /**
  * @dataProvider wsiDataProvider
  *
  * @param mixed     $actionParams
  * @param mixed     $expectedParams
  * @param \stdClass $remoteResponse
  * @param mixed     $expectedData
  */
 public function testWSICompatibility($actionParams, $expectedParams, $remoteResponse, $expectedData)
 {
     $this->settings->set('wsi_mode', true);
     $this->initSettings(true);
     $testActionName = 'testAction';
     $this->soapClientMock->expects($this->at(3))->method('__soapCall')->with($this->equalTo($testActionName), $this->equalTo([(object) $expectedParams]))->will($this->returnValue($remoteResponse));
     $this->transport->init($this->transportEntity);
     $result = $this->transport->call($testActionName, $actionParams);
     $this->assertEquals($expectedData, $result);
 }
 function it_should_decrypt_a_cookie(GetResponseEvent $event, Request $request, ParameterBag $cookies)
 {
     $cookies->get('session')->willReturn('dGVzdA==');
     $cookies->has('session')->willReturn(true);
     $cookies->set('session', 'test')->shouldBeCalled();
     $request->cookies = $cookies;
     $event->getRequest()->willReturn($request);
     $event->getRequestType()->willReturn(HttpKernelInterface::MASTER_REQUEST);
     $this->onKernelRequest($event)->shouldReturn(null);
 }
예제 #26
0
 /**
  * {@inheritDoc}
  */
 public function toRequestParams(Profile $profile)
 {
     $params = new ParameterBag();
     foreach (get_class_methods(get_class($profile)) as $method) {
         if ('get' === substr($method, 0, 3)) {
             $property = strtolower(preg_replace('/([a-z])([A-Z])/', '\\$1_\\$2', substr($method, 3)));
             $params->set($property, $profile->{$method}());
         }
     }
     return $params;
 }
예제 #27
0
 function it_should_properly_convert_parameter(Request $request, ParamConverter $paramConverter, Project $project, ProjectRepository $projectRepository, ParameterBag $parameterBag)
 {
     $parameterBag->has('projectSlug')->willReturn(true);
     $parameterBag->get('projectSlug')->willReturn('foobar');
     $parameterBag->set(Argument::type('string'), Argument::any())->shouldBeCalled();
     $request->attributes = $parameterBag;
     $projectRepository->findOneBy(['slug' => 'foobar'])->willReturn($project);
     $paramConverter->getClass()->willReturn('CiTron\\Project\\Entity\\Project');
     $paramConverter->getName()->willReturn('project');
     $this->apply($request, $paramConverter)->shouldReturn(true);
 }
 public function let()
 {
     $request = new ParameterBag();
     $request->set('token', '12345678');
     $request->set('team_id', 'team');
     $request->set('channel_id', 'CX12345');
     $request->set('channel_name', 'My Channel');
     $request->set('user_id', 'user_1234');
     $request->set('user_name', 'myName');
     $request->set('command', '/slash');
     $request->set('text', 'command');
     $this->beConstructedWith($request);
 }
예제 #29
-10
 /**
  * Copies billing address to shipping address
  *
  * @param ParameterBag $parameters
  */
 protected function checkCopyAddress(ParameterBag $parameters)
 {
     if (1 === (int) $parameters->get('copyAddress')) {
         $billingAddress = $parameters->get('billingAddress');
         $parameters->set('shippingAddress', ['shippingAddress.firstName' => $billingAddress['billingAddress.firstName'], 'shippingAddress.lastName' => $billingAddress['billingAddress.lastName'], 'shippingAddress.street' => $billingAddress['billingAddress.street'], 'shippingAddress.streetNo' => $billingAddress['billingAddress.streetNo'], 'shippingAddress.flatNo' => $billingAddress['billingAddress.flatNo'], 'shippingAddress.city' => $billingAddress['billingAddress.city'], 'shippingAddress.postCode' => $billingAddress['billingAddress.postCode'], 'shippingAddress.country' => $billingAddress['billingAddress.country']]);
     }
 }
 /**
  * @test
  */
 public function it_should_change_controller_attribute_to_use_service()
 {
     $this->attributes->set('_controller', 'stdClass::method');
     $this->given_controller_is_annotated_by_injectable_annotation();
     $this->listener->onKernelController($this->getEvent());
     $this->assertEquals('stdClass:method', $this->attributes->get('_controller'));
 }