Try without adding a autoload your self, let laravel auto discover it.
Composer/autoload problem
Hi all, I'm stuck on a composer/autoloader problem and I wonder if anyone can offer any suggestions.
php 8.1.10 Laravel 9.41.0
I had to make changes to the shweshi OpenGraph package (https://github.com/shweshi/OpenGraph) to make it work without allow_url_fopen(), so I have forked it (this is new to me) and included the local fork in my composer.json as a local repository like so:
"repositories": [
{
"type": "path",
"url": "./local/open-graph",
"options": {
"symlink": true
}
}
}
Inside the local open-graph repository's composer.json at /local/open-graph/composer.json I have:
{
"name": "open-graph/open-graph",
"description": "Fork of shweshi/OpenGraph with fixes to work without allow_url_fopen",
"type": "library",
"license": "MIT",
"autoload": {
"psr-0": {
"OpenGraph": "src/"
}
},
"minimum-stability": "dev",
"require": {}
}
composer validate checks out OK and I can do a composer update of the local repository and my laravel project, and the following completes successfully:
cd local/open-graph/ && echo "open-graph" && composer clear-cache && composer dump-autoload && cd ../.. && echo "laravel" && composer clear-cache && dump-autoload
open-graph
Result:
open-graph
Cache directory does not exist (cache-vcs-dir):
Cache directory does not exist (cache-repo-dir):
Cache directory does not exist (cache-files-dir):
Clearing cache (cache-dir): /home/<user>/.cache/composer
All caches cleared.
Generating autoload files
Generated autoload files
laravel
Cache directory does not exist (cache-vcs-dir):
Cache directory does not exist (cache-repo-dir):
Cache directory does not exist (cache-files-dir):
Clearing cache (cache-dir): /home/<user>/.cache/composer
All caches cleared.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
INFO Discovering packages.
cohensive/oembed ...................................................... DONE
fruitcake/laravel-cors ................................................ DONE
itsgoingd/clockwork ................................................... DONE
jenssegers/agent ...................................................... DONE
kalnoy/nestedset ...................................................... DONE
laravel/fortify ....................................................... DONE
laravel/jetstream ..................................................... DONE
laravel/sail .......................................................... DONE
laravel/sanctum ....................................................... DONE
laravel/tinker ........................................................ DONE
livewire/livewire ..................................................... DONE
nesbot/carbon ......................................................... DONE
nunomaduro/collision .................................................. DONE
nunomaduro/termwind ................................................... DONE
rappasoft/laravel-livewire-tables ..................................... DONE
spatie/laravel-ignition ............................................... DONE
spatie/laravel-permission ............................................. DONE
theanik/laravel-more-command .......................................... DONE
> @php artisan vendor:publish --force --tag=livewire:assets --ansi
INFO Publishing [livewire:assets] assets.
Copying directory [vendor/livewire/livewire/dist] to [public/vendor/livewire] ..................................... DONE
Generated optimized autoload files containing 6534 classes
The package gets symlinked under /vendor/open-graph as expected.
However, in /app/Services/TwitterService.php I have:
use Illuminate\Support\Facades\Log;
use OpenGraph\OpenGraph;
...
and when execution hits that use I get
Error: Class "OpenGraph\OpenGraph" not found
I have tried every variation of path and rebuilding autoload dependencies many, many times. I am (clearly) not very good with autoload and composer. Can anybody offer any suggestions?
Please or to participate in this conversation.