Closed totten closed 9 months ago
Add a command to generate "services" in the "service container". The code-style is based on automatic registration in v5.55+. By default, it implements EventSubscriberInterface (since this is common).
EventSubscriberInterface
## Generate service (without specifying a name) civix generate:service ## Generate service (with specific name) civix generate:service myextension.foo
Note: If you run civix interactively, it will prompt to confirm/revise the name of the service and PHP class.
civix
On a demo extension (named civix_addsvc), here's the console output:
civix_addsvc
Which generates a file like:
<?php use CRM_CivixAddsvc_ExtensionUtil as E; use Civi\Core\Service\AutoService; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * @service civix_addsvc.myService */ class CRM_CivixAddsvc_MyService extends AutoService implements EventSubscriberInterface { public static function getSubscribedEvents(): array { return [ // '&hook_civicrm_alterContent' => ['onAlterContent', 0], // '&hook_civicrm_postCommit::Contribution' => ['onContribute', 0], // TIP: For hooks based on GenericHookEvent, the "&" will expand arguments. ]; } // /** // * @see \CRM_Utils_Hook::alterContent // */ // public function onAlterContent(&$content, $context, $tplName, &$object) { ... } // /** // * @see \CRM_Utils_Hook::postCommit // */ // public function onContribute($op, $objectName, $objectId, $objectRef = NULL) { ... } }
This generator supports the Civi\ namespace, but (for existing extensions) the CRM_ namespace is the default. Note that:
Civi\
CRM_
info.xml
<civix> <namespace>CRM/Myextension</namespace> </civix>
--naming=Civi
--naming=CRM
Test failure unrelated.
Add a command to generate "services" in the "service container". The code-style is based on automatic registration in v5.55+. By default, it implements
EventSubscriberInterface
(since this is common).Usage
Note: If you run
civix
interactively, it will prompt to confirm/revise the name of the service and PHP class.Output
On a demo extension (named
civix_addsvc
), here's the console output:Which generates a file like:
Comment
This generator supports the
Civi\
namespace, but (for existing extensions) theCRM_
namespace is the default. Note that:info.xml
--naming=Civi
or--naming=CRM
.