))
->setFactoryService(self::SELF)->setFactoryMethod('createEventDispatcher');
+ $container->setDefinition('magic_function_provider', new Definition(
+ '\Civi\API\Provider\MagicFunctionProvider',
+ array()
+ ));
+
$container->setDefinition('civi_api_kernel', new Definition(
'\Civi\API\Kernel',
- array(new Reference('dispatcher'))
+ array(new Reference('dispatcher'), new Reference('magic_function_provider'))
))
->setFactoryService(self::SELF)->setFactoryMethod('createApiKernel');
* @param \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher
* @return \Civi\API\Kernel
*/
- public function createApiKernel($dispatcher) {
+ public function createApiKernel($dispatcher, $magicFunctionProvider) {
+ $dispatcher->addSubscriber(new \Civi\API\Subscriber\ChainSubscriber());
$dispatcher->addSubscriber(new \Civi\API\Subscriber\TransactionSubscriber());
$dispatcher->addSubscriber(new \Civi\API\Subscriber\I18nSubscriber());
+ $dispatcher->addSubscriber($magicFunctionProvider);
+ $dispatcher->addSubscriber(new \Civi\API\Subscriber\PermissionCheck());
$dispatcher->addSubscriber(new \Civi\API\Subscriber\APIv3SchemaAdapter());
+ $dispatcher->addSubscriber(new \Civi\API\Subscriber\WrapperAdapter(array(
+ \CRM_Utils_API_HTMLInputCoder::singleton(),
+ \CRM_Utils_API_NullOutputCoder::singleton(),
+ \CRM_Utils_API_ReloadOption::singleton(),
+ \CRM_Utils_API_MatchOption::singleton(),
+ )));
$dispatcher->addSubscriber(new \Civi\API\Subscriber\XDebugSubscriber());
- $dispatcher->addListener(\Civi\API\Events::AUTHORIZE, function(\Civi\API\Event\AuthorizeEvent $event) {
- $apiRequest = $event->getApiRequest();
- // At time of writing, _civicrm_api3_api_check_permission generates an exception on failure
- _civicrm_api3_api_check_permission($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']);
- $event->authorize();
- });
- $kernel = new \Civi\API\Kernel($dispatcher, array());
+ $kernel = new \Civi\API\Kernel($dispatcher);
+
+ $reflectionProvider = new \Civi\API\Provider\ReflectionProvider($kernel);
+ $dispatcher->addSubscriber($reflectionProvider);
+
+ $kernel->setApiProviders(array(
+ $reflectionProvider,
+ $magicFunctionProvider,
+ ));
+
return $kernel;
}
}