Answers.Body: <p>Firstly, ensure your directory structure matches your namespacing, so it should be:</p>
  <pre><code>- Module.php
  - variables/BCSVariable.php
  - services/TimeslotService.php
  </code></pre>
  <p>Services are generally registered as components on the module, rather than being instantiated directly.</p>
  <pre class="lang-php prettyprint-override"><code>public function init()
  {
      parent::init();
  
      $this-&gt;setComponents([
          'timeslot' =&gt; TimeslotService::class,
      ]);
  
      // ...
  }
  </code></pre>
  <p>Which can then be called as follows.</p>
  <pre class="lang-php prettyprint-override"><code>Module::getInstance()-&gt;timeslot-&gt;get();
  </code></pre>
  <p>See the docs at <a href="https://craftcms.com/docs/4.x/extend/services.html" rel="nofollow noreferrer">https://craftcms.com/docs/4.x/extend/services.html</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-20T14:29:23.353Z
Answers.LastActivityDate: 2022-10-20T14:29:23.353Z
Answers.UserDisplayName: Ben Croker
Answers.Body: <p>Okay.. my problem was that TimeslotService was opened with shorthand PHP so like</p>
  <pre><code>&lt;?
  </code></pre>
  <p>DDEV doesn't like this by default so you should always just open with the full  opening tag. Hopefully I can help others with this information.</p>
  <pre><code>&lt;?php
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-21T11:56:44.713Z
Answers.LastActivityDate: 2022-10-21T11:56:44.713Z
Answers.UserDisplayName: wesley
Body: <p>I'm migrating from Nitro to DDEV, and on this particular project I'm running im some problems with a custom module.</p>
  <p>I'm getting this error:</p>
  <p>Error
  Class &quot;modules\bcsmodule\services\TimeslotService&quot; not found</p>
  <p>It's only occurring in DDEV. Everything works fine in Nitro.</p>
  <p>I tried ddev exec composer dump-autoload</p>
  <p>This is the code:</p>
  <pre><code>&lt;?php 
  namespace modules\bcsmodule\variables;
  
  use craft\elements\Entry;
  use modules\bcsmodule\services\TimeslotService;
  use modules\eventmailermodule\EventMailerModule;
  
  class BCSVariable {
     public function test(){
          return 'blabla';
     }
  
     /**
      * Gets all timeslots available for training and for current user
      */
     public function getAvailableTimeslots(Entry $training): Array
     {
        return (new TimeslotService($training))
           -&gt;allTimeslots()
           -&gt;filterByUser()
           -&gt;filterByMaxUsers()
           -&gt;get();
     }
  </code></pre>
  <pre><code>&lt;?
  
  namespace modules\bcsmodule\services;
  
  use Craft;
  use craft\elements\Entry;
  use yii\base\Component;
  
  class TimeslotService extends Component
  {
      protected $user = null;
      protected $training;
      protected $timeslots;
  ...
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-10-13T17:06:08.060Z
Comments.Text: Wild guess here, but can you rule out case issues? I’m looking at `BCSVariable` (not `BcsVariable`) and wondering how everything’s registered and if each container might handle filename casing differently.
Comments.UserDisplayName: Matt Stein
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-10-20T12:11:13.640Z
Comments.Text: @MattStein Well, the test() variable is working just fine. Is there something about the TimeslotService ddev does not like? Or do you mean I should try BcsVariable as class name?
Comments.UserDisplayName: wesley
Tags: <craft3><nitro>
Title: Class not found when migrating to DDEV from Nitro
ThreadText: # Class not found when migrating to DDEV from Nitro
  
  (Asked by: username_0 on 2022-10-13)
  
  I'm migrating from Nitro to DDEV, and on this particular project I'm running im some problems with a custom module.
  
  I'm getting this error:
  
  Error
  Class "modules\bcsmodule\services\TimeslotService" not found
  
  It's only occurring in DDEV. Everything works fine in Nitro.
  
  I tried ddev exec composer dump-autoload
  
  This is the code:
  
  ```
  <?php 
  namespace modules\bcsmodule\variables;
  
  use craft\elements\Entry;
  use modules\bcsmodule\services\TimeslotService;
  use modules\eventmailermodule\EventMailerModule;
  
  class BCSVariable {
     public function test(){
          return 'blabla';
     }
  
     /**
      * Gets all timeslots available for training and for current user
      */
     public function getAvailableTimeslots(Entry $training): Array
     {
        return (new TimeslotService($training))
           ->allTimeslots()
           ->filterByUser()
           ->filterByMaxUsers()
           ->get();
     }
  
  ```
  
  ```
  <?
  
  namespace modules\bcsmodule\services;
  
  use Craft;
  use craft\elements\Entry;
  use yii\base\Component;
  
  class TimeslotService extends Component
  {
      protected $user = null;
      protected $training;
      protected $timeslots;
  ...
  
  ```
  
  **Tags:** craft3, nitro
  
  > **Comments:**
  > **username_1**: Wild guess here, but can you rule out case issues? I’m looking at `BCSVariable` (not `BcsVariable`) and wondering how everything’s registered and if each container might handle filename casing differently.  
  > **username_0**: @username_1 Well, the test() variable is working just fine. Is there something about the TimeslotService ddev does not like? Or do you mean I should try BcsVariable as class name?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2022-10-20. Score: 1
  
  Firstly, ensure your directory structure matches your namespacing, so it should be:
  
  ```
  - Module.php
  - variables/BCSVariable.php
  - services/TimeslotService.php
  
  ```
  
  Services are generally registered as components on the module, rather than being instantiated directly.
  
  ```php
  public function init()
  {
      parent::init();
  
      $this->setComponents([
          'timeslot' => TimeslotService::class,
      ]);
  
      // ...
  }
  
  ```
  
  Which can then be called as follows.
  
  ```php
  Module::getInstance()->timeslot->get();
  
  ```
  
  See the docs at <https://craftcms.com/docs/4.x/extend/services.html>
  
  
  ---
  
  ### Answer by username_0 on 2022-10-21. Score: 1
  
  Okay.. my problem was that TimeslotService was opened with shorthand PHP so like
  
  ```
  <?
  
  ```
  
  DDEV doesn't like this by default so you should always just open with the full opening tag. Hopefully I can help others with this information.
  
  ```
  <?php
  
  ```
  
  
  ---
  
  