From ec84755a14246f50594bcae8bf8883e24111b3b2 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 13 Apr 2017 18:51:02 -0700 Subject: [PATCH] Rename CRM_Utils_Hook_Inspector to Civi\Core\CiviEventInspector --- CRM/Utils/Hook.php | 2 +- .../Core/CiviEventInspector.php | 25 ++++++++++--------- Civi/Core/Container.php | 2 +- .../Core/CiviEventInspectorTest.php} | 9 ++++--- 4 files changed, 20 insertions(+), 18 deletions(-) rename CRM/Utils/Hook/Inspector.php => Civi/Core/CiviEventInspector.php (85%) rename tests/phpunit/{CRM/Utils/Hook/InspectorTest.php => Civi/Core/CiviEventInspectorTest.php} (83%) diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 192d2e6856..7ddcf0a990 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -1844,7 +1844,7 @@ abstract class CRM_Utils_Hook { /** * Build a description of available hooks. * - * @param CRM_Utils_Hook_Inspector $inspector + * @param \Civi\Core\CiviEventInspector $inspector */ public static function hooks($inspector) { $event = \Civi\Core\Event\GenericHookEvent::create(array( diff --git a/CRM/Utils/Hook/Inspector.php b/Civi/Core/CiviEventInspector.php similarity index 85% rename from CRM/Utils/Hook/Inspector.php rename to Civi/Core/CiviEventInspector.php index 8440be8349..bee94cae77 100644 --- a/CRM/Utils/Hook/Inspector.php +++ b/Civi/Core/CiviEventInspector.php @@ -1,13 +1,14 @@ getHooks())); * @endCode * @@ -15,13 +16,13 @@ * as code-generation and inspection. It should be not called by regular * runtime logic. */ -class CRM_Utils_Hook_Inspector { +class CiviEventInspector { /** * Register the default hooks defined by 'CRM_Utils_Hook'. * * @param \Civi\Core\Event\GenericHookEvent $e - * @see CRM_Utils_Hook::hooks() + * @see \CRM_Utils_Hook::hooks() */ public static function findBuiltInHooks(\Civi\Core\Event\GenericHookEvent $e) { $skipList = array('singleton'); @@ -43,12 +44,12 @@ class CRM_Utils_Hook_Inspector { * Perform a scan to identify/describe all hooks. * * @param bool $force - * @return CRM_Utils_Hook_Inspector + * @return CiviEventInspector */ public function build($force = FALSE) { if ($force || $this->hooks === NULL) { $this->hooks = array(); - CRM_Utils_Hook::hooks($this); + \CRM_Utils_Hook::hooks($this); ksort($this->hooks); } return $this; @@ -96,7 +97,7 @@ class CRM_Utils_Hook_Inspector { * Add a new hook definition. * * @param array $hook - * @return CRM_Utils_Hook_Inspector + * @return CiviEventInspector */ public function add($hook) { $name = isset($hook['name']) ? $hook['name'] : NULL; @@ -112,7 +113,7 @@ class CRM_Utils_Hook_Inspector { } if (TRUE !== $this->validate($hook)) { - throw new CRM_Core_Exception("Failed to register hook ($name). Invalid definition."); + throw new \CRM_Core_Exception("Failed to register hook ($name). Invalid definition."); } $this->hooks[$name] = $hook; @@ -130,19 +131,19 @@ class CRM_Utils_Hook_Inspector { * Ex: 'hook_civicrm_'. * @param null|callable $filter * An optional function to filter/rewrite the metadata for each hook. - * @return CRM_Utils_Hook_Inspector + * @return CiviEventInspector */ public function addStaticStubs($className, $prefix = 'hook_', $filter = NULL) { - $class = new ReflectionClass($className); + $class = new \ReflectionClass($className); - foreach ($class->getMethods(ReflectionMethod::IS_STATIC) as $method) { + foreach ($class->getMethods(\ReflectionMethod::IS_STATIC) as $method) { if (!isset($method->name)) { continue; } $hook = array( 'name' => $prefix . $method->name, - 'description_html' => $method->getDocComment() ? CRM_Admin_Page_APIExplorer::formatDocBlock($method->getDocComment()) : '', + 'description_html' => $method->getDocComment() ? \CRM_Admin_Page_APIExplorer::formatDocBlock($method->getDocComment()) : '', 'fields' => array(), 'class' => 'Civi\Core\Event\GenericHookEvent', ); diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index d428e3daac..ec31c5415e 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -250,7 +250,7 @@ class Container { $dispatcher->addListener('hook_civicrm_post::Case', array('\Civi\CCase\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_caseChange', array('\Civi\CCase\Events', 'delegateToXmlListeners')); $dispatcher->addListener('hook_civicrm_caseChange', array('\Civi\CCase\SequenceListener', 'onCaseChange_static')); - $dispatcher->addListener('hook_civicrm_hooks', array('CRM_Utils_Hook_Inspector', 'findBuiltInHooks')); + $dispatcher->addListener('hook_civicrm_hooks', array('\Civi\Core\CiviEventInspector', 'findBuiltInHooks')); $dispatcher->addListener('civi.dao.postInsert', array('\CRM_Core_BAO_RecurringEntity', 'triggerInsert')); $dispatcher->addListener('civi.dao.postUpdate', array('\CRM_Core_BAO_RecurringEntity', 'triggerUpdate')); $dispatcher->addListener('civi.dao.postDelete', array('\CRM_Core_BAO_RecurringEntity', 'triggerDelete')); diff --git a/tests/phpunit/CRM/Utils/Hook/InspectorTest.php b/tests/phpunit/Civi/Core/CiviEventInspectorTest.php similarity index 83% rename from tests/phpunit/CRM/Utils/Hook/InspectorTest.php rename to tests/phpunit/Civi/Core/CiviEventInspectorTest.php index 14e67f2764..0cdc90f8b6 100644 --- a/tests/phpunit/CRM/Utils/Hook/InspectorTest.php +++ b/tests/phpunit/Civi/Core/CiviEventInspectorTest.php @@ -1,13 +1,14 @@ get('hook_civicrm_alterSettingsMetaData'); $this->assertEquals('hook_civicrm_alterSettingsMetaData', $hook['name']); $this->assertEquals(array('settingsMetaData', 'domainID', 'profile'), array_keys($hook['fields'])); @@ -18,7 +19,7 @@ class CRM_Utils_Hook_InspectorTest extends CiviUnitTestCase { } public function testGetAll() { - $inspector = new CRM_Utils_Hook_Inspector(); + $inspector = new CiviEventInspector(); $all = $inspector->getAll(); $this->assertTrue(count($all) > 1); $this->assertTrue(isset($all['hook_civicrm_alterSettingsMetaData'])); -- 2.25.1