Custom KanbanService
Collapse
X
-
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. -
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 -
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.👍 1 -
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.👍 1 -
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 ?
ThanksLast edited by rabii; 01-02-2024, 01:20 PM. -
No need to define a container service.
CustomKanbanService should extend KanbanService, as there's no interface.PHP Code:$binder->bindInstance(\Espo\Tools\Kanban\KanbanService::class, \Espo\Custom\Tools\Kanban\CustomKanbanService::class);
As an alternative, you can define a new route for the same URI path that will call a custom API action.Leave a comment:
-
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:
-
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.Tags: None

Leave a comment: