Answers.Body: <p>I suppose it depends on what the code is going to be doing.  If it's standard "business logic" code related to your plugin, then it would make more sense to add it to your plugin's <a href="http://buildwithcraft.com/docs/plugins/services" rel="nofollow">services</a>, which is where we recommend that type of logic goes.  There, it handles the interactions with the database and returns the appropriate <a href="http://buildwithcraft.com/docs/plugins/models" rel="nofollow">models</a> back to your plugin's <a href="http://buildwithcraft.com/docs/plugins/controllers" rel="nofollow">controllers</a> and/or <a href="http://buildwithcraft.com/docs/plugins/variables" rel="nofollow">template variables</a>.</p>
  
  <p>Adding it to your service layer will also get you the added benefit of Craft auto-uploading the classes for you as well and attaching them to the global <code>craft()</code> instance as <code>craft()-&gt;pluginHandle</code></p>
  
  <p><strong>Update</strong></p>
  
  <p>If we're talking about enums, I'd follow Craft's example and create an <code>enums</code> folder for your plugin.  From your plugin's <code>init()</code> method, simply import your custom enums:</p>
  
  <pre><code>public function init()
  {
      Craft::import('plugins.yourPluginHandle.enums.MyCustomEnum');
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T02:36:32.470Z
Answers.Text: I might have to edit that to make it a little more clear... I am including my custom enum.
Answers.UserDisplayName: Jason McCallister
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T03:31:50.190Z
Answers.Text: Can you edit your original question to clarify?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T03:33:53.553Z
Answers.Text: I edited the title and content to make more sense. Thanks Brad.
Answers.UserDisplayName: Jason McCallister
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T03:47:19.863Z
Answers.Text: Are there any benefits to importing the enums in the `init()` method?
Answers.UserDisplayName: Jason McCallister
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T04:16:37.470Z
Answers.Text: Not particularly, just seems cleaner/more explicit to me.  If you load outside of init(), they'll they included as soon as the plugin file gets loaded.  Inside init, it'll be slightly later when the plugin's init() method gets called.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T04:54:46.207Z
Answers.Text: @Brad, does this method work if you are importing a library with a different namespace?
Answers.UserDisplayName: Ben Parizek
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T04:58:06.867Z
Answers.Text: @BenParizek If you're importing a whole separate, namespaced library, you should probably be doing that from Composer, anyway. :)
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-15T02:34:47.653Z
Answers.LastActivityDate: 2014-07-15T03:38:34.137Z
Answers.LastEditDate: 2014-07-15T03:38:34.137Z
Answers.UserDisplayName: Brad Bell
Body: <p>If I was going to include my custom enums for my plugin, should the include be outside of my plugin class or use the <strong>init()</strong> method. What is the best way to handle this and are there any pros or cons to either? </p>
  
  <p><strong>Current method:</strong></p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  // include enums for custom statuses
  include(dirname(__FILE__) . '/enums/PluginNameEnums.php');
  
  class PluginNamePlugin extends BasePlugin
  {
      // etc
  }
  </code></pre>
  
Tags: <plugin-development><best-practice>
Title: How should I include my custom enums class in my plugin?
ThreadText: # How should I include my custom enums class in my plugin?
  
  (Asked by: username_0 on 2014-07-15)
  
  If I was going to include my custom enums for my plugin, should the include be outside of my plugin class or use the **init()** method. What is the best way to handle this and are there any pros or cons to either?
  
  **Current method:**
  
  ```
  <?php
  namespace Craft;
  
  // include enums for custom statuses
  include(dirname(__FILE__) . '/enums/PluginNameEnums.php');
  
  class PluginNamePlugin extends BasePlugin
  {
      // etc
  }
  
  ```
  
  **Tags:** plugin-development, best-practice
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-07-15. Score: 3 | Accepted answer
  
  I suppose it depends on what the code is going to be doing. If it's standard "business logic" code related to your plugin, then it would make more sense to add it to your plugin's [services](http://buildwithcraft.com/docs/plugins/services), which is where we recommend that type of logic goes. There, it handles the interactions with the database and returns the appropriate [models](http://buildwithcraft.com/docs/plugins/models) back to your plugin's [controllers](http://buildwithcraft.com/docs/plugins/controllers) and/or [template variables](http://buildwithcraft.com/docs/plugins/variables).
  
  Adding it to your service layer will also get you the added benefit of Craft auto-uploading the classes for you as well and attaching them to the global `craft()` instance as `craft()->pluginHandle`
  
  **Update**
  
  If we're talking about enums, I'd follow Craft's example and create an `enums` folder for your plugin. From your plugin's `init()` method, simply import your custom enums:
  
  ```
  public function init()
  {
      Craft::import('plugins.yourPluginHandle.enums.MyCustomEnum');
  }
  
  ```
  
  > **Comments:**
  > **username_0**: I might have to edit that to make it a little more clear... I am including my custom enum.  
  > **username_1**: Can you edit your original question to clarify?  
  > **username_0**: I edited the title and content to make more sense. Thanks username_1.  
  > **username_0**: Are there any benefits to importing the enums in the `init()` method?  
  > **username_1**: Not particularly, just seems cleaner/more explicit to me.  If you load outside of init(), they'll they included as soon as the plugin file gets loaded.  Inside init, it'll be slightly later when the plugin's init() method gets called.  
  > **username_2**: @username_1, does this method work if you are importing a library with a different namespace?  
  > **username_1**: @username_2 If you're importing a whole separate, namespaced library, you should probably be doing that from Composer, anyway. :)  
  
  ---
  
  