just started working on a project, I ran composer update and was greeted with a exception when trying to clear cache.
When I try to run php bin\console server:run I am greeted with this message:
php bin\console server:run
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Fatal error: Class 'AppKernel' not found in CoreBundle\bin\console:27
Stack trace:
#0 {main}
thrown in CoreBundle\bin\console on line 27
Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Fatal error: Class 'AppKernel' not found in CoreBundle\bin\console on line 27
Symfony\Component\Debug\Exception\FatalThrowableError: Fatal error: Class 'AppKernel' not found in CoreBundle\bin\console on line 27
Call Stack:
0.0112 427536 1. Symfony\Component\Debug\ErrorHandler->handleException() CoreBundle\vendor\symfony\symfony\src\Symfony\Component\Debug\ErrorHandler.php:0
Another strong possibility, particularly if the project has been updated from a v2.7 project (or before) is that the AppKernel is just not known to Composer. It is now best practice to not manually require/include the file, (so those lines are removed from web/app_*.php, and bin/console.php). but instead have it autoloaded. However, this requires a line in Composer so that it can be found. Only the composer autoloader would ever be included manually, which can then load everything else.
"autoload": {
"files": ["app/AppKernel.php"],
"psr-4": { // etc...
There are two possible reasons for this.
First your autoloader is trashed or can't find files
composer dump-autoload
Second reason could be, that your var directory isn't writable in which the cache file for symfony is placed.
Just check the permissions.
Also take a close look into the log files.
Maybe it tells you what the real Problem is.
(Like an issue with syntax etc.)
For some reason, I had to explicitly add src/Kernel.php to autoload. So my composer.json autoload section became:
"autoload" : {
"files": ["app/AppKernel.php",
"src/Kernel.php"],
"psr-4": { "": "src/"},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
}
After adding this, running composer dump-autoload did the trick.
Related
I'm using Symfony 4.4 on a project and I need to use stfalcontinymce. Since I'm on SF4 I need the version 2.4. So I did this:
composer require stfalcon/tinymce-bundle=2.4
But then I get this error:
!! 11:03:44 CRITICAL [php] Uncaught Error: Class 'Twig_Extension' not found ["exception" => Error { …}]
!!
!! In StfalconTinymceExtension.php line 13:
!!
!! Attempted to load class "Twig_Extension" from the global namespace.
!! Did you forget a "use" statement?
Someone told me that it's because this version doesn't get along with Twig 3 so I need to downgrade my Twig version. I then did this to downgrade Twig:
composer require twig/twig=2
But then I get this error:
13:14:07 CRITICAL [php] Uncaught Error: Call to undefined method Twig\Environment::registerUndefinedTokenPa
rserCallback() ["exception" => Error { …}]
!!
!! In srcApp_KernelDevDebugContainer.php line 2040:
!!
!! Attempted to call an undefined method named "registerUndefinedTokenParserCallback" of class "Twig\Environm ent".
!! Did you mean to call e.g. "registerUndefinedFilterCallback" or "registerUndefinedFunctionCallback"?
I tried adding in composer.json
"twig/extensions": "*"
Then composer install, then running the command:
composer require stfalcon/tinymce-bundle=2.4 -W
And I get this error:
!! 13:49:04 CRITICAL [php] Uncaught Error: Call to undefined method
Twig\Environment::registerUndefinedTokenParserCallback() ["exception" => Error { …}]
!!
!! In srcApp_KernelDevDebugContainer.php line 2045:
!!
!! Attempted to call an undefined method named "registerUndefinedTokenParserCallback" of class "Twig\Environment".
!! Did you mean to call e.g. "registerUndefinedFilterCallback" or "registerUndefinedFunctionCallback"?
I'm really lost here. Can someone help? thanks
Your executed commands don't seem to be possible on my system at all since there will be version constraint conflicts.
Instead of restricting to one version for your dependencies, you should use a constraint.
Your require in composer.json may contain something like the following
"twig/twig": "^2",
"stfalcon/tinymce-bundle": "2.4.*",
"twig/extra-bundle": "^2"
The constraints are explained here. But the ^2 basically means >= 2.x.x and < 3.0.0
For the tinymce bundle I used the above because of the this GitHub issue
Furthermore twig/extensions seems to be deprecated, and this GitHub issue mentions twig/extra-bundle which is needed and may be its replacement.
I am upgrading laravel from 5.5.* to 5.6.0. Composer install ran fine. I am trying to run unit tests upon which this error is popping up.
Class '..\Unit\UnitTestCase' not found
This is the stack trace of the error:
Fatal error: Uncaught Error: Class 'PhiraterTest\Unit\UnitTestCase'
not found in
/home/vagrant/code/phirater-l51/tests/unit/Phirater/AdditionalCurrencies/CreateAdditionalCurrencyCommandHandlerTest.php:11
Stack trace:
#0 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Util/Fileloader.php(64):
include_once()
#1 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Util/Fileloader.php(48):
PHPUnit\Util\Fileloader::load('/home/vagrant/c...')
#2 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Framework/TestSuite.php(325):
PHPUnit\Util\Fileloader::checkAndLoad('/home/vagrant/c...')
#3 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Framework/TestSuite.php(403):
PHPUnit\Framework\TestSuite->addTestFile('/home/vagrant/c...')
#4 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(65):
PHPUnit\Framework\TestSuite->addTestFiles(Array)
#5 /home/vagrant/code/phirater-l51/vendor/phpunit/phpunit/src/TextUI/Command.php(169):
PHPUnit\Runner\BaseTestRunner->getTest('tes in
/home/vagrant/code/phirater-l51/tests/unit/Phirater/AdditionalCurrencies/CreateAdditionalCurrencyCommandHandlerTest.php
on line 11
My unit tests are in tests/ directory. My UnitTestCase class in extended by \TestCase class and TestCase class is extended by BrowserKitTestCase. What am i doing wrong here? What could be the solution?
If your dependency class is really present and has proper namespace, then the most probable reasons of mentioned error are (avoid copying below examples to your project, that will definetely not work):
composer.json file (root directory) has no relevant record of the dependency (do not forget composer.lock file also), smth like:
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
as a result of above, vendor/autoload.php file (or any of its merged siblings, e.g. vendor/composer/autoload_classmap.php, depending on your case) can miss relevant record of the dependency, smth like:
return array(
'PHPUnit\\Framework\\TestCase' => '/vendor/phpunit/phpunit/src/Framework/TestCase.php',
In most such cases it is really a missed dependency delivered by autoload.php functionality, which in its turn caused by composer malfunctioning. So taking in account all that, try to update composer itself by running composer self-update, and then updating your dependencies by composer update.
I have made a test project to understand how composer and packagist works. The project is also on packagist.
A simple composer require rakibtg/gowin will install the package from packagist.
But for some reason the namespacing is not working as expected.
Here is my directory structure and the composer file.
Here is the GoWin.php file:
<?php
namespace GoWin;
class GoWin {
public function serve() {
echo 'Lets Win Everybody!';
}
}
Here is the test.php file where i am trying to use the serve() method from the GoWin class.
<?php
require_once './vendor/autoload.php';
// use GoWin;
( new GoWin\GoWin() )->serve();
But it fails to execute the serve method with this error:
Fatal error: Uncaught Error: Class 'GoWin\GoWin' not found in
/Users/usr/Desktop/t estGoWin/index.php:7 Stack trace:
0 {main} thrown in /Users/usr/Desktop/testGoWin/index.php on line 7
At this moment i cant understand what i am missing! Also should i use psr-0 or psr-4?
I solved it by switching to PSR-4, simply update the composer.json autolaod property as this:
"autoload": {
"psr-4": {
"GoWin\\": "src/"
}
},
I've tried updating Symfony to v2.7.40 today. At the end of the update process while clearing the cache I encounter
PHP Fatal error: Class 'Twig\Extension\AbstractExtension' not found
In my composer.json I already have required and installed "twig/extensions": "~1.5"
Do I need to update any other bundle/library?
Thank you
I am trying to setup mongo db in codeigniter after doing setup when I run my controller getting this error. I have tried similler error on stackoverflow but no luck. here is the error:
Fatal error: Class 'MongoClient' not found in /var/www/html/grant/application/libraries/Mongo_db.php on line 216
A PHP Error was encountered
Severity: Error
Message: Class 'MongoClient' not found
Filename: libraries/Mongo_db.php
Line Number: 216
Backtrace:
Your Mongo_db class is expecting that the MongoClient class has already been loaded and Mongo_db is trying to instantiate it. Your question didn't include the link to the Mongo library you are using so I'm unable to debug further, however here are the basic steps.
Before loading your Mongo_db library try loading Mongo_client
$this->load->library('mongo_client');
If your libraries rely on composer autoloader make sure that you have included the autoloader class somewhere in your bootstrap or configuration
include 'vendor/autoload.php'
If your libraries rely on composer, you may also want to check your autoload make sure you are including your libraries directory in the class map:
{
"autoload": {
"classmap": ["application/libraries"]
}
}
If you updated your autoload configuration in your composer.json file make sure to run this command
composer dump-autoload