/** * @param $response SymfonyResponse * * @return Response */ public function convert($response) { $headers = f\map_indexed(function ($_, $k) use($response) { return $response->headers->get($k); }, $response->headers->all()); return new Response($response->getStatusCode(), $response->getContent(), $headers); }
public function convert(Request $request) { $headers = $request->getHeaders(); $keysMap = f\map_indexed(function ($v, $k) { return 'HTTP_' . $k; }, $headers); $server = f\rename_keys($headers, $keysMap); return SymfonyRequest::create($request->getUri(), $request->getMethod(), $request->getParameters(), $cookies = array(), $files = array(), $server, $request->getContent()); }
/** * f\fill($coll, $paramRules) * * Returns a new collection filled with param rules. * If a param is optional and it does not exist and there is a default value, it's filled. * If a param exists and there is no param rule for that param, it's not filled. * * // filling with empty coll * f\fill(array(), array('a' => f\optional(array('d' => 1))); * => array('a' => 1) * * // filling with existing coll * f\fill(array('a' => 1), array('a' => f\required(), 'b' => f\optional(array('d' => 2))); * => array('a' => 1, 'b' => 2) * * // without param rule * f\fill(array('a' => 1, 'b' => 2), array('a' => f\required())); * => array() */ function fill($coll, $paramRules) { $fill = function ($rule, $key) use($coll) { if (f\not($rule instanceof param_rule)) { throw new \InvalidArgumentException('Fill rules must be created with felpado\\required and felpado\\optional.'); } if ($rule instanceof optional) { $value = f\get_or($coll, $key, $rule->getDefaultValue()); } else { $value = f\get($coll, $key); } return $value; }; return f\map_indexed($fill, $paramRules); }
/** * @dataProvider provideMapIndexed */ public function testMapIndexed($expected, $coll, $fn) { $this->assertSame($expected, f\map_indexed($fn, $coll)); }