Skip to content

Commit

Permalink
hook_civicrm_container - Backport
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Jan 18, 2017
1 parent 86344a2 commit d9df759
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,31 @@ public static function crudLink($spec, $bao, &$link) {
);
}

/**
* Modify the CiviCRM container - add new services, parameters, extensions, etc.
*
* @code
* use Symfony\Component\Config\Resource\FileResource;
* use Symfony\Component\DependencyInjection\Definition;
*
* function mymodule_civicrm_container($container) {
* $container->addResource(new FileResource(__FILE__));
* $container->setDefinition('mysvc', new Definition('My\Class', array()));
* }
* @endcode
*
* Tip: The container configuration will be compiled/cached. The default cache
* behavior is aggressive. When you first implement the hook, be sure to
* flush the cache. Additionally, you should relax caching during development.
* In `civicrm.settings.php`, set define('CIVICRM_CONTAINER_CACHE', 'auto').
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
* @see http://symfony.com/doc/current/components/dependency_injection/index.html
*/
public static function container(\Symfony\Component\DependencyInjection\ContainerBuilder $container) {
self::singleton()->invoke(1, $container, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_container');
}

/**
* @param array <CRM_Core_FileSearchInterface> $fileSearches
* @return mixed
Expand Down
2 changes: 2 additions & 0 deletions Civi/Core/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public function createContainer() {
\Civi\Core\Resolver::singleton()->call(CIVICRM_FLEXMAILER_HACK_SERVICES, array($container));
}

\CRM_Utils_Hook::container($container);

return $container;
}

Expand Down

0 comments on commit d9df759

Please sign in to comment.