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
Related
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
{
...
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.
Im getting this exception when running phpunit. I'm running the latest Laravel 5.4 with PHPUnit 5.7.23
ReflectionException: Class config does not exist
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Container/Container.php:729
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Container/Container.php:608
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Container/Container.php:575
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:728
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Container/Container.php:1172
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php:57
/home/vagrant/Code/ProcessingHub-App/vendor/myvendor/core/src/app/Providers/CoreServiceProvider.php:50
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:574
/home/vagrant/Code/ProcessingHub-App/tests/CreatesApplication.php:18
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:89
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:66
/home/vagrant/Code/ProcessingHub-App/tests/TestCase.php:27
/home/vagrant/Code/ProcessingHub-App/tests/Unit/PassportTest.php:30
As you can see the exception comes from CoreServiceProvider this is one of my own ServiceProviders Nothing to weird happening there as you can see here
/**
* Register any package services.
*
* #return void
*/
public function register()
{
$this->registerEloquentFactoriesFrom(__DIR__.'/../../database/factories');
$this->mergeConfigFrom(
__DIR__.'/../../config/fields.php', 'fields'
);
}
contents of fields.php:
return [];
If i outcommend $this->mergeConfigFrom() it works like a charm, but the weird thing is i do this in multiple ServiceProviders and in these Classes it is not an issue.
I literally tried everything.
Running: composer dump-autoload
Running: php artisan optimize
Removing vendor and reinstalling everything
Debugging everywhere but no usefull info
Replacing test with basic testExample from laravel didn't work either
I already replaced my .env with an new simple .env didn't help.
My question is:
Does annyone know how i could fix this.
After I looked more into the \tests directory with a fresh Laravel installation i saw the thing i was staring at for like hours and hours.
The application was trying to register the ServiceProvider before the app was bootstraped. Sorry for the troubles (It was not my code).
namespace Tests;
use Illuminate\Contracts\Console\Kernel;
trait CreatesApplication
{
/**
* Creates the application.
*
* #return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$app->register(\StepOrange\Core\Providers\CoreServiceProvider::class);
return $app;
}
}
I've a problem running my newly created Laravel package which please check out https://github.com/Younesi/laravel-aparat
I can download it via Composer with no problem and it's auto-discovered via Laravel but when I try to use it, It gives me the following error of not finding class.
Class 'Younesi\LaravelAparat\Aparat' not found
My service Provider code is like:
/**
* Register the service provider.
*
* #return void
*/
public function register()
{
$this->app->bind('aparat', function ($app) {
return new Aparat;
});
}
/**
* Get the services provided by the provider.
*
* #return array
*/
public function provides()
{
return array('aparat');
}
Any help would be appreciated.
Looking at the package it's working fine, in composer.json of that package there is:
"autoload": {
"psr-4": {
"Younesi\\laravelAparat\\": "src"
}
},
Notice that laravel is not with capital letter here, so in your code you should import rather this way:
use Younesi\laravelAparat\Aparat;
instead of:
use Younesi\LaravelAparat\Aparat;
I also see that you are author of this package, so I would recommend using standard conversion (namespace starting with capital letter) instead of current namespace.
Looking further at package code, I also see that in service provider there is:
namespace Younesi\LaravelAparat;
namespace so it's nothing weird it won't work if you autoload it with lower-case letter and have namespace with upper-case letter
There were some cases with registration problem, cache issues, etc. Try one of these solutions:
register your provider (in main composer.json, then in config/app.php [provider & alias] ), then run composer dump-autoload
make sure you have initiated your package : go to the folder, then composer init
try php artisan config:cache or delete everything in bootstrap/cache/
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.