I am quite confused by the following deprecation notice in my Symfony 5.4 application.
The "Symfony\Component\Console\Command\Command::$defaultName" property
is considered final. You should not override it in
"CRMPiccoBundle\Console\Command\Aws\Cognito\CreateUser".
In my code I have the following:
class CreateUser extends Command
{
protected static $defaultName = 'crmpiccobundle:aws:cognito:createuser';
...which aligns with the documentation.
The parent Command class looks like this:
/**
* #var string|null The default command name
*/
protected static $defaultName;
All my commands are now outputting a deprecation notice, which is not ideal.
composer show | grep console
symfony/console v5.4.19 Eases the creation of beautiful and testable command line interfaces
What am I misunderstanding here? I'm on PHP 8.1.14.
First: Deprecations are not errors You are not required to fix anything until you upgrade to Symfony 6. Then you must fix the error.
Second, like many documentations, the Symfony docs sometimes lag behind the development. The new method is documented here
So you can switch to using this
#[AsCommand(
name: 'crmpiccobundle:aws:cognito:createuser',
description: 'Creates a new user.',
)]
class CreateUser extends Command
{
...
Related
There's a solution via RFE for this in RFE; solve problem with bin commands and php versions
I'm dealing with a new app in symfony 5.4 and php 7.4 to test the new additions and changes in symfony 6. I've used the entity maker from the console to create the entity and the crud, and the db was created perfectly. However, the generator uses the new "attributes" (according to the convention in https://symfony.com/doc/5.4/routing.html) instead of the "classic" annotations. Debugging via console to see the resulting paths, none of the routes defined in the controllers is shown (of course, a 404 error was shown when accessing the url in dev mode). I decided to replace the attributes with classic annotations, and the paths are shown and the 404 error is gone. But now, I find that the logic the generator uses is via the repository to use the Entity Manager, and when accessing to the index to start from scratch, I get:
Could not find the entity manager for class "App\Entity\Room". Check your Doctrine configuration to make sure it is configured to load this entity’s metadata.
The portion of code shown in the debugger is this:
class RoomRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Room::class); // Here is the error
}
And the entity starts with this:
namespace App\Entity;
use App\Repository\RoomRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: RoomRepository::class)]
class Room
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column()]
private ?int $id = null;
...
My biggest concern is that I guess I can't rewrite the full crud reverting to annotations, which is a lot of work (just what I wanted to avoid by using the generator), so there must be something about the attributes that I'm missing. Here's a controller whose crud I haven't modified yet, so anyone can take a look and find out why the router can't find the defined paths with this kind of annotation.
namespace App\Controller;
use App\Entity\RoomFeature;
use App\Form\RoomFeatureType;
use App\Repository\RoomFeatureRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/admin/feature')]
class RoomFeatureController extends AbstractController
{
#[Route('/', name: 'admin_room_feature_index', methods: ['GET'])]
public function index(RoomFeatureRepository $roomFeatureRepository): Response
{
return $this->render('room_feature/index.html.twig', [
'room_features' => $roomFeatureRepository->findAll(),
]);
}
...
What is the problem with all this? Thanks in advance.
As stated in the first comment, forcing every bin/console (for make: commnds) and composer commands to be run especifically by prepending php7.4 to the command, everything works but with "classic" annotations, I've found no way to use attributes in controllers with php7.4. The .php-version file seems to be used only by the symfony-cli to launch the dev webserver. I hope this helps anyone who can face this scenario in the future.
I had a similar situation and on my case it was related to an incorrect namespace on a Trait (under src/Entity/Traits).
The trait wasn't even being used but apparently it will still cause this error.
Regarding your second comment:
the resulting code using annotations via attributes should be
compatible with whatever version of php is supported with symfony 5.4
This assumption is wrong, since symfony 5.4 supports php 7.2.5 and up. Although 7.2 is sunsetted officially, there are plenty of installations out there or with extended support from distros so that's besides the point: Symfony will happilly run in 7.2 or 7.3.
In any case, it's maker bundle who determines whether or not to use attributes based on the php version that is used to execute the maker commands, not the available installed versions. You can force it to use specific version features by executing composer config platform.php 7.4.x.
And be aware that maker bundle 1.44 has dropped annotation support altogether, so pin your version to an older one.
I have following lines of code in my controller.
<?php
namespace App\Controller;
use App\Repository\TaskListRepository;
use FOS\RestBundle\Controller\AbstractFOSRestController;
class ListController extends AbstractFOSRestController
{
/**
* #var TaskListRepository
*/
private $taskListRepository;
public function __construct(TaskListRepository $taskListRepository)
{
$this->taskListRepository = $taskListRepository;
}
/**
* #Route("/lists", name="lists")
*/
public function getListsAction()
{
return $this->taskListRepository->findAll();
}
}
When I try to debug route, I am getting following error:
[info] User Deprecated: Using the WebserverBundle is deprecated since
Symfony 4.4. The new Symfony local server has more features, you can
use it instead. 2019-12-16T04:37:53+01:00 [info] User Deprecated:
Loading the file "../../src/Controller/" from the global resource
directory "D:\xampp\htdocs\symfony_rest\src" is depre cated since
Symfony 4.4 and will be removed in 5.0.
How can I fix this issue?
The deprecation message that you get has nothing to do with your controller and is just a warning, not an error.
You have included the WebserverBundle bundle in your project, but this bundle will be deprecated past Symfony 4.4. The bundle itself is fine and you can still use it, but it simply means that you won't be able to use it anymore once you move to Symfony 5.
If you don't use the bundle and want to get rid of the deprecation message, simply run the following command:
composer remove symfony/web-server-bundle
I want to get the objects of a repository but I have next error
Call to a member function findAll() on null
The error line is $projects = $this->projectRepository->findAll();
First used the object manager to get the repository, it did not work. The current configuration is:
In Controller
/**
*projectRepository
*
* #var \VENDOR\MyExtName\Domain\Repository\ProjectRepository
* #inject
*/
protected $projectRepository = null;
And Repository
class ProjectRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
public function createQuery() {
$query = parent::createQuery();
$query->getQuerySettings()->setRespectStoragePage(FALSE);
return $query;
}
}
This happens also with findByUid($uid)
The objects exists in DB and visible in BE.
I cleaned the caches, deleted the contents of the typo3temp directory and followed the questions about a similar error (that I thought) Call to a member function findAll() on a non-object , but it did not work and the exception I have is different.
I appreciate your help, please guide me to correct this error
This error is almost always caused by the annotation "compiling" of extbase and related to the cache. You said you cleared the caches and removed the contents of typo3temp, but the cache clearing methods are very different and they do not work for every cache.
For example, the annotation cache is only cleared by using the Clear Cache button of the Install Tool. The toolbar icons on top of the TYPO3 backend do not clear these kinds of caches.
The annotation caches will not get stored in the typo3temp folder afaik, but have their own section in the database. Cache clearing should NEVER be done by deleting typo3temp folder content by hand, but ALWAYS via the Install Tool or the appropriate buttons or commands in the TYPO3 backend or the CLI.
Finally, there is an autoload cache of PHP classes, that doesn't get cleared by the Install Tool either. So if you add a new PHP class to your extension in development, you need to deinstall and reinstall your extension via the extensionmanager. If you are using composer to install your TYPO3 instance, it is again a little bit different. If this is the case, you can clear the autoload cache by typing in the command composer dump-autoload to clear the class loading cache of composer, since TYPO3 is using it if in composer mode.
I guess that you simply did not try the Install Tool button to clear the cache.
And this error occurs if you forget to inject your repository in your controller:
/**
*projectRepository
*
* #var \VENDOR\MyExtName\Domain\Repository\ProjectRepository
* #inject
*/
protected $projectRepository = null;
If you use the methode __construct, to be careful dont type __constract.
I have started to learn Laravel. Until now, everything worked perfectly. I'm following this tutorial and I'm stuck with episode 7.
The problem is that I cannot start artisan anymore. I have tried to install tinker, and I've probably updated artisan so I ended up without artisan and tinker. I am using Linux Ubuntu 12.04 LTS. I have installed everything via command line. After that I tried to run:
php artisan --version
The following problem occurs:
[ErrorException]
Declaration of App\Providers\EventServiceProvider::boot() should be
compati ble with
Illuminate\Foundation\Support\Providers\EventServiceProvider::boot
()
This is how my file app/Providers/EventServiceProvider.php looks like:
<?php
namespace App\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* #var array
*/
protected $listen = [
'App\Events\SomeEvent' => [
'App\Listeners\EventListener',
],
];
/**
* Register any other events for your application.
*
* #param \Illuminate\Contracts\Events\Dispatcher $events
* #return void
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
//
}
}
I'm using Laravel 5.2 and my composer.json it looks like this:
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"doctrine/dbal": "^2.6#dev",
"vluzrmos/tinker": "dev-master",
"moon/artisan": "dev-master"
I've seen similar problems here for example:
https://laracasts.com/discuss/channels/general-discussion/l5-composer-update-ends-with-an-error-suddenly
https://laracasts.com/discuss/channels/laravel/event-service-provider-in-package
but never the answer was given directly and actually I do not understand how to solve this problem? I would need direct answer because I'm newbie in Laravel. Can artisan be updated somehow easy with Linux command line so it can work again?
Apparently, the new boot() method doesn't take any argument. You'll have to apply some changes to the three providers.
/**
* Register any other events for your application.
*
- * #param \Illuminate\Contracts\Events\Dispatcher $events
* #return void
*/
- public function boot(DispatcherContract $events)
+ public function boot()
{
- parent::boot($events);
+ parent::boot();
//
}
Check out this commit for the full list of changes.
https://github.com/laravel/laravel/commit/2b05ce3b054593f7622c1be6c4c6aadc1c5a54ae
Similar to #greut answer, but if it is caused by upgrading laravel (which may be triggered if you are installing other package through composer update and your version for laravel is dev-master), there are 2 places that you need to change the parameter.
App\Providers\RouteServiceProvider
App\Providers\EventServiceProvider
In both controller, there is a method named boot(). Change the parameter to empty. i.e.
public function boot(/*original something here. empty it*/)
{
parent::boot(/*original something here. empty it*/);
}
Reference: https://laracasts.com/discuss/channels/forge/laravel-53-update-causing-error-on-forge-only/replies/189654
I encountered the same problem in forge while performing the upgrade to 5.3, you need to get rid of bootstrap/cache and as you mentioned artisan won’t launch because of that error so you need to do it the old way: rm -R bootstrap/cache and then mkdir bootstrap/cache. Don’t forget to apply the correct permissions of bootstrap/cache after you’re done.
Speaking strictly from a PHP point of view, when artisan tries to start up its CLI application, and you get this error
Declaration of App\Providers\EventServiceProvider::boot() should be compatible with Illuminate\Foundation\Support\Providers\EventServiceProvider::boot
You've defined a class App\Providers\EventServiceProvider. This class has Illuminate\Foundation\Support\Providers\EventServiceProvider as an parent/ancestor (aliased as ServiceProvider in your class).
The boot method in your Illuminate\Foundation\Support\Providers\EventServiceProvider has a set of arguments. You have defined boot in App\Providers\EventServiceProvider, and changed those arguments somehow (fewer arguments, different type hints, different/no defaults, etc.).
You can't do that.
Make you boot compatible with the parent class, and you'l fix your problem.
(This, however, might not fix all your problems, as the comments make it sound like you're using an unreleased version of Laravel that may differ from what's in a tutorial)
I'm going through the process of setting up and running behat on windows. The installation and set up where successful, now when trying to run it from CMD i get:
2 scenarios (2 undefined)
8 steps (8 undefined)
0m0.081s
You can implement step definitions for undefined steps with these snippets:
/**
* #Given /^I am on "([^"]*)"$/
*/
public function iAmOn($arg1)
{
throw new PendingException();
}
And so on.
I'm running the command:
F:\Program_Files\Behat\bin>Behat F:\Program_Files\Behat\vendor\behat\mink-extension\features\search.feature
I think that some resource is not being reached, so there is are all the relevant directories:
Behat: "F:\Program_Files\Behat\bin\"
Features: "F:\Program_Files\Behat\vendor\behat\mink-extension\features\"
Feature context: "F:\Program_Files\Behat\bin\features\bootstrap\FeatureContext.php"
Behat config: "F:\Program_Files\Behat\bin\behat.yml"
Trying to place the features file here: "F:\Program_Files\Behat\bin\features\search.feature"
gives the same output.
Please let me know, how to succefully run behat against the *.feature file specified. Thanks.
UPDATE:
when i run " >behat -dl " there is no output - I guess I'm not reaching definition expressions.
Yes, the step definitions where missing in:
Behat\bin\features\bootstrap\FeatureContext.php
I was confused a bit when they ran the test script in this tutorial:
http://knpuniversity.com/screencast/behat/intro
If anyone else has this problem follow these steps here and add the step definitions manually:
http://docs.behat.org/quick_intro.html#writing-your-step-definitions
Or please check that the FeatureContext.php correctly inherits the step definitions from Mink library. You should comment out this line:
Behat\Behat\Context\BehatContext,
Add this line:
use Behat\MinkExtension\Context\MinkContext;
And modify the FeatureContext class declaration to extend MinkContext
class FeatureContext extends MinkContext { // code here }