Esempio n. 1
0
 /**
  * Returns a map of routing parameters extracted from the request attributes (which mast have been set previously by
  * a router).
  *
  * @param ServerRequestInterface $request
  * @return array A map of name => value of all routing parameters set on the request.
  */
 static function getRouteParameters(ServerRequestInterface $request)
 {
     return mapAndFilter($request->getAttributes(), function ($v, &$k) {
         if ($k && $k[0] == '@') {
             $k = substr($k, 1);
             return $v;
         }
         return null;
     });
 }
 /**
  * Generates a javascript representation of the provided options, stripping the ones that are null or empty strings.
  *
  * @param array  $options A map of options.
  * @param string $indent  Indentation level, composed of spaces.
  * @return string
  */
 static function makeOptions(array $options, $indent = '')
 {
     $o = mapAndFilter($options, function ($v, $k) use($indent) {
         if (is_object($v)) {
             if (method_exists($v, 'toArray')) {
                 $v = $v->toArray();
             } else {
                 $v = (array) $v;
             }
         }
         return exists($v) ? "{$k}: " . json_encode($v, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : null;
     });
     return "{\n{$indent}  " . implode(",\n{$indent}  ", $o) . "\n{$indent}}";
 }