i know this question has been asked already multiple times:
Symfony 3.4 and Fixtures Bundle issue with bundle version 3.0
Symfony 3.4.0 Could not find any fixture services to load
Symfony Doctrine can't find fixtures to load
Could not find any fixture services to load - Symfony 3.2
None of the above actually helped me out. That said, this is my configuration:
Composer.json
"require": {
"php": ">=7.0",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
....
},
"require-dev": {
....
"doctrine/doctrine-fixtures-bundle": "^3.0",
}
I'm using a company-developed Bundle which worked fine until the last version of the above (last tested and working configuration had PHP 5.6, Doctrine bundle ^1.6,doctrine orm ^2.5, fixture bundle ^3.0).
This bundle has some Fixture inside VendorName/BundleName/DataFixtures/ORM, all the fixtures have the following declaration:
Class MyFixture1 extends Fixture implements OrderedFixtureInterface,FixtureInterface, ContainerAwareInterface{
...
}
Inside this bundle there's a services.yml file, loaded by this:
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
VendorName/BundleName/Resources/config/Services.yml i tried different configurations:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
VendorName\BundleName\:
resource: '../../*'
# you can exclude directories or files but if a service is unused, it's removed anyway
exclude: '../../{Entity,Repository,Tests,EventListener}'
I tried expliciting searching inside DataFixtures:
VendorName/BundleName\DataFixtures\:
resource: '../../src/VendorName/BundleName/DataFixtures'
tags: ['doctrine.fixture.orm']
And even manually configure the service:
VendorName\BundleName\DataFixtures\ORM\MyFixture1:
class: VendorName/BundleNamee\DataFixtures\ORM\MyFixture1
tags: ['doctrine.fixture.orm']
But unfortunately it keeps giving the error. Any idea of what i'm doing wrong? Long time ago it was possible to manually specify to the fixture command which bundle to look in, but now it's not possible anymore
UPDATE 1:
Sorry guys forgot to point the error message: "Could not find any fixture services to load"
The accepted answer helped point me in the right direction to get this working. Though cache could indeed be a problem, having Fixtures in your own bundles does require you to register them.
Using SF 5.1.* I created a services_dev.yaml file and added in:
services:
// other config
Namespace\Registered\In\Composer\For\Fixtures\:
resource: '../vendor/path/registered/in/composer/to/fixtures'
tags: ['doctrine.fixture.orm']
Then indeed, clear cache and it should work.
Added *_dev to the services.yaml file as it's a way for Symfony to only load it in when in your in a dev environment (per APP_ENV Environment variable).
For everyone landing here i solved my problem, what i can tell you is:
Double check you enabled the Bundle in the AppKernel
Clear your symfony cache using the command php bin/console cache:clear --env=dev (or env=prod)
Manually delete cache folder
Related
I'm having autowiring issues within symfony since I have updated my Docker to the latest version.
I am not entirely sure of the causality here but certainly, my issues started appearing only after updating my docker. Since this was the case I obviously tried to revert back to a previous docker version but still had the same issues as on the new build. That's why I am doubtful of the causality.
I'm now on: Docker version 3.5.2 with Docker Engine v20.10.7
docker-engine config is the unchanged config:
{
"registry-mirrors": [],
"insecure-registries": [],
"debug": false,
"experimental": false,
"features": {
"buildkit": true
},
"builder": {
"gc": {
"enabled": true,
"defaultKeepStorage": "20GB"
}
}
}
when I started my first project I had an issue with the composer not reading my lib-folder. This was solved as described below but it might provide some more insight, context and things I have checked/done
At first my mind went to this Windows env variable. Alas, it was set so it was not the problem.
Secondly, my mind went to file ownership or file permissions but also not the problem. Everything in my containers was owned by root and had rwx permissions.
Thirdly I thought it might be because of the new WSL2 backend I had to install. Until the day of the update I had still been running on the Hyper-V backend. Luckily there is a setting in docker where you can switch off the use of WSL-2 and revert to Hyper-V but this was also not the solution to my problem.
My composer.json looked like this:
"autoload": {
"classmap": [
"scripts/composer/ScriptHandler.php",
"lib/",
...
],
"psr-4": {
...
}
},
Everything but (some) files of lib were present in my autoload_classmap.php
After fiddling about for too long I finally tried the following and suddenly my problems on my first project were gone
"autoload": {
"classmap": [
"scripts/composer/ScriptHandler.php",
"lib/*",
...
],
"psr-4": {
...
}
},
I still don't understand why the first one should not work. It has worked until this thursday since the infamous update.
Now on to the second project and I really can't figure out what's going on and I'm at a loss for words. My colleagues can't seem to figure out what's wrong either. This second project is something more recent so not loading a classmap anymore and everything follows PSR-4 standards.
This is the autoload part of the composer.json:
"autoload": {
"psr-4": {
"App\\": "src/",
"Project\\": "scripts/"
}
},
This is my services.yaml (These are just the standard symfony settings AFAIK):
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'
This is my docker PHP container:
php:
container_name: "${DOCKER_PROJECT_NAME}_php"
environment:
COLUMNS: 80
PHP_FPM_GROUP: wodby
PHP_FPM_USER: wodby
PHP_SENDMAIL_PATH: "/usr/sbin/sendmail -t -i -S mailhog:1025"
PHP_DEFAULT_CHARSET: 'utf-8'
PHP_DATE_TIMEZONE: 'UTC'
PHP_UPLOAD_MAX_FILESIZE: '10M'
PHP_POST_MAX_SIZE: '10M'
PHP_DISPLAY_ERRORS: 'On'
PHP_DISPLAY_STARTUP_ERRORS: 'On'
PHP_MAX_EXECUTION_TIME: '30000'
PHP_MAX_INPUT_TIME: '60'
PHP_MAX_INPUT_VARS: '2000'
PHP_ERROR_REPORTING: 'E_ALL'
PHP_LOG_ERRORS: 'On'
PHP_LOG_ERRORS_MAX_LEN: '0'
PHP_MEMORY_LIMIT: '512M'
PHP_SESSION_GC_MAXLIFETIME: '700000'
PHP_REALPATH_CACHE_SIZE: '4096K'
PHP_REALPATH_CACHE_TTL: '3600'
PHP_XHPROF: $PROFILING_ENABLED
env_file:
- .env
image: "wodby/php:7.4-dev-4.16.2"
volumes:
- "./:/var/www/html"
## For php profiler traces
- "files:/mnt/files"
On startup I am getting the following Runtime Exception:
Cannot autowire service "App\Form\Wizard\DaysOffType": argument "$daycareTransformer" of method "__construct()" references class "App\Form\DaycareTransformer" but no such service exists.
This class is not new, it's been in code for 2 years. It's in the right folder and the namespacing is correct. Also the src folder is included in the autoload_psr4.php.
The DaycareTransformer that "can't be found" is located in src/Form under the namespace App\Form as per psr4 namespace convention
<?php
namespace App\Form;
use App\Entity\Daycare;
use App\Service\DaycareService;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
class DaycareTransformer implements DataTransformerInterface
{
private $daycareService;
public function __construct(DaycareService $daycareService)
{
$this->daycareService = $daycareService;
}
...
}
There have not been any recent changes to this code. Not to the DaysOffType which has the DaycareTransformer injected and not to the DaycareTransformer.
I am the only person having these issues as I am the only one who runs Docker on a Windows machine. Production and QA environments are all up and running so there is no structural problem in the code.
It could be because the project running symphony in this case was locate at Windows partition (C: or D: or whatever inside your window) and not Linux distro.
If you are using WSL (most likely), you should always store Linux related project inside your distro (Ubuntu in my case, I store it it ~/...). You should not store Linux related project in /mnt/... when using WSL.
When I said "Linux related" I mean whatever project usually want to run on Linux environment, or using docker
Don't know if this could solve it for others because there could be a wide range of reason for this problem. But this is how I solve mine.
We've got the same problem on a Windows machine with Docker and Symfony 5.x.
We continued to work on this machine, but we changed our configuration.
For example, for your error I would use the following config.
Cannot autowire service "App\Form\Wizard\DaysOffType": argument "$daycareTransformer" of method "__construct()" references class "App\Form\DaycareTransformer" but no such service exists.
config/services.yml or config/services_dev.yml
services:
App\Form\DaycareTransformer: ~
We defined all the required classes from our errors and it solved our problem. But it solved problem only for one URL instead of all. You need to check each your routes or classes that use Symfony's autowire.
Unfortunately, the solution like declaration of resources didn't for us. We had to define all the required classes from our errors.
services:
App\DataTransformer\:
resource: '../src/DataTransformer/'
Don't redefined your classes that have already defined in your config, because it replaces your configuration and may make other errors.
You can do it in config/services.yml and commit it or you can use config/service_dev.yml and don't commit it if you haven't use this config before. In the second way you also can change .gitignore and add there the filename.
# Ignore changes for the file and don't track it.
config/services_dev.yml
WARNING! If you still have problems with it define all the required classes in services.yml instead of two or more config files.
We don't have this problem on Linux and MacOS machines.
I start new project and install fresh copy of Symfony 5 (microservice skeleton), and add first controller HealthCheckController to the default folder src/Controller, at this moment all is fine, I can get access to it from browser.
In next step I change a project name in composer.json and all related namespaces in code to
"autoload": {
"psr-4": {
"Project\\SubProject\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Project\\SubProject\\Tests\\": "tests/"
}
},
and in service.yaml
Project\SubProject\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
Project\SubProject\Controller: # assuming you have namespace like that
resource: '../src/Controller/'
tags: [ 'controller.service_arguments' ]
everything still works.
Next step is to change directory structure, add layers and modules. So I move Kernel.php to the Common/Infrastructure/Symfony/ (ofcourse I change path to config files in the kernel) and controller to folder Common/Interfaces/Controller and change configs in the service.yaml
Project\SubProject\:
resource: '../src/'
exclude:
- '../src/Common/Infrastructure/Symfony/DependencyInjection/'
- '../src/Common/Infrastructure/Symfony/Kernel.php'
- '../src/Module1/Infrastructure/Entity/'
- '../src/Module2/Infrastructure/Entity/'
- '../src/Module3/Infrastructure/Entity/'
- '../src/Module1/Test/'
- '../src/Module2/Test/'
- '../src/Module3/Test/'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
Project\SubProject\Common\Interfaces\Controller\: # assuming you have namespace like that
resource: '../src/Common/Interfaces/Controller/'
tags: [ 'controller.service_arguments' ]
and in routes/annotation/yaml
controllers:
resource: ../../src/Common/Interfaces/Controller
type: annotation
kernel:
resource: ../../src/Common/Infrastructure/Symfony/Kernel.php
type: annotation
and now I'm getting error Project\SubProject\Common\Interfaces\Controller\HealthCheckController" has no container set, did you forget to define it as a service subscriber?
What I'm doing wrong, I forgot to change something???
I know you can tell me you need to add container to controller like this
Project\SubProject\Common\Interfaces\Controller\HealthCheckController:
calls:
- method: setContainer
arguments: ['#service_container']
but it's stupid to configure each controller manually when autowire feature turned on, and when it worked with a default directory structure.
Also I clear cache by CLI command and manually deleting folder.
It was somewhat difficult to follow exactly what your configuration files ended as. I don't have a specific answer for you but I was a bit intrigued at the notion of moving Kernel.php. You did not mention moving the config directory so I chose to leave it where it was and:
namespace Project\SubProject\Common\Infrastructure\Symfony;
class Kernel extends BaseKernel
{
protected function configureContainer(ContainerConfigurator $container): void
{
$base = $this->getProjectDir();
$container->import($base . '/config/{packages}/*.yaml');
$container->import($base . '/config/{packages}/'.$this->environment.'/*.yaml');
$container->import($base . '/config/services.yaml');
$container->import($base . '/config/{services}_'.$this->environment.'.yaml');
}
# same for configureRoutes
# project/config/services.yaml
services:
_defaults:
autowire: true
autoconfigure: true
Project\SubProject\:
resource: '../src/'
exclude:
- '../src/Common/Infrastructure/Symfony/Kernel.php'
Project\SubProject\Common\Interfaces\Controller\:
resource: '../src/Common/Interfaces/Controller/'
tags: ['controller.service_arguments']
# project/config/routes/annotations.yaml
controllers:
resource: ../../src/Common/Interfaces/Controller/
type: annotation
Tweaked index.php and console to use the new Kernel path and it all worked as expected.
I should point out that as long as you are extending from AbstractController then you don't actually need the Controller section in services.yaml at all. It's quite puzzling why you seem to be getting a controller service but setContainer is not being called.
bin/console debug:container HealthCheckController
Class Project\SubProject\Common\Interfaces\Controller\HealthCheckController
Tags controller.service_arguments
container.service_subscriber
Calls setContainer
The Calls setContainer is obviously the important line.
I'm guessing you do have a typo somewhere and I suspect you did not actually start your namespace with Project\SubProject. But again it does work as expected.
Just for my own reference I checked in my test project.
I'm a newbie on Symfony and I'm having a problem to integrate the 'ry167/twig-gravatar' package on my project.
First, I did :
$ composer require ry167/twig-gravatar 3.0.0
And after I modified my services.yaml, which looks like this :
services:
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
twig.extension.gravatar:
class: \TwigGravatar
arguments:
$default: ~ e.g. 'monsterid'
$size: ~ e.g. 50
$filterPrefix: ~ e.g. 'foo'
$rating: ~ e.g. 'x'
$useHttps: true
tags:
- { name: twig.extension }
And finally, I have this on my view:
<p>{{ 'example#example.com'|grAvatar }}</p>
But I got this error:
Invalid service "twig.extension.gravatar": class "Twig_Extension" not found while loading "TwigGravatar"
Any ideas? I can't understand where my problem comes from...
You probably use Twig 3.* which removed all PSR-0 classes (with the underscore).
The next version of ry167/twig-gravatar fixes the issue.
There is already a release candidate.
Option 1: Wait for next stable release
If you want to wait for the stable release, then temporarily add a conflict block to your composer.json to use the latest Twig version before 3.0:
{
...
"require": {
...
"ry167/twig-gravatar": "^3.0.0",
...
},
"conflict": {
"twig/twig": ">=3.0"
}
}
Run composer update afterwards to let Composer do the work of figuring out the dependencies and downgrading your Twig version.
You may remove the conflict when version 4.0 is released and you changed the dependency to ^4.0.0.
Option 2: Use Release Candidate
If you want to use the new version right away, you have to tell composer that non-stable versions are alright using stability flags.
composer require ry167/twig-gravatar "^4.0.0#RC"
I try to load css and js files from my symfony project and for all files I have 404.
So, I try like this :
<link href="{{ asset('css/css-theme/bootstrap.min.css') }}" rel="stylesheet">
I mention that I create the install of web :
php bin/console assets:install web --symlink
As result I have :
Trying to install assets as absolute symbolic links.
Bundle Methode/Error
FrameworkBundle absolute symlink
[OK] All assets were successfully installed
What I'm doing wrong ? Please help me. Thx in advance
Since Symfony 2.8 Assetic Bundle is not embebbed with this. You must install first your assetic bundle :
install with composer
composer require symfony/assetic-bundle
declare bundle in you appKernel
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = array(
// ...
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
);
// ...
}
}
declare config in your config.yml
# app/config/config.yml
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
cssrewrite: ~
You also need to dump assets via command:
php bin/console assets:dump
This physically writes all of the asset files you need for your environment. The big disadvantage is that you need to run this each time you update an asset
You can use "watch" command so that assets are regenerated automatically as they change.
php bin/console assetic:watch
More on assets management process here:
Symfony asset Documentation
Edit
Correct command for dump is.
php bin/console assetic:dump
You may also need to install "assetic" bundle via composer. With a command.
composer require symfony/assetic-bundle
And add it to your AppKernel:
public function registerBundles()
{
$bundles = array(
// ...
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
);
// ...
}
I´m trying to make working doctrine2 extensions but it still wrotes me this error:
Fatal error: Class 'Gedmo\Tree\TreeListener' not found in /data/web/virtuals/48565/virtual/www/domains/kozusnikjan.com/Symfony/app/cache/prod/appProdDebugProjectContainer.php on line 1377
And I don´t know, how to solve the problem. Please, help. Here are some files:
http://pastebin.com/k9rqvGQn -- config.yml
http://pastebin.com/TvxbvEyS -- doctrine-extensions.yml
http://pastebin.com/prUFmrTb -- AppKernel.php
http://pastebin.com/0zAaHwW9 -- DoctrineExtensionListener.php
Thank you very much
Edit:
New files:
http://pastebin.com/qEAZtFba -- composer.json
http://pastebin.com/aBnvrZj9 -- config.yml
http://pastebin.com/E1aSSddm -- appKernel.php
I edited this files. I didn´t create any file. Thank you for your help!
You're using Gedmo directly. Try through StofDoctrineExtensionsBundle...
If you are using composer add to your composer.json at require section
"stof/doctrine-extensions-bundle": "1.1.*#dev"
and run composer update. You must load bundle on AppKernel.
then put on your config.yml
stof_doctrine_extensions:
default_locale: %locale%
orm:
default:
tree: true
May be you wanna find your problem, but I use Gedmo this way and works fine.
I know it's an old Problem, but I had this one too today. Solved it by declaring the tree listener as a service:
https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/symfony2.md#doctrine-extension-listener-services
It's the same for every Gedmo extension such as translatable, sluggable, timestampable...