Ejemplo n.º 1
0
 /**
  * @param        $object
  * @param string $format
  * @param array  $groups
  *
  * @return object
  */
 public static function normalize($object, $format = 'json', $groups = ['default'])
 {
     return SerializerManager::getSerializers()->normalize($object, $format, ['groups' => $groups]);
 }
Ejemplo n.º 2
0
 /**
  * @ApiDoc(
  *  description="Lists a type",
  *  requirements={
  *      {
  *          "name"="type",
  *          "dataType"="string",
  *          "description"="type to be compared to"
  *      }
  *  },
  *  parameters={
  *      {"name"="nightly", "dataType"="boolean", "required"=false, "description"="Defines if it should list nightly
  *      or stable types"},
  *      {"name"="limit", "dataType"="integer", "required"=false, "description"="Sets the limit of the amount to be
  *      shown, max 30"},
  *      {"name"="page", "dataType"="integer", "required"=false, "description"="The page of the list, combined with
  *      the limit"},
  *      {"name"="latest", "dataType"="boolean", "required"=false, "description"="Returns the latest type, whereas
  *      it will return an object instead of an array"}
  *  }
  * )
  *
  * @Route("/list/{type}")
  * @Template()
  * @Method({"GET"})
  *
  * @param Request $request
  * @param string  $type
  *
  * @return JsonResponse
  */
 public function listBuildVersionsAction(Request $request, $type)
 {
     /**
      * @var TypeHelper $typeHelper
      * @var bool       $nightly
      */
     $typeHelper = $this->get('bot.type_helper');
     $stable = !ParameterParser::parseStringToBoolean($request->query->get('nightly'));
     if (($limit = $request->query->get('limit')) != null) {
         $limit = intval($limit);
         if ($limit > 30 || $limit < 0) {
             $limit = 30;
         }
     } else {
         $limit = 30;
     }
     if (($page = $request->query->get('page')) != null) {
         $page = intval($page);
         if ($page < 0) {
             $page = null;
         } else {
             $page = $limit * $page;
         }
     } else {
         $page = null;
     }
     if (($latest = $request->query->get('latest')) != null) {
         if (ParameterParser::parseStringToBoolean($latest)) {
             $limit = 1;
             $page = 0;
         }
     }
     if ($typeHelper->typeExists($type)) {
         /** @var TypeRepository|EntityRepository $repository */
         $repository = $this->getDoctrine()->getManager()->getRepository($typeHelper->getRepositorySlug($type));
         /** @var Type[] $typeList */
         $typeList = $repository->findBy(['active' => true, 'stable' => $stable], ['releaseDate' => 'DESC'], $limit, $page);
         $typeListJson = [];
         if ($typeList != null && sizeof($typeList) > 1) {
             foreach ($typeList as $t) {
                 $typeListJson[] = SerializerManager::normalize($t);
             }
         } elseif ($typeList != null && sizeof($typeList) > 0) {
             $typeListJson = SerializerManager::normalize($typeList[0]);
         }
         return new JsonResponse($typeListJson);
     } else {
         return new JsonResponse(['result' => 'Unknown type requested'], 404);
     }
 }