Answers.Body: <p>The example in the wiki was problematic. If you look at the <a href="https://github.com/civicrm/civicrm-core/tree/4.6/CRM/Utils/API]">wrappers included with core</a>, they're never placed under the <code>api/v3</code> folder -- they're always under <code>CRM/Utils/API</code>. (I've updated the wiki to use a different name.)</p>
  
  <p>That's merely a matter of convention, though. The API-wrapper system doesn't impose any constraints on where to put the class or how to name it. As far as that system is concerned, you can use any valid PHP class (as long as it implements the <code>API_Wrapper</code> interface).</p>
  
  <p>The limitation here is in the reflection mechanism (<code>MagicFunctionProvider-&gt;getEntityNames()</code> and <code>getActionNames()</code>) which maps between API entities/actions and files/folders/functions. This is tricky to do because the naming conventions have been traditionally loose/ambiguous, so the current implementation uses a general rule of thumb: if you put <em>any</em> PHP file under "api/v3", then it will be reported as an entity name.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-13T05:34:00.160Z
Answers.LastActivityDate: 2015-06-13T05:34:00.160Z
Answers.UserDisplayName: Tim Otten
Body: <p>I just wrote an extension with short-name "<a href="https://civicrm.org/extensions/gender-self-identify" rel="nofollow noreferrer">genderselfidentify</a>" (it's cool, you should check it out), which implements <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_apiWrappers" rel="nofollow noreferrer">hook_civicrm_apiWrappers</a>. This hook requires you to declare a class for your api wrapper functions, but the <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_apiWrappers" rel="nofollow noreferrer">docs for it</a> don't say exactly what you should name the class or where you should put it. The example given is:</p>
  
  <pre><code>function example_civicrm_apiWrappers(&amp;$wrappers, $apiRequest) {
    $wrappers[] = new api_v3_APIWrapperExample();
  }
  </code></pre>
  
  <p>Which implies that</p>
  
  <ul>
  <li>The class name should start with <code>api_v3_</code></li>
  <li>It should be placed in the extension's <code>api/v3</code> directory</li>
  <li>(noting the lack of <code>require_once</code> in the example) it will be autoloaded by CiviCRM.</li>
  </ul>
  
  <p>I found all the above to be true, naming my class <code>api_v3_GenderselfidentifyAPIWrapper</code> the autoloading and wrapper functionality worked great... but then I noticed something strange in the API Explorer:</p>
  
  <p><img src="https://i.sstatic.net/B4ehE.png" alt="enter image description here"></p>
  
  <p>Why is my wrapper class showing up as if it were an entity?</p>
  
Tags: <api><hooks>
Title: Where to put api wrapper class in an extension
ThreadText: # Where to put api wrapper class in an extension
  
  (Asked by: username_0 on 2015-06-13)
  
  I just wrote an extension with short-name "[genderselfidentify](https://civicrm.org/extensions/gender-self-identify)" (it's cool, you should check it out), which implements [hook\_civicrm\_apiWrappers](http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_apiWrappers). This hook requires you to declare a class for your api wrapper functions, but the [docs for it](http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_apiWrappers) don't say exactly what you should name the class or where you should put it. The example given is:
  
  ```
  function example_civicrm_apiWrappers(&$wrappers, $apiRequest) {
    $wrappers[] = new api_v3_APIWrapperExample();
  }
  
  ```
  
  Which implies that
  
  * The class name should start with `api_v3_`
  * It should be placed in the extension's `api/v3` directory
  * (noting the lack of `require_once` in the example) it will be autoloaded by CiviCRM.
  
  I found all the above to be true, naming my class `api_v3_GenderselfidentifyAPIWrapper` the autoloading and wrapper functionality worked great... but then I noticed something strange in the API Explorer:
  
  ![enter image description here](https://i.sstatic.net/B4ehE.png)
  
  Why is my wrapper class showing up as if it were an entity?
  
  **Tags:** api, hooks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-06-13. Score: 5 | Accepted answer
  
  The example in the wiki was problematic. If you look at the [wrappers included with core](https://github.com/civicrm/civicrm-core/tree/4.6/CRM/Utils/API]), they're never placed under the `api/v3` folder -- they're always under `CRM/Utils/API`. (I've updated the wiki to use a different name.)
  
  That's merely a matter of convention, though. The API-wrapper system doesn't impose any constraints on where to put the class or how to name it. As far as that system is concerned, you can use any valid PHP class (as long as it implements the `API_Wrapper` interface).
  
  The limitation here is in the reflection mechanism (`MagicFunctionProvider->getEntityNames()` and `getActionNames()`) which maps between API entities/actions and files/folders/functions. This is tricky to do because the naming conventions have been traditionally loose/ambiguous, so the current implementation uses a general rule of thumb: if you put *any* PHP file under "api/v3", then it will be reported as an entity name.
  
  
  ---
  
  