Ejemplo n.º 1
0
 public function testInvalidJsonToArray()
 {
     $formData = new ApiFormTransfer();
     $formData->setSource('{"a"}');
     $jsonManager = new JsonDecoder();
     $this->assertNull($jsonManager->transform($formData)->getData());
 }
 /**
  * @param ApiFormTransfer $formData
  * @param DecoderInterface $decoder
  *
  * @return string
  */
 public static function createResponse(ApiFormTransfer $formData, DecoderInterface $decoder)
 {
     $transformerName = '\\ApiBundle\\Transformer\\' . $formData->getType() . 'Transformer';
     if (class_exists($transformerName)) {
         /** @var TransformerInterface $transformer */
         $transformer = new $transformerName();
         return $transformer->transform($decoder);
     }
     return sprintf('Transformer %s not implemented', $transformerName);
 }
 /**
  * @param Request $request
  *
  * @return array
  */
 public function indexAction(Request $request)
 {
     $formDefault = new ApiFormTransfer();
     $formDefault->setType(ResponsiveForm::getResolutionChoirces());
     $form = $this->createForm(ResponsiveForm::class, $formDefault)->handleRequest($request);
     $dimensions = [];
     $url = '';
     $isLarge = false;
     if ($form->isValid()) {
         /** @var ApiFormTransfer $response */
         $response = $form->getData();
         $url = $response->getSource();
         $dimensions = array_map(function ($row) use(&$isLarge) {
             $dimensions = explode('x', $row);
             if ($dimensions[0] > 600 || $dimensions[1] > 600) {
                 $isLarge = true;
             }
             return $dimensions;
         }, $response->getType());
     }
     return $this->render('ApiBundle:Responsive:index.html.twig', ['form' => $form->createView(), 'url' => $url, 'is_large' => $isLarge, 'dimensions' => $dimensions]);
 }
Ejemplo n.º 4
0
 /**
  * @param ApiFormTransfer $formTransfer
  *
  * @return self
  */
 public function transform(ApiFormTransfer $formTransfer)
 {
     $this->data = unserialize($formTransfer->getSource());
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * @param ApiFormTransfer $formTransfer
  *
  * @return self
  */
 public function transform(ApiFormTransfer $formTransfer)
 {
     $this->data = json_decode($formTransfer->getSource(), true);
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * @param ApiFormTransfer $formTransfer
  *
  * @return $this
  */
 public function transform(ApiFormTransfer $formTransfer)
 {
     $this->data = $formTransfer->getSource();
     return $this;
 }