понедельник, 29 ноября 2021 г.

[JMS serializer] how to set naming strategy

     public function serialize($object, array $serializationGroups)

    {

        $serializer = SerializerBuilder::create();

        $serializer->setPropertyNamingStrategy(new SerializedNameAnnotationStrategy(new IdenticalPropertyNamingStrategy()));

        $serializer->addMetadataDir($this->configDir . "/serializer", 'App\Entity');

        $serializer->setCacheDir($this->cacheDir . "/jms_serializer");

        $serializer = $serializer->build();


        $group = new GroupsExclusionStrategy($serializationGroups);

        $context = SerializationContext::create();

        $context->addExclusionStrategy($group);


        return $serializer->serialize($object, 'json', $context);

    }

It will make JSON string where property field is camelCased instead of Snake_cased. I highly recommend to use 'App\Entity' in addMetadataDir() because by default in Symfony jms_serializer.yaml config is set 'namespace_prefix' in metadata node, and without 'App\Entity' argument YML/XML entity configs won't work. It is also example how to customize Serializer parameters manually with SerializerBuilder without framework config.

вторник, 9 ноября 2021 г.

[Symfony] Cannot read index 'email' from object of type App\Entity\User because it doesn't implement \ArrayAccess

 Its because PropertyAccessor thinks form is an array. To change it, set form data_class. For example in your form Type:

public function configureOptions(OptionsResolver $resolver)

    {

        $resolver

            ->setDefaults([

                'data_class' => User::class,

...


среда, 27 октября 2021 г.

[MacOSX] how to reset permission for Camera and Microphone in Opera

 If you don't have Opera allowed Camera permission in "Security & Privacy" settings window, run this in Terminal:

tccutil reset Camera com.operasoftware.Opera


and restart Opera

понедельник, 25 октября 2021 г.

[behat] chromedriver cannot call send on null fix

 When you have error like this:

Fatal error: Call to a member function waitForLoad() on null (Behat\Testwork\Call\Exception\FatalThrowableError

Add this into your context:

if ($this->getSession()->isStarted() === false) {

            $minkSession->start();

}

четверг, 26 августа 2021 г.

[Symfony] Cannot login at Test environment - fix (in Behat)

When you trying to login in Test env, and it does not show any error (you was returned on login form again), and you does not have anything in logs, except Guard authenticator does not support the request. {"firewall_key":"main","authenticator":"App\\Security\\AppAuthenticator"}, you can try this.

 I removed lines:

 session:

        storage_id: session.storage.mock_file

in config/packages/test/framework.yaml and it worked

вторник, 10 августа 2021 г.

How to create CollectionType with empty one element

 Add 'data' => [''] (not 'empty_data') to the Collection type form configuration.

понедельник, 9 августа 2021 г.

Swedbank Latvia apk download for Huawei users

 Download link here (no viruses, I am also using this version):

https://cloud.mail.ru/public/MzmP/dHKuUHvqc

downloaded via apps.evozi.com.

If you don't have Google Play or using Huawei phones (like P40 lite), you can download Swedbank Latvia android app from here