예제 #1
0
 public function testRemove()
 {
     $bag = new ParameterBag(array('foo' => 'bar'));
     $bag->add(array('bar' => 'bas'));
     $this->assertEquals(array('foo' => 'bar', 'bar' => 'bas'), $bag->all());
     $bag->remove('bar');
     $this->assertEquals(array('foo' => 'bar'), $bag->all());
 }
 /**
  * @inheritdoc
  */
 public function transform(ParameterBag $item)
 {
     foreach ($item->keys() as $key) {
         if (!in_array($key, $this->fields)) {
             $item->remove($key);
         }
     }
 }
예제 #3
0
 /**
  * @inheritdoc
  */
 public function map(ParameterBag $item)
 {
     foreach ($this->mapping as $from => $to) {
         // use a special kind of null value to check, because we do want a
         // `null` value if it's actually set, but we cannot use the has()
         // method on deep paths, like foo[bar]
         if ('__null__' === ($value = $item->get($from, '__null__', $this->deep))) {
             continue;
         }
         // if value is null, only set it when we don't already have this value
         if ($item->has($to) && !$this->mayOverride($item->get($to), $value)) {
             $item->remove($from);
             continue;
         }
         $item->set($to, $value);
         // remove the original if the key is mapped to a different key
         if ($to !== $from) {
             $item->remove($from);
         }
     }
     return $item;
 }
예제 #4
0
 function it_posts_users_action(Request $request, ParameterBag $bag, ContainerInterface $container, UserRepository $repository, UserInterface $user, UserHandler $handler, Mailer $mailer)
 {
     $request->request = $bag;
     $bag->get('force')->shouldBeCalled()->willReturn(false);
     $bag->remove('force')->shouldBeCalled();
     $container->get('kreta_user.repository.user')->shouldBeCalled()->willReturn($repository);
     $bag->get('email')->shouldBeCalled()->willReturn('*****@*****.**');
     $repository->findOneBy(['email' => '*****@*****.**'])->shouldBeCalled()->willReturn($user);
     $container->get('kreta_user.form_handler.invitation')->shouldBeCalled()->willReturn($handler);
     $user->isEnabled()->shouldBeCalled()->willReturn(true);
     $handler->processForm($request, $user)->shouldBeCalled()->willReturn($user);
     $handler->processForm($request)->shouldBeCalled()->willReturn($user);
     $container->get('kreta_user.mailer')->shouldBeCalled()->willReturn($mailer);
     $mailer->sendInvitationEmail($user)->shouldBeCalled();
     $this->postUsersAction($request)->shouldReturn($user);
 }
 /**
  * Removes a route parameter.
  *
  * @param string $parameterName
  */
 public function remove($parameterName)
 {
     $this->params->remove($parameterName);
 }
예제 #6
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;
 }
예제 #7
0
 protected function parseConnections($options, $defaultHost, $defaultPort, $defaultScheme = 'tcp')
 {
     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' => $defaultScheme, '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;
         }
     } else {
         $connections = isset($options['save_path']) ? (array) explode(',', $options['save_path']) : [];
         if (empty($connections)) {
             $connections[] = $defaultHost . ':' . $defaultPort;
         }
         foreach ($connections as $conn) {
             // Default scheme if not given so parse_url works correctly.
             if (!preg_match('~^\\w+://.+~', $conn)) {
                 $conn = $defaultScheme . '://' . $conn;
             }
             $uri = new Uri($conn);
             $connBag = new ParameterBag();
             $connBag->set('uri', $uri);
             $connBag->add(Psr7\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;
 }
예제 #8
0
 /**
  * Insert every external resources: css and header js will be added before page '</head>' and
  * footer javascript will be added before page '</body>'.
  *
  * @return self
  */
 private function insertExternalResources()
 {
     $header_render = '';
     foreach ($this->externalResources->get(self::CSS_LINK, array()) as $href) {
         $header_render .= $this->generateStylesheetTag($href);
     }
     foreach ($header_js = $this->externalResources->get(self::HEADER_JS, array()) as $src) {
         $header_render .= $this->generateJavascriptTag($src);
     }
     if (!empty($header_render)) {
         $this->setRender(str_replace('</head>', "{$header_render}</head>", $this->getRender()));
     }
     $footer_render = '';
     $footer_js = array_diff($this->externalResources->get(self::FOOTER_JS, array()), $header_js);
     foreach ($footer_js as $src) {
         $footer_render .= $this->generateJavascriptTag($src);
     }
     if (!empty($footer_render)) {
         $this->setRender(str_replace('</body>', "{$footer_render}</body>", $this->getRender()));
     }
     $this->externalResources->remove(self::CSS_LINK);
     $this->externalResources->remove(self::HEADER_JS);
     $this->externalResources->remove(self::FOOTER_JS);
     return $this;
 }