DiscoverPlaces Raport #2
Ten wpis to krótki raport na temat tego co zostało zrobione w ostatnim tygodniu w ramach projektu DiscoverPlaces.
Niestety w ostatnim tygodniu udało się zrobić naprawdę niewiele, a to dlatego, że dużo czasu zajęły mi inne rzeczy np. dosyć obszerny post na temat tworzenia tła przy użyciu <canvas>. Poniżej główna część kodu ostatnio napisanego. Są to dwa formularze, które posłużą do walidacji danych przy dodawaniu wiadomości oraz komentarza.
<?php namespace AppBundle\Form\Type; use AppBundle\Entity\Message; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\File; use Symfony\Component\Validator\Constraints\Image; use Symfony\Component\Validator\Constraints\Range; /** * Class MessageType * @package AppBundle\FormType */ class MessageType extends AbstractType { /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('content', TextType::class, [ 'required' => false ]) ->add('photo', FileType::class, [ 'required' => false, 'constraints' => [ new Image() ] ]) ->add('video', FileType::class, [ 'required' => false, 'constraints' => [ new File([ 'mimeTypes' => [ 'video/mp4', 'video/x-flv', 'application/x-mpegURL', 'video/MP2T', 'video/3gpp', 'video/quicktime', 'video/x-msvideo', 'video/x-ms-wmv' ] ]) ] ]) ->add('latitude', NumberType::class, [ 'required' => true, 'constraints' => [ new Range([ 'min' => -90, 'minMessage' => 'latitude.min_message', 'max' => 90, 'maxMessage' => 'latitude.max_message' ]) ] ]) ->add('longitude', NumberType::class, [ 'required' => true, 'constraints' => [ new Range([ 'min' => -180, 'minMessage' => 'longitude.min_message', 'max' => 180, 'maxMessage' => 'longitude.max_message' ]) ] ]) ->add('scope', ChoiceType::class, [ 'required' => true, 'choices' => Message::AVAILABLE_SCOPES, 'invalid_message' => 'scope.invalid' ]) ; } /** * @param OptionsResolver $resolver */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'data_class' => Message::class, 'csrf_protection' => false ]); } }
<?php namespace AppBundle\Form\Type; use AppBundle\Entity\Comment; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\File; use Symfony\Component\Validator\Constraints\Image; /** * Class CommentType * @package AppBundle\FormType */ class CommentType extends AbstractType { /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('content', TextType::class, [ 'required' => false ]) ->add('photo', FileType::class, [ 'required' => false, 'constraints' => [ new Image() ] ]) ->add('video', FileType::class, [ 'required' => false, 'constraints' => [ new File([ 'mimeTypes' => [ 'video/mp4', 'video/x-flv', 'application/x-mpegURL', 'video/MP2T', 'video/3gpp', 'video/quicktime', 'video/x-msvideo', 'video/x-ms-wmv' ] ]) ] ]) ; } /** * @param OptionsResolver $resolver */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'data_class' => Comment::class, 'csrf_protection' => false ]); } }
Planuję trochę przyśpieszyć pracę nad projektem, dlatego też zamierzam obecnie na blogu nie brnąć w inne tematy, tylko poświęcić czas na pisanie kodu i przedstawianie rezultatów.
Subscribe and master unit testing with my FREE eBook (+60 pages)! 🚀
In these times, the benefits of writing unit tests are huge. I think that most of the recently started projects contain unit tests. In enterprise applications with a lot of business logic, unit tests are the most important tests, because they are fast and can us instantly assure that our implementation is correct. However, I often see a problem with good tests in projects, though these tests’ benefits are only huge when you have good unit tests. So in this ebook, I share many tips on what to do to write good unit tests.
Dodaj komentarz