1

Working on an application that will be used to extend the Chatter package

Issue is, I want to make modifications to the package but don't want to do is directly to the package. Changes won't persist after a composer update.

Now from my understanding extending the package would require me to exclude the specific file from auto-loading and load my own files/directories...

composer.json

I made changes to composer.json to accommodate to Mac/Unix and Windows file path syntax:

"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "exclude-from-classmap": [
        "vendor/devdojo/chatter/src/Controllers/ChatterDiscussionController.php",
        "vendor/devdojo/chatter/src/Models/Discussion.php",
        "vendor\\devdojo\\chatter\\src\\Controllers\\ChatterDiscussionController.php",
        "vendor\\devdojo\\chatter\\src\\Models\\Discussion.php"
    ],
    "psr-4": {
        "App\\": "app/",
        "Forum\\": "app/forum"
    }
},

folder structure

.
+-- app
|   +-- Console
|   +-- Exceptions
|   +-- Forum
    |   +-- Chatter
        |   +-- Controllers
            |   +-- ChatterDiscussionController.php
        |   +-- Models
            |   +-- ...
|   +-- Helpers
|   +-- Http
|   +-- ...
+-- bootstrap
+-- ...

Custom ChatterDiscussionController.php

<?php

namespace Forum\Chatter\Controllers;

use Auth;
use Carbon\Carbon;
use DevDojo\Chatter\Events\ChatterAfterNewDiscussion;
use DevDojo\Chatter\Events\ChatterBeforeNewDiscussion;
use DevDojo\Chatter\Models\Models;
use Event;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as Controller;
use Validator;
use App\User;

class ChatterDiscussionController extends Controller
{...

test

To test this, I placed dd("Custom") in my custom DiscussionController and dd("Original") within the package version of DiscussionController. And as you may already surmise, this continues to hit the package version of the DiscussionController.

The only way I got this to work was to add the specific file to files key within autoload section "files": ["app/Helpers/Chatter.php"] <~~ This is an example. This will be a managing nightmare once I start extending more and more packages. From my understanding this can be accomplished by creating a ServiceProvider, but I am unable to find a suitable example of getting this to work using that method.

Has anyone had this issue before? What was the fix. Any help in the right direction is much appreciated.

sogeniusio
  • 111
  • 3
  • 14

0 Answers0