Forums

Covering OroCommerce, OroCRM, OroPlatform topics, including community updates and company announcements.

Forums OroCommerce How can I override a moethod in symfony component

This topic contains 6 replies, has 2 voices, and was last updated by Andrey Yatsenko Andrey Yatsenko 9 months ago.

  • Creator
    Topic
  • #32583
    Ayman Hussein
    Ayman Hussein
    Participant

    I need to override locate method in vendor\symfony\symfony\src\Symfony\Component\Config\FileLocator.php class,

    How can i override this method in my bundle?

    Thanks


    arh922

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #32584
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    Hi arh922,
    It’s not possible to override class method in php without hacks, but if you use the class as a service,

    you can just override class parameter at the container, for example add in services.yml:

    or you can decorate the service file_locator, check out this tutorial
    https://symfony.com/doc/2.8/service_container/service_decoration.html

    #32585
    Ayman Hussein
    Ayman Hussein
    Participant

    What is the file locator service name (Id) so i can override old class with new class?


    arh922

    #32586
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    What is the file locator service name (Id) so i can override old class with new class?

    file_locator

    #32587
    Ayman Hussein
    Ayman Hussein
    Participant

    Does it need any parameter because I got the following error when override the service:

    Yml:

    Error:

    [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
    Can’t parse configuration. oro_cache_invalidate.frontend_options.template: Unable to find template “OroCacheBundle:Action:invalidate.html.twig”

    where can I find the origin service (yml file)? i search it out in all vendors but did not find it?


    arh922

    #32588
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    /vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml, line 58, if you have different symfony version it can be in different line.

    Service definition is for “Symfony\Component\HttpKernel\Config\FileLocator” as “Symfony\Component\Config\FileLocator” not used directly.

    #32589
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    Probably you should configure Symfony plugin in your IDE, we use PhpStorm at Oro, it’s very useful, as it highlight services for classes to quick navigation it were easy to find definition for me.

Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

You will be redirected to [title]. Would you like to continue?

Yes No
sso for www.magecore.comsso for oroinc.comsso for oroinc.desso for oroinc.frsso for marketplace.orocommerce.comsso for marketplace.orocrm.com