Laravel 4 wont autoload provider - php

So I have created a new provider and facade and added them to my app configuration. Problem Is that I get an error:
Class 'Cergis\View\Helper\SentryViewProvider' not found
The class is using a PSR-0 naming scheme and I have verified that it's correct by adding
"psr-0": {
"Cergis\\": [
"vendor/cergis/logger/src/",
"vendor/cergis/sentry-view/src/"
]
}
If I do this and run composer dump-autoload then it works without issue. But for some reason it's unable to do so without me manually telling it where to find the classes in the vendor folder. I have tried removing everything and starting fresh, running composer dump-autoload before adding it to app.providers.

Try looking at /vendor/composer/autoload_classmap.php and check if Cergis\View\Helper\SentryViewProvider is there, if not then add these line at the start of the array:
'SentryViewProvider' => $baseDir . 'View\Helper\SentryViewProvider.php,'
Feel free to edit the value to match the path

Have you ran composer dump since creating them?

Related

Symfony - How to override a vendor component which is not in a bundle

I'm searching for override a file which is in the vendor's directory
but is not a bundle.
I'm working with Symfony 2.7
To be more specific, i'm trying to override a method in this file :
vendor/akeneo/pim-community-dev/src/Pim/Component/Catalog/Updater/ProductUpdater.php
And I'd like to do it in a file like :
src/MyApp/Component/Catalog/Updater/ProductUpdater.php
All the documentation I've found is relied to parts of a Bundle.
So, is it even possible to do that ?
If it is, how to do it ?
There is a way to override a file using composer.
You can add in your composer.json under the autoload->psr-4 key something like this.
"autoload": {
"psr-4": {
"Pim\\Component\\Catalog\\Updater\\": "MyApp/Pim/Component/Catalog/Updater"
},
Where the first part is the namespace of the file you want to override and the second part is the new path.
This can create some issues when you add new packages to composer, so make sure you run composer dump-autoload to recreated the autoload order.
i don't really like this method, but it did save me a couple of times to fix files from bundles without actually forking the bundle, and if nothing else helps this can me used as a last resort.
More about composer autoload here
https://getcomposer.org/doc/01-basic-usage.md#autoloading
Hope this helps,
Alexandru Cosoi

Symfony3 - creating a vendor-based bundle

We'd like to create a bundle which can deployed via composer/packagist for others to use. It'll wrap the logic created by the owners of MessageBird. Basically a kind of Service which will indeed be called with the container via ourvendor.messagebird.messaging.
Since it's a type of bundle (as per the docs of Sf3), we created a bundle while following the documentation:
http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_bundle.html
As the directory /src we used /vendor instead. That's when it all went wrong. Our namespace could not be located, loaded or even when we manually added it to the autoloading classes of Composer it failed all the same.
The question is, what is the best practice to go about this? We got it working right now and what we did was the following:
We created a bundle wit the following cmd:
bin/console generate:bundle --shared --namespace=OurVendor/MessageBird/MessageBirdBundle --bundle-name=MessageBirdBundle --format=yml
We moved the /src/OurVendor directory to /vendor/OurVendor as the only way to get a perfect generation was to use the default /src folder.
We manually updated the AppKernel.php
We did some debugging with namespaces for Composer but eventually we added "OurVendor\\":"vendor/" to the "autoload/psr-4" directive in root composer.json
We ran composer dumpautoload && bin/console cache:clear -e dev which resulted in an error.
We ran composer -o update which checked all dependencies and updated accordingly, including autogenerated autoload files
Strangely enough we had to add the Bundle to the AppKernel.php class and cleaned the cache again.
After all this it worked but the documentation said no such thing about developing a 3rd party vendor bundle.
http://symfony.com/doc/current/bundles/best_practices.html
So long story short, did we go about it the wrong way or what?
/vendor directory is managed by composer. Do not copy/move anything there. Don't even edit anything there, unless you understand all consequences.
When you create a shared bundle, you need to push it to a VCS of your choice, and add it as a dependency in composer.json of the project which uses it.
When you run composer update it will check-out your bundle into /vendor directory and generate correct autoload file.
Please read more how to use private repositories with composer.

Yii2 Error: Class dektrium\rbac\Module does not exist

I have just updated my composer and after that when i run my Yii2 application i got this error "Class dektrium\rbac\Module does not exist" i am using rbac in my application.
I checked desctrium\rabc directory there is no file with Module class. However i can see two new files RbacWebModule, RbacConsoleModule in that directoy.
I have a backup of my application on other server. so do i have to put my backup there to correct this error or is there any other solution. i can see in my vendor folder all other folders also get updated with composer update. So how to get rid of this error.
Thanks in advance.
This class has been renamed over a month ago. Since it's still beta I recommend to check for any major changes with every upgrade. Always follow the instruction.
Add rbac module to web application config file as follows:
...
'modules' => [
...
'rbac' => 'dektrium\rbac\RbacWebModule',
...
],
...

Symfony - Autoloader can't find class / composer error

When I tried adding a new dependency to my project with composer require xyz I got the following error:
The autoloader expected class "PackageVersions\Versions" to be defined in file ".../vendor/ocramius/package-versions/src/PackageVersions/Versions.php".
The file was found but the class was not in it, the class name or namespace probably has a typo.
I dug into that file, to see that the Versionsclass is there, in the right file, but with a the following name:
Versions_composer_tmp0
The namespace declarations seem to be good in the entire project, as well as php opening tags (I read that might cause such problems).
Additionally, I remarked that all the use statements in the Installer class file, which is the one that creates the Versions class are marked by phpstorm as Undefined Classes. They all should be found in the namespace Composer\xyz.
I tried the following without succes:
clearing the symfony cache
clearing composer cache
composer self-update
deleting the ocramius vendor folder so that composer would download it again
renaming the class, which is pointless since the entire purpose of this Versions class is to be rewritten with each composer install or composer update
edit:
I'm trying to install 1up-lab/OneupUploaderBundle, the Ocramius/PackageVersionsis already there as a dependency probably (I did not require it manually)
edit 2:
I just saw that server:run won't work either. So the problem is definitely not related to the bundle I'm trying to install. I managed to make the server run by renaming the class from Versions_composer_tmp0 to Versions.
It turns out that this is a composer issue:
composer/composer#5237
Ocramius released a fix/workaround for this:
Ocramius/PackageVersions - Release 1.0.4

Laravel 4 migrate rollback problems

I can easily run the artisan migrate etc, but when i try to roll it back, with migration:rollback i keep getting this error,
c:\xampp\htdocs\laravel>php artisan migrate:rollback
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'CreateCodesnippetsTable' not found","file":"C:\\xampp\\htdocs\\laravel\\vendor\\laravel\\framework\\src\\Illum
inate\\Database\\Migrations\\Migrator.php","line":301}}
Is this a bug? or how should i debug this?
Maybe you've already solved this issue. But I'm noticing that for some reason a rollback often requires you to run composer dumpautoload first. Even if your migration works.
Having just wrestled with this problem for several days, I think I can now provide the definitive answer to solving this problem. Yeah, big call I know, but bear with me.
The first port of call if you encounter this problem is to run composer dump-autoload. This should result in an updated version of the file vendor/composer/autoload_classmap.php.
If autoload_classmap.php doesn't get updated then you may have a permissions problem, in which case you could try sudo composer dump-autoload.
However, if autoload_classmap.php does get updated, check that it contains an entry for your migration class (in this case CreateCodesnippetsTable). If there is no entry for this class then you should check your composer.json file and make sure the app/database/migrations folder is included in the autoload section, eg:
"autoload": {
"classmap": [
"app/controllers",
"app/models",
"app/database/migrations"
]
},
This last bit is what screwed things up for me. In a misguided attempt at optimising things I pulled as much as I could out of my composer.json file, naively thinking this would only affect web requests. It turns out this affected Artisan as well, so putting this line back in and running composer dump-autoload fixed the problem for me.
Finally, if all that fails, then maybe there's a bug in one of the supporting libraries that is causing the problem, in which case you can try updating using composer update or some variation thereof. However, I suspect that this will rarely be the true cause of the problem.
If you are in windows, simply use composer in your terminal/command line utility and do the following:
composer dump-autoload
Hope it helps!
From what I can see I am guessing you have changed the class name manually.
In the error you have the class name CreateCodesnippetsTable but in the migration file you provided (pastebin), the class name is CreateCodeSnippetsTable (notice the S in Snippets, I guess that is what you changed manually).
If you check the migrations table in your database you will see records for each migration. When you create the migration it will be saved in the database with that name and the rollback method tries to read the file with the name provided in the database, in the case when you change it manually laravel can't find the class and you get the error.
To fix this you can undo the changes and try to rollback or manually edit the migration row in your database to include the correct class name.
Hope this helps.
It seems to me there are no single solution of this error. I have tried many suggestion but at last this one works in my end.
COMPOSER=composer.json composer dump-autoload
I fixed it by running
composer.phar update
download the composer.phar file from laravel site and bring the composer.phar file to the root directory of laravel folder,
then from terminal come to the root directory of laravel and run the composer.phar update or simply run php artisan dump-autoload.
i faced the same problem and figure out the problem
I've created a migration for adding new column date in PatientReasonOfVisits table
i used laravel generators
when i create the migration the class name was
class AddDateToPatientReasonOfVisitsTable
sure after creating a new migration file u need to run composer dump-autoload to ensure the file is listed in class map file
the file name was
2014_09_02_214134_add_date_to_patientreasonofvisitstable.php
the migration done successfully
and a new record has been added into migration table.
in migration column the file name is used
when i rollback the migration
i got the class not found exception what class is not found
this one
AddDateToPatientreasonofvisitsTable
note : the difference between classes names
why and how i solved this problem
i guess when u rollback the class name resolved using the migration file name which in migration table
the capital and small letters is decided by underscores "_" in file name
so after renaming the migration file to
2014_09_02_214134_add_date_to_patient_reason_of_visits_table.php
and sure run composer dump-autoload after renaming the file
the class name resolved correctly with no exception
I simply dropped the migrations table then ran php artisan migrate:refresh
Then the migrations were all able to execute, not sure if that's the best method, but it worked for me.
I'm running Laravel 5.

Categories