Background
I know what I'm trying to do sounds a bit wrong but I do have my reasons.
Basically I have a central core app that's a default laravel app with a few tweaks and boilerplate code, I have then developed a series of packages that can be used to extend the app through composer. These packages are not meant to function without the core framework so a dependency upon it is fully expected.
What I want to do
What I would like to do is have a BaseController in my core app and have the various controllers in my package extend this BaseController to provide universal functionality throughout the various module packages.
I was expecting to be able to place the base controller in app/controllers/BaseController.php
and then extend it from my package using:
class PackageController extends \BaseController{}
Unfortunately when I do this it still looks within the package (currently workbenched) for the controller and I get the error:
include(/var/www/l4core.dev/workbench/myvendor/mypackage/src/controllers/BaseController.php):
failed to open stream: No such file or directory
Can anyone tell me what I'm doing wrong here. I am looking for a solution which allows me to easily move my packages between vendor dir and workbench for development. Any help greatly appreciated
Update
The previously mentioned error message appears to have been due to an include in my packages /vendor/composer/classloader.php - I have now deleted the vendor directory and done a fresh composer install. This has not solved the problem but it has at least shifted it as I now get the following error message:
Class 'BaseController' not found
My Packages composer.json
{
"name": "modules/sesame",
"description": "",
"authors": [
{
"name": "any",
"email": ""
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "4.0.x",
"zizaco/confide": "dev-master",
"zizaco/entrust": "dev-master",
"conarwelsh/mustache-l4": "dev-master"
},
"autoload": {
"classmap": [
"src/controllers",
"src/models",
"src/migrations",
"src/seeds"
],
"psr-0": {
"Modules\\Sesame": "src/"
}
},
"minimum-stability": "dev"
}
Be sure to execute:
php artisan dump-autoload
And verify that your class BaseController is in /vendor/composer/autoload_classmap.php.
OR like the OP stated, removing the vendor directory and running composer install again could sometimes solve the problem.
Related
I have created a custom comoposer package and I want to use it on my project with this composer.json:
{
"name": "papillon/test",
"type": "library",
"version": "dev-master",
"require": {
"php": "^7.1.11"
},
"autoload": {
"psr-4": {
"Papillon\\Fountaine\\Eau\\": "src/Papillon/Fountaine/Eau/"
}
}
}
I compress it in zip. In the main project, I add a folder called repo, where I add de composer package zip. Then, I modify the composer.json of the main project like this:
{
"repositories": [
{
"type": "artifact",
"url": "var/main/repo"
}
],
"require": {
"papillon/test": "dev-master"
}
}
I execute composer update and the pakage is added to vendor folder; all seems to be going well... but if I want to test the package from the main project with this script:
<?php
require (__DIR__ . '/vendor/autoload.php');
use Papillon\Fountaine\Eau\FlowerClass;
echo FlowerClass::bloom();
It returns: PHP Fatal error: Uncaught Error: Class 'Papillon\Fountaine\Eau\FlowerClass' not found in .../test_package.php:6
Stack trace:
#0 {main}
thrown in .../test_package.php on line 6
I think that the package may not be recognized by the main project; maybe the package was improperly installed in the main project?
Debugging autoload can be very useful to catch errors. Take care with the route paths, the autoload tryed to find the classes files in a path with a lowercase folder when in the package composer.json the route was definded with that folder uppercase.
I have setup gRPC in core PHP and it is working fine but I want to use it with laravel 5.7. I have downloaded gRPC using composer.json. Now I don't know what I have to do for using gRPC in it.
I have added below in my composer.json file
"require": {
"datto/protobuf-php": "dev-master",
"grpc/grpc": "^1.15.0"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/stanley-cheung/Protobuf-PHP"
}
]
But now I am not getting what should be next to do. So anyone knows then please let me know. I have my core PHP code for gRPC(core library example) which I have setup from this web url. gRPC in PHP. So I just want to integrate into laravel.
How to use protoc generated files with Laravel (5.7)
Prepare your .proto file describing your services as you would normally do
Set as package name package app.grpc;
Run the generation command: protoc --php_out=./ --grpc_out=./ --plugin=protoc-gen-grpc=/your/path/to/grpc_php_plugin yourfile.proto
Now copy App/Grpc inside laravel App
Copy GPBMetadata folder as new folder in laravel root
Change composer.json file inserting GPBMetadata location in the autoload classmap section (see below)
Run command composer dump-autoload
Now you can use your generated classes in any controller, remember to add use App\Grpc\YourClassName at the top.
let me know if someone have better solutions to this
Relevant part of composer.json:
...
"autoload": {
"classmap": [
"database/seeds",
"database/factories",
"GPBMetadata"
],
"psr-4": {
"App\\": "app/"
}
}
...
you don't need these anymore
"datto/protobuf-php": "dev-master",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/stanley-cheung/Protobuf-PHP"
}
]
Instead, you should add "google/protobuf": "^3.6.1" to your require.
See this as an example:
https://github.com/grpc/grpc/blob/master/examples/php/composer.json
The versions were out-of-date - just take the latest releases.
I'm using TYPO3 6.2.26, I added to my extension an external library (sinergi/browser-detector) using composer. We have two servers one for development and another for production. The problem appear in the production context, but in development work it excellent.
I have the next structure on both servers (git subversion):
myext/Resources/Private/composer.json
myext/Resources/Private/Libraries/autoload.php (generate by composer)
myext/Resources/Private/Libraries/sinergi/...
myext/Resources/Private/Libraries/composer/... (generate by composer)
myext/ext_autoload.php
I load the composer loader in the ext_autoload.php:
require __DIR__ . '/Resources/Private/Libraries/autoload.php';
My composer.json look like this:
{
"name": "vendor/vendor",
"description": "My description",
"type": "library",
"require-dev": {
"sinergi/browser-detector": "^6.1"
},
"config": {
"vendor-dir": "Libraries"
},
"authors": [
{
"name": "xxx",
"email": "xxx"
}
]
}
With this configurations it works without problems in the development environment. In production occurs a strange situation, when I delete the cache it works only one time, at the second time the web server returns a 500 Error:
PHP Fatal Error: class Sinergi\\BrowserDetector\\...not found...
I tried some solution which I founded in Internet like:
Adding to my composer.json:
"autoload":
"prs-4": {
"Sinergi\BrowserDetector\" : "Libraries/sinergi/browser-detector/src/"
}
Dumping the autoload
composer dump-autoload
Disabling opcache
Deleting composer.lock and new install
But, the problem is still there only in production. I remove too the content of the typo3temp directory, and then it works one time, but at the second 500 Error. Do anybody know what can I make?
I don't know how your files end up on production but you should use
"require": {
"sinergi/browser-detector": "^6.1"
},
instead of require-dev, otherwise, it is just for dev.
Laravel 4 custom package not appearing in autoload_namespace.php
I have tried to create a custom package by creating a workbench package in one of my laravel apps, committing it to github and then installing it in a different package. My problem is that the namespace map is not being added to autoload_namespace.php and the knock on effect of this is that the line
Markfee\Responder\ResponderServiceProvider in my providers array causes the following error when i run:
php artisan dump-autoload
Error Output:
PHP Fatal error: Class 'Markfee\Responder\ResponderServiceProvider' not found in /media/sf_wwwshare/feenance/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 157
The package can be found at:
https://github.com/markfee/responder.git
I include the package with the following entries in my composer.json file
"repositories": {
"responder": {
"type": "package",
"package": {
"name": "markfee/responder",
"description": "Simple responder class for responding with json from api",
"version": "0.1.0",
"source": {
"type": "git",
"url": "https://github.com/markfee/responder.git",
"reference": "a7a24c82479fc01ec0c06833690bfd2eeee9e47d"
}
}
}
},
"require": {
"laravel/framework": "4.2.*",
"markfee/responder": "0.1.*"
},
If anyone can shed any light I'd be very greatful. Please ask if you need any further details.
You did the complicated way by providing a package definition for that repository. If you do that, this package is a complete replacement for any composer.json in that repository, and this should only be used in case there is none.
You didn't add the autoloading definition into that package, so it is correctly missing in your autoloading.
Suggestion: Avoid using type:package in your own composer.json file. Simply use type:vcs if the repository already has a composer.json.
If you want to use the master branch just like a tagged version, you can add an alias in your require statement: "markfee/responder": "dev-master as 0.1.0". You could also clone that repo and tag the commit you want in your own local copy, and reference your own repo instead. Or try to convince the maintainer to tag a version and add his repo to packagist.org.
with help from Sven I got this working, the exact changes I made were to replace the original entry in my composer.json with the following. I didn't use an alias as I just want to include the master branch at the moment. Versioning and adding to packagist are my next task:
"repositories": {
"responder": {
"type": "vcs",
"url": "https://github.com/markfee/responder.git"
}
},
"require": {
"laravel/framework": "4.2.*",
"markfee/responder": "dev-master"
},
I'm trying to organize my project with a base code and external bundles as a plugins for the base project.
I've already registered the bundles in packagist and the "composer.phar install" command works as expected. The autoloader also works as expected, so everything is OK but the "php console doctrine:generate:entities ACSACSPanelDynHostBundle" command don't work at all. It returns the next message:
[RuntimeException]
Can't find base path for "ACSACSPanelDynHostBundle" (path: "/var/www/acspanel/vendor/acs/paneldynhost", destination: "/var/www/acspanel/vendor/acs/paneldynhost").
I tryied to use psr-4 in composer.json to define the namespace but it don't works either.
I would like to know what is the proper way to use the console commands with my vendor bundles.
The code of my bundle composer.json is:
{
"name": "acs/paneldynhost",
"description": "Dynhost service creation for ACSPanel",
"keywords": ["dynamic domain","acspanel"],
"type": "
"autoload": {
"psr-4": { "ACS\\ACSPanelDynHostBundle\\": "" }
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
}