Symfony InvalidArgumentException when running app/console - php

I have been developing a website using Symfony. Everything was good until earlier today I was adding some Fixtures using the DoctrineFixturesBundle and ran the "app/console" command. I received the following error:
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
Symfony\\Bundle\\AsseticBundle\\EventListener\\RequestListener
is not a valid class name for the "assetic.request_listener" service.
I tried undoing the changes I made to the fixtures to find my mistake and it didn't change. In my infinite wisdom, I decided to try updating my vendors by running "composer update" and it didn't work.
Also, when I run my site in a browser, I get the same error.
I don't know what's going on. Someone please help, any help appreciated.

For those who stop by :)
In most cases problem is with class name which has leading \ in front of class name. More info more info

Just wanted to let you all know how I fixed it. It's not the most elegant solution but it worked. I downloaded a new company of Symfony, copied over all my bundles, my whole config directory,my composer.json, and my AppKernel.php. It got rid of all my errors, even some cache issues I was getting.

For the record, this error is always related to one thing and that's the name of the class is wrong. Either you are specifying the path the class incorrectly, or you spelled the name wrong.
For instance, I got stumped on this one because I accidentally add .php to the class name.

Reformat on .xml files gave me same issue. Exactly, reformat the files in a directory instead of a single file, working with PhpStorm.
#abarisone:
Problem was in a services.xml file. PhpStorm "reformat" transform (example):
<parameter key="xxx">Petrus\xx\xx\XHRCoreExceptionListener</parameter>
to:
<parameter key="xxx">
Petrus\xx\xx\XHRCoreExceptionListener
</parameter>
Was hard to find and easy to correct, manually with help of "Local history" Phpstorm's feature.

Related

No definition found for function in vendor vscode

My vscode does not see the definition of functions in vendor library.
I don't know if it has anything to do with gitignore, where I have put vendor, but I would like to find a solution that lets me keep it in gitignore, but allows me to search through in the work environment.
Because it does not see the definition, it gets underlined as a problem and I can not take a peak into what I am working here with.
It does not affect the resulting outcome, it is problem while using the vscode.
Can you please help?
I tried creating config.json in the project root folder .vscode saying:
{
"search.useIgnoreFiles": false
}
It didn't do anything.
Thank you for looking into it.
Add the direcory path into intelephense configuration:
#ext:bmewburn.vscode-intelephense-client
Like here into include path list:

Symfony2 cached controller won't update

I'm quite new to PHP and have received some Symfony2 project to maintain. Now I've found out that when I update foo.html.twig, that page will not change until I perform the command console c:c -e prod. Until then the shown page will be foo.html_.twig (hence the underscore).
The problem is that I've changed a controller, let's say BarController.php, but the new added value in that controller does not work in the .twig file, I think because the BarController_.php did not get updated with the clear cache command. What did I do wrong here?
Edit:
As Nate says it's not Symfony that caches controllers, but at least I see that BarController_.php is much older than BarController.php, and it's the one with the underscore that does not have the newly added value.
Edit 2:
BarController.php and BarController_.php both reside in the same folder.
Sometimes you need to clear cache by your own. You can try
rm -rf app/cache/prod/*
and don't forget to change rights.
Apparently I was completely looking at the wrong places. It had nothing to do with caching at all.
Those underscored files appeared because of my hacky way of 'version control', which meant I copied a file I was going to edit, put '.old' after the filename so I had a backup. For some reason there was created an underscored file for these things.
The problem of not being able to read the getter's value was just a bug in my code.

PhpStorm won't resolve includes using constants

This used to work, but it stopped working recently. I don't think anything changed in my settings, but I have poured over them for a couple hours now just to make sure. I have checked all over google and SO too. Please pay attention to the details before claiming "this was answered over here..." Thanks. :)
Assumptions and Requirements
Assume we have two files:
<project_root>/index.php
<project_root>/folder/file.php
Assume our project root is /home/me/project.
We want to include file.php from index.php. We expect PhpStorm to be able to resolve the file path and allow us to do nifty IDE things like "Go To Declaration."
What works
require 'folder/file.php';
require '/home/me/project/folder/file.php';
$root = '/home/me/project/';
require $root.'folder/file.php';
What No Longer Works
define('ROOT_DIR', "/home/me/project/");
require ROOT_DIR.'folder/file.php';
PhpStorm does recognize the value of ROOT_DIR when I mouseover, but it highlights home and says something like: Path '"/home/me...folder/file.php' not found
Why Use a Constant Anyway?
To keep this simple, I've left out details that are not necessary to illustrate the problem. The primary thing I'd like to address is why this used to work but no longer does, and/or how can I make it work again.
Sorry, can't help. What are you really trying to do?
Here are the details I left out. If we can't solve the primary issue, perhaps we can find a good work around.
I'm working with an existing codebase. Most files require a config.php file that defines root_dir() for getting the web/project root. PhpStorm wasn't resolving those paths (understandably so), so I created a constant to takes it's place. That makes more sense anyway.
In today's battle, I discovered that you can do this:
/** #define "root_dir()" "/home/me/project/" */
// or
/** #define "ROOT_DIR" "/home/me/project/" */
If you put that anywhere in the file then PhpStorm is able to resolve all the includes/requires in that file. BUT, it only works in that file, even if you try to include/require it in another file. You'd have to do this to EVERY file to get it working everywhere. Nope. Nuh-uh. No thank you. I need to reference the absolute path to the project/web root in a way that PhpStorm will recognize across the whole project.
#LazyOne answered this in the comments. This is a bug in the latest release, and it's being tracked here: https://youtrack.jetbrains.com/issue/WI-31754
Until this gets patched I've created this work around:
Using Keyboard Maestro, I created a hotkey that will paste the #define comment at the top of the file and return the cursor to its original position. Download the macro here. Import that and edit the text.
Edit: You may actually need to edit the file in a regular text editor. One of the file paths may need to be changed to work on your system.
Note: I'm using a modified version of the Mac Eclipse keyboard layout in PHPStorm. I'm not sure that will matter.
Also, be aware that many of your "changed files" will simply have this mapping at the top of the file, and this mapping may not be correct for you teammates. I'm simply excluding those changes from my commits.

php artisan [BadMethodCallException]

First of all I have just begun to tinker with Laravel 5 and php artisan, so don't judge to harsh please ;)
To get rid of ./public/index.php in the website path I did the following:
moved all the files in root/page_local/ folder;
moved files from public folder to root/page/;
modified the root/page_local/index.php file accordingly.
So the laravel works as it should now, but php-artisan is not. Every command that I try to run returns the same error:
[BadMethodCallException]
Method patter does not exist.
But I remember creating a Controller before and it worked, I tried multiple functions (--version, list, create::controller).
Even when I run composer update it errors when it tries to run php artisan clear-compiled.
I still managed to update the composer by running composer update --no-scripts
Please help me out on this one because I couldn't find any information regarding this issue on Laravel website and google. If you will need me to provide any of my code, let me know what you need and I will do so.
Thanks in advance.
Search your code for patter string, my guess is that you have a typo somewhere and the method is called pattern so use that instead. There is no patter method anywhere in Laravel code.

Error with propel-generate-crud in Symfony 1.0

When I try to generate a CRUD test for a new project I am getting a PHP Warning and a Fatal Error.
The errors relate to files that it cannot find, however, I have checked and the files are definitely there.
The error text is 'require_once(lib/model/map/QuestionMapBuilder.php): failed to open stream: No such file or directory in c:\webroot\askeet\lib\model\om\BaseQuestionPeer.php on line 547'
What details of my project should I check?
I think it's a problem with your include path.
Check it, the require_once() call is looking for lib/model/map/QuestionMapBuilder.php
But your include_path is C:\webroot\askeet\lib
Which, when resolved together into a full path, would look like this
C:\webroot\askeet\lib\lib\model\map\QuestionMapBuilder.php
So, I think your solution is to add C:\webroot\askeet to your include path.
You are generating crud for the Question model class but it doesn't seem to exist. Documentation on using the crud generator
First you must use the schema.yml file to define your database, and run
./symfony propel:build-model
to generate your model files. (this will generate lib\model\map\QuestionMapBuilder.php)
I finally tracked down the issue. In my PHP.ini files, they were setup wit the default UNIX file path settings.
Weirdly nothing had ever been broken by this incorrect configuration. Plus, everything in Symfony had worked up until now.
I have switched to Windows style file_path and all is well again.
Thanks for all the answers!

Categories