Symfony 2.8 route annotation failing - symfony

Have looked through SO at various Symfony routing issues but no-one seems to have the same issue as this.
Yesterday, routing worked without issue.
Today I am getting errors regarding values being required for arguments with defaults set
This is an example route that is causing me a problem
#Route("/summary/{staffId}", name="task_instance_summary", requirements={"staffId":"\d+"},defaults={"staffId":"0"})
The method definition:
public function summaryAction(Request $request, $staffId)
and of course the error:
"Controller "PlanXL\TaskBundle\Controller\InstanceController::summaryAction()" requires that you provide a value for the "$staffId" argument (because there is no default value or because there is a non optional argument after this one).")
Debug output:
[router] Route "task_instance_summary"
Name task_instance_summary
Path /task/instance/summary/{staffId}
Path Regex #^/task/instance/summary(?:/(?P\d+))?$#s
Host ANY
Host Regex
Scheme ANY
Method ANY
Class Symfony\Component\Routing\Route
Defaults _controller: PlanXLTaskBundle:Instance:summary
staffId: 0
Requirements staffId: \d+
Options compiler_class: Symfony\Component\Routing\RouteCompiler
I have already cleared the cache (even though I am working on dev) but I can't see why I am getting an error. The router can obviously see the default value when I run the debug so why not when called through my application?

Try it;
public function summaryAction(Request $request, $staffId = 0)

Related

Symfony 3.4. Not any route is working - No route found for "GET /

My Symfony 3.4 project does not recognize any route anymore. Debugging routes in terminal (php bin/console debug:router) does show all the routes but app_dev.php keeps giving error messages. Routing is enabled and set correct in routing.yml file.
Clearing cache also did not work.
mail_chimp:
resource: "#MailChimpBundle/Controller/"
type: annotation
prefix: /
/**
* #Route("/klanten/lijst")
*/
public function klantenLijstAction() {
return;
}
screenshot
Thanks.
> the routing tries to match routes one by one in the order of their definitions; whenever one matches, work is done.
In the routes-list image, you look to have three (maybe more) routes to answer the URL '/'. Which single one should run a controller action?
You should probably set prefixes for the URLs that aren't the index route.

Symfony4 - Casting env variable issue

apparently, Symfony cast env variable is not working on symfony 4.0.
I have this configuration:
cache:
session:
enabled: "%env(bool:SESSION_CACHE_ENABLED)%"
But I get this error:
Invalid type for path "cache.session.enabled". Expected boolean, but got string.
What is my problem? I'm using symfony version 4.0
Thanks
EDIT
Probably, it is a problem of the plugins. That's what I think: Symfony 4 is now based on .env config variable, that are STRING as default; to handle this, S4 is able to use "casting" env var
'%env(bool:myvar)%'
And it works; if you do a var_dump within a controller, you can see that the variable is a boolean.
Most of current plugins, also those who supports S4, are not able to use this syntax, so, they see that variable as STRING, and the validator return an error.
These plugins should be fixed or, actually, I can duplicate the .yml file on each package/{env}/ dir with separated configuration ( the situation that I would avoid with .env )
The problem is fixed in symfony 4.1 https://github.com/symfony/symfony/issues/22151

symfony4 migrate autowire to true - get error message

I am migrating from symofony 2.7 to symfony 4.0. With success I migrated one bundle. Now I am migrating the second bundle and the error message is coming up. I don't get at all what symfony 4.0 wants from me.
If I turn on autowire: true this error message is coming up.
Cannot autowire service "App\Kernel": argument "$environment" of method "Symfony\Component\HttpKernel\Kernel::__construct()" must have a type-hint or be given a value explicitly.
Can somebody help me?
If I turn it off, no message is coming up.
Update
I registered my bundle only in bundles.php
App\Backend\AccountBundle\BackendAccountBundle::class => ['all' => true],
Usually the Kernel is added to the Service Container as a so called synthetic service, meaning it's not generated by the DI-container from configuration. Rather the id is set and then the previously configured service is just added to the container. It seems rather odd that your bundle's container wants to create a new kernel here. So I would check where and how you want to access the kernel in any of the bundle's services and whether you actually want to pass in the kernel and not something else. If you do you might want to check the Service Container-documentation on synthetic services.
As to the error itself. Symfony's autowiring often falls flat when you have services that require parameters like with the Kernel:
public function __construct(string $environment, bool $debug) {...}
In these cases you have to either have a parameter defined in your services.yaml that matches the name of the parameter:
# config/services.yaml
parameters:
environment: prod
debug: false
or you have to tell the configuration which parameters you want to have in those places.
App\Kernel:
$environment: prod
$debug: false
This will tell the autowiring that only the 2 arguments named environment and debug should be overwritten with the values you provide, but the rest is done via autowiring. This way you can skip the arguments: part of the definition and you can also skip all arguments you know are correctly set via autowiring.
For example if you have a service like this:
class MyService {
public function __construct(OtherServce $service, string $someParameter) {}
}
# config/services.yaml
services:
_defaults:
autowiring: true
MyService:
$someParameter: 'someValue'
This is the same as explicitly writing:
services:
MyService:
class: MyService
arguments:
- '#OtherServce'
- 'someValue'

FOSRestBundle: PATCH methods not working (501 - Not implemented)

I'm using FOSUserBundle (the same problem on 0.12.0 and current dev-master) with Symfony 2.3.
I have problem with PATCH methods.
Simple example:
public function patchAction($slug)
{
[...]
return $view;
}
I see proper route was generated in php app/console router:debug:
api_patch_user PATCH ANY ANY /api/users/{slug}.{_format}
But when I am making request, I'm getting:
501 - Not implemented
When I change only method name to i.e. DELETE everything is working. So the problem is only with PATCH type requests.

Compilation failed: unmatched parentheses in appstageUrlMatcher.php

On my production system i get an error in the symfony router:
Warning: preg_match() [function.preg-match]: Compilation
failed: unmatched parentheses at offset 60 in
/mypath/app/cache/prod/appprodUrlMatcher.php line 205
Whereas on the local machine and on another server it works fine.
I digged in the cache and the pattern for the route is different:
Working on my dev server:
#^/hotels/(?<groupId>[^/\\-]+)\\-(?<groupName>[^\\-]+)$#s
Not working on production:
#^/hotels(?:/(?<groupId>[^/\\-]+)(?:\\-(?<groupName>[^\\-]+))?)?)?$#s
the route is:
hotel:
pattern: /hotels/{groupId}-{groupName}
defaults: { _controller: "MyBundle:Hotel:hotel", requirements:{ groupName: "[a-zA-Z1-9\+\/]+" } }
I read some issues on github that similar errors are possible when using an old PCRE.
https://github.com/symfony/symfony/issues/4093
Mine seems new enough thou: PHP 5.3.6 with PCRE Version 8.11.
I am on Solaris.
The patterns are generated by symfony, right? So, why are the patterns different?
And after all why doesnt it work? Has somebody any clue?
This was not a symfony issue but rather a bug in the PHP 5.3.6 version on this Solaris machine.
The constant INF returned float(0) which blew up the routing.
See more here: php INF has value zero

Resources