Probleme with Symfony 3.3.8 bundle creation - php

i try to create a bundle by console with symfony 3.3.8 after this version i dont have any problem with that but now i have one,
image1
image2
Any suggestion please!!!!!!

In your composer.json
replace your autoload part with:
"autoload": {
"psr-4": {
"": "src/"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},

thinks i also execut the command bellow
composer dump-autoload.
Problem resolve.

Related

Laravel forge after each deploy having to use composer update

So I have a helper file: App\helpers.php, added in my JSON as follows:
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
},
"files": [
"app/helpers.php"
]
},
In this helper file I have for example a simple userName() method for displaying the full name of a user:
function userName()
{
return auth()->user() ? auth()->user()->present()->name : '';
}
Everything works fine in my local environment. But everytime I push to my production environment, I get errors:
Call to undefined function userName()
Whenever in Laravel Forge I do a composer update after deploying, the error disappears and my website works flawlessly.
I have never had this issue with any other projects, and I am using the helpers.php file the exact same way.
My question is, why is this happening and of course my second question would be, how to solve this?
if you look at forge deploy script, you'll see the line:
$FORGE_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader
the --no-dev flag will skip your autoload-dev rules, so you just need to move the helper reference into autoload instead of autoload-dev
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"files": [
"app/Helpers.php"
]
},

error while extending the bundle ClassNotFoundException

I just created a new 2.8 Symfony project then added SonataAdminBundle
when I tried to add SonataMediaundle as you can see in the screenshot after completing step 2.5 in the documentation I get this error that I just couldn't explain.
(I'm a new user so I can't add pictures yet so you'll only see the link)
first of all, Cerad, the problem solved thanks to you,
by changing the autoload in my composer.json file from this:
...
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle"
},
To this:
...
"autoload": {
"psr-4": {
"": "src/"
},
then run command:
composer dumpautoload
and VoilĂ  everything come back to work.

Adding Third party library to Laravel

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/"
}

Add an external library to symfony

I'm trying to add an external library to symfony.
I've tried this on the app/autoload.php:
$loader->add('LibCokeId',__DIR__ . '/../vendor/libcokeid/libcokeid/lib');
However when I try to use it in a controller:
use libCokeId\LibCokeId
Libcokeid::init()
I get the miss use statement error.
Any help?
In the situation where you have a library that doesn't use composer and you can't retrieve it from packagist, you can manipulate the Composer autoload.
Simply add the class in the composer.json files, as example:
"autoload": {
"psr-0": { "": "src/" },
"files": [
"vendor/folder/my_custom_lib/myFiles.php",
"vendor/libcokeid/libcokeid/lib/libCokeId/LibCokeId.php"
]
},
OR you can Autoload the whole folder in composer.json:
"autoload": {
"psr-0": { "": "src/" },
"classmap": [
"vendor/libcokeid/libcokeid/lib"
],
},
Remember to make a composer install after setting this.
Hope this help.

Composer/Laravel Fatal Error

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"
]
},

Categories