I want to override vendor class EloquentUserProvider.
I have created one same file in app/Ovverides folder
this is my composer.json
"exclude-from-classmap": [
"vendor\\Illuminate\\Auth\\EloquentUserProvider.php"
],
"psr-4": {
"App\\": "app/",
"App\\Ovverides\\": "app/Ovverides/"
}
after running composer dump-autoload , the file is not overridden
Related
I'm want create a packagist based in laravel,
I've created a laravel project,
I've created the next directory:
app/
...
packages/
- imfranq/
-- mypackage/
--- src/
---- Providers/
I want use the provider created in my Providers folder
My package composer.json
...
"autoload": {
"psr-4": {
"Imfranq\\MyPackage\\": "src/"
}
}
laravel app.php
'providers' => [
...
Imfranq\MyPackage\Providers\MyPackageServiceProvider::class,
]
I've run make:provider command and I've moved the file to my package folder
My MyPackageServiceProvider.php
public function boot()
{
dd('test');
}
Up to this point nothing works.
I try:
composer dump-autoload command
composer cache:clear command
php artisan clear-compiled command
nothing works
I try in laravel package.json
"autoload": {
"psr-4": {
"App\\": "app/",
"Imfranq\\MyPackage\\": "packages/imfranq/mypackage/src/"
},
"classmap": [
"packages/imfranq/mypackage/src",
"database/seeds",
"database/factories"
]
},
also
"extra": {
"laravel": {
"providers": [
"Imfranq\\MyPackage\\MyPackageServiceProvider"
]
}
},
Not work...
I'm using Laravel modules by nwidart and I want to create module in subfolder. According issue on its Github this is not possible but is possible to change paths in composer.json. So I've created new module Role2 and moved it to subfolder Administration. Then I've changed module's composer.json:
{
"name": "nwidart/role2",
"description": "",
"authors": [
{
"name": "Nicolas Widart",
"email": "n.widart#gmail.com"
}
],
"extra": {
"laravel": {
"providers": [
"Modules\\Administration\\Role2\\Providers\\Role2ServiceProvider"
],
"aliases": {
}
}
},
"autoload": {
"psr-4": {
"Modules\\Administration\\Role2\\": ""
}
}
}
But after command composer dumpautoload I see nothing in command php artisan module:list and also in vendor/composer/autoload_psr4.php there is no path to this module. What I'm doing wrong or what is missing to generate multiple composer (one in root and one in module)? Or is there some simple option to have module in subfolder?
There is what I have in root composer.json:
...
"autoload": {
"classmap": [
"database",
"vendor",
"app/Easyk"
],
"exclude-from-classmap": [
"vendor/swiftmailer"
],
"psr-4": {
"App\\": "app",
"Modules\\": "Modules",
"Easyk\\": "app/Easyk",
"Asipem\\OAuth2ClientManagement\\": "packages/asipem/oauth2-client-management/src",
"Asipem\\CAPRequestDispatcher\\": "packages/asipem/cap-request-dispatcher/src"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
],
"psr-4": {
"Tests\\Unit\\": "tests/unit"
}
},
...
autoload -> psr-4 key from composer.json is used to define psr-4 root namespaces for the application.
What happens is you define a namespace and the directory location for Autoloader to look for the files under that namespace.
As in your root composer.json
"psr-4": {
"App\\": "app",
"Modules\\": "Modules",
"Easyk\\": "app/Easyk",
"Asipem\\OAuth2ClientManagement\\": "packages/asipem/oauth2-client-management/src",
"Asipem\\CAPRequestDispatcher\\": "packages/asipem/cap-request-dispatcher/src"
}
App is the base namespace and app is its base directory. By defining it, you tell autoloader that all files with namespace App will be residing inside the directory 'app'. After that, Autoloader will traverse the app directory in the PSR-4 way for file path following the namespace trail after base namespace App.
For example: Controller App\Controller\ExampleController will tell Autoloader that the class defination will be found at app/Controller/ExampleController.
So you need to specify the base directory location of your module against the namespace Modules\\Administration\\Role2\\ which is the base source directory of your module folder.
Hope it helped.
I have an RSA algorithm Library giving to me by a payment gateway and When I do a
include (app_path().'/PaymentGateway/Crypt/RSA.php');
this and try to make an object as $rsa = new Crypt_RSA(); this it gives me and error saying
Class 'App\Http\Controllers\Crypt_RSA' not found
I tried including it in web.php and making an object it worked the problem occur when I try to include it in a Controller.
This is what I did. Oh and a little back ground I use to have this in Laravel 4, PHP 5, jpgraph 2.
I am using jpgraph 4.1 on Laravel 5.5 using PHP 7.
Created a folder under app called jpgraph
Placed the src folder that is in the tarball of jpgraph in that folder
Created file call Graph1.php, is my code using jpgraph, with the class Custom_GraphsJM in the jpgraph folder.
In composer.json added "app/jpgraph/Graph1.php" to the "classmap"
"autoload": {
"classmap": [
"database/seeds",
"database/factories",
"app/jpgraph/Graph1.php"
],
"psr-4": {
"App\\": "app/"
}
},
In the application folder:
composer dump-autoload
Checked the autoload_classmap.php and I have
'Custom_GraphsJM' => $baseDir . '/app/jpgraph/Graph1.php',
In my Model at the top I have
use Custom_GraphsJM;
To create a class
$Two_Graphs_Temp = new Custom_GraphsJM();
You can tell Composer to autoload any (non-PSR) class by adding the base folder to:
"autoload": {
"classmap": [
"app/commands",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
],
....
And you can also autoload autoloaders by adding them to the files section:
"autoload": {
"files": [
"temboo/src/Temboo_Loader.php"
],
...
After adding those entries, execute:
composer dumpautoload
And check the file vendor/composer/autoload_classmap.php, the available classes must be all listed in it, if one file is not there it will not be autoloaded.
On default, everything included in the app folder of your laravel project is autoloaded, that is described in the composer.json of your project:
...
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
...
The only thing you will need to do is simply use the namespace:
use App/Path/To/Third/Party/plugin/Class;
If, however, the plugin is placed outside of the scope of App, then simply add it to the psr-4 autoloader:
"psr-4": {
"ProjectRootNs\\": "projects/myproject/"
}
I want to change main folder [app] to author name in laravel 5 how can I do that can I do that without change anything in autoloader or composer ?
You will have an entry on your composer.json file named "psr-4", inside change it to your new renamed directory.
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "your_new_directory/"
}
},
Then in command line run:
$ composer dump-autoload
Or
$ php composer.phar dump-autoload
I added this to my composer.json file
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Claremontdesign\\Cdbase\\": "packages/Claremontdesign/cdbase/src",
"Claremontdesign\\Narbase\\": "packages/Claremontdesign/narbase/src",
"Claremontdesign\\Nhr\\": "packages/Claremontdesign/nhr/src"
},
"files": [
"packages/Claremontdesign/cdbase/src/Helpers/helpers.php",
"packages/Claremontdesign/narbase/src/Helpers/helpers.php",
"packages/Claremontdesign/nhr/src/Helpers/helpers.php"
]
},
then, I ran composer update from the command line, and it gave me this error:
symfony component debug exception fatalerrorexception class "Claremontdesign\Cdbase\ServiceProvider" not found
Has anyone else encountered this?
Also, I added a service provider in add.php
Claremontdesign\Cdbase\ServiceProvider::class
Did you try running just composer dump? composer update runs some scripts before it actually runs - for example php artisan clear-compiled. When artisan runs, it'll probably fail because it tries to register the serviceprovider which isn't autoloaded yet. composer dump only generates the autoload files, which is what you need in this case.
i think you are missing one more slash after every src folder
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Claremontdesign\\Cdbase\\": "packages/Claremontdesign/cdbase/src/",
"Claremontdesign\\Narbase\\": "packages/Claremontdesign/narbase/src/",
"Claremontdesign\\Nhr\\": "packages/Claremontdesign/nhr/src/"
},
"files": [
"packages/Claremontdesign/cdbase/src/Helpers/helpers.php",
"packages/Claremontdesign/narbase/src/Helpers/helpers.php",
"packages/Claremontdesign/nhr/src/Helpers/helpers.php"
]
},