Ejemplo n.º 1
0
 /**
  * Only return non-null and non-empty values in an array.
  *
  * @param array $properties
  * @param array|null $allowed
  *
  * @return array
  */
 public static function filterEmptyValues($properties, array $allowed = null)
 {
     // If provided, only use allowed properties
     $properties = Arr::only($properties, $allowed);
     return array_filter($properties, function ($value) {
         if (is_array($value) && count($value) === 0) {
             return false;
         }
         return !is_null($value);
     });
 }
Ejemplo n.º 2
0
 /**
  * @param $ramlResource
  * @param $ramlAction
  * @param $uriParameters
  * @param $resource
  * @param $method
  * @param Spec $spec
  * @param $reflector
  */
 protected function addPostSchema(&$ramlResource, &$ramlAction, &$uriParameters, $resource, $method, Spec $spec, $reflector)
 {
     if (Arr::has($ramlAction, 'body')) {
         $ramlAction['body'] = [];
     }
     $parameters = $reflector->getMethodParameters($resource, $method);
     $fields = array_unique(array_merge(array_keys($spec->getConstraints()), array_keys($spec->getDefaults()), $spec->getRequired()));
     $specFields = [];
     foreach ($fields as $field) {
         if (in_array($field, $parameters)) {
             $uriParameters[$field] = $this->specFieldToParameter($spec, $field);
             continue;
         }
         $specFields[] = $field;
     }
     $filteredSpec = new Spec(Arr::only($spec->getConstraints(), $specFields), Arr::only($spec->getDefaults(), $specFields), Std::filter(function ($element) use($specFields) {
         return in_array($element, $specFields);
     }, $spec->getRequired()));
     $ramlAction['body']['schema'] = (new SpecSchemaEncoder())->encode($filteredSpec);
 }
Ejemplo n.º 3
0
 public function testOnly()
 {
     $this->assertEqualsMatrix([[[], Arr::only([1, 2, 3])], [[1], Arr::only([1, 2, 3], [0])], [[0 => 1, 2 => 3], Arr::only([1, 2, 3], [0, 2])], [[1, 2, 3], Arr::only([1, 2, 3], null)]]);
 }