Custom KanbanService

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • rabii
    commented on 's reply
    i have tried that it didn't work either. But i figure it out instead of bindingInstance i have used an implemtation extending original class to my custom class and now it works like a charm.

  • a.slyzhko
    commented on 's reply
    You need to instantiate your custom service and pass it as a second param, instead of using its name. ::class returns a string representing a name of the class, not an object of this class

  • rabii
    commented on 's reply
    Hey Yuri,

    when i tried this $binder->bindInstance(\Espo\Tools\Pdf\Service::class, \Espo\Custom\Tools\Pdf\CustomService::class);

    It doesn't work. i get an error expected type object. when i checked the bindInstance it require an object as a second argument. Is there something i am missing. I am trying to bind the pdf service class with a custom pdf service class.

  • yuri
    commented on 's reply
    I see. I'll try to address this problem in v8.2.

  • rabii
    commented on 's reply
    That makes sense, thanks for explaining. i will try to implement this.

  • a.slyzhko
    commented on 's reply
    ERROR: Slim Application Error Type: FastRoute\BadRouteException Code: 0 Message: Cannot register two routes matching "/api/v1/Kanban/([^/]+)" for method "GET" File: /var/www/espocrm/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php Line: 111

  • yuri
    commented on 's reply
    One of the reason of not having interfaces, is having interface implies that we gave a "promise" that it will work at least till the next major version number. Whenever I add an interface, I need to think enough whether I won't have a need to change it in the nearest future.

  • yuri
    commented on 's reply
    What error did you get? I just tried to define a custom route for an existing route path and it worked.

  • yuri
    commented on 's reply
    You need to extend if as PHP will give error otherwise.

    This binding works best when we use interfaces. That's why using interfaces is encouraged nowadays. To be able to substitute with any implementation. We don't have that many interfaces in Espo codebase though.

    When there's no interface, only extending is an option.

  • rabii
    replied
    Hey yuri

    What if we need to change a method on an existing class, e.g i want to change the method generate on this class Espo\Tools\Pdf\Service with my custom implementation in a custom service class Espo\Custom\Tools\Pdf\CustomService. would the binding class below work:

    PHP Code:
    <?php
    namespace Espo\Custom;
    
    use Espo\Core\Binding\Binder;
    use Espo\Core\Binding\BindingProcessor;
    
    class Binding implements BindingProcessor
    {
        public function process(Binder $binder): void
        {
           $binder
               ->bindInstance(\Espo\Tools\Pdf\Service::class, \Espo\Custom\Tools\Pdf\CustomService::class);}
    }

    Do i still have to extend the pdf Service on my custom Services and implement a generate function to overwrite the function on the pdf service class ?

    Thanks
    Last edited by rabii; 01-02-2024, 01:20 PM.

    Leave a comment:


  • a.slyzhko
    commented on 's reply
    I tried to define the same custom route. But get error that application cannot bind two identical routes

  • yuri
    replied
    No need to define a container service.

    PHP Code:
    $binder->bindInstance(\Espo\Tools\Kanban\KanbanService::class, \Espo\Custom\Tools\Kanban\CustomKanbanService::class);
    CustomKanbanService should extend KanbanService, as there's no interface.

    As an alternative, you can define a new route for the same URI path that will call a custom API action.

    Leave a comment:


  • emillod
    replied
    Take a look at Dependency Injection. I haven't tested it, but you could give this a try to see if it works. Make sure the namespaces are correct.

    Code:
    custom/Espo/Custom/Binding.php
    PHP Code:
    <?php
    namespace Espo\Custom;
    
    use Espo\Core\Binding\Binder;
    use Espo\Core\Binding\BindingProcessor;
    
    class Binding implements BindingProcessor
    {
        public function process(Binder $binder): void
        {
            $binder
                ->bindService('Espo\\Tools\\Kanban\\KanbanService $service', 'customKanbanService');
        }
    }
    Code:
    custom/Espo/Custom/Resources/metadata/app/containerServices.json
    Code:
    {
        "customKanbanService": {
            "className": "Espo\\Custom\\Tools\\Kanban\\KanbanService"
        }
    }
    ​

    Leave a comment:


  • a.slyzhko
    started a topic Custom KanbanService

    Custom KanbanService

    Is it possible to create custom KanbanService to be used instead of standard one? I tried to create new class in custom/Espo/Custom/Tools dir, but it has no affect.
Working...