FOSUser on Symfony 3.3 - symfony

This is similar to Symfony3 You have requested a non-existent service "validator.builder", while add FOSUserBundle, on vanilla Symfon3.3 instead of microkernel (in case that makes differences).
Problem:
I have a problem trying to set up FOSUser (v.2) on a Symfony 3.3:
[Symfony\Component\DependencyInjection\Exception\AutowiringFailedException]
Cannot autowire service "validator.builder": argument "$node" of method
"Symfony\Component\Config\Definition\Builder\ValidationBuilder::__construct()"
references class Symfony\Component\Config\Definition\Builder\NodeDefinition"
but no such service exists.
Browsing through online API:
ValidationBuilder is marked up to the 3.2 branch, although exists in github
NodeDefinition is also marked up to v3.2, although exists in github
Does that mean that their documentation is not up to date with the master 3.3?
Or not maintained anymore?
Context:
Following the official documentation, I first faced these problems:
mailer_user cannot be null ; solved by editing parameters.yml:
parameters:
mailer_user: "me#example.com"
non-existent-service-validator-builder ; solved by declaring service validator.builder
non existent parameter kernel secret ; solved by duplicating a line in parameters.yml:
parameters:
secret: <-generated-upon-install->
kernel.secret: <-duplicated-line->
I suppose there is a nice and clever way to get out of this problem, if anyone faced it yet?

Solved! In service.yml, do not declare service as
validator.builder:
class: Symfony\Component\Config\Definition\Builder\ValidationBuilder
But this way:
Symfony\Component\Config\Definition\Builder\ValidationBuilder:
autowire: true
Once again, the official documentation had the answer!

Related

You must either configure a "public_key" or a "secret_key".[Symfony]

I tried to setup a login authentication using LexikJWTAuthentication, I already generated the necessary keys
Here is how its called
config/packages/lexik_jwt_authentication.yaml
lexik_jwt_authentication:
secret_key:'%kernel.project_dir%/config/jwt/private.pem' # required for token creation
public_key:'%kernel.project_dir%/config/jwt/public.pem' # required for token verification
pass_phrase:'mafdhklkjkn234kas' # required for token creation, usage of an environment variable is recommended
token_ttl: 3600
Here is return when I try to login, I used postman
Here is the var_dump of config in vendor/lexik/jwt-authentication-bundle/DependencyInjection/LexikJWTAuthenticationExtension.php
bundles.php
I got the same error and it was from "lexik_jwt_authentication.yaml" was not in my repo, after adding it, the problem was fixed.
I pass the same error when passing a production, and honestly it's a bit silly. Cannot find keys because they are not loaded in configuration, ie dependency "nelmio/cors-bundle" was installed as dev.
By reinstalling it
composer require nelmio/cors-bundle
everything works again.
My apologies for my english

Doctrine 2.5: Unrecognized field (but only in Symfony's prod mode)

So I seem to be plagued by issues that only affect production mode in Symfony and not developer mode. This time, I have a ManyToOne association and I'm trying to fetch only the entities which do not have an association (i.e. they have a NULL value in the database). This works exactly as I'd expect in dev move, but in prod mode, Doctrine throws an "unrecognized field" exception... for a field which absolutely does exist.
Here's the relevant part of the entity in question (Page.php):
/**
* #ORM\ManyToOne(targetEntity="Project", inversedBy="pages")
* #ORM\JoinColumn(name="project_id", referencedColumnName="ID")
*/
protected $project;
And here is the relevant line from the controller (PageController.php):
$pages = $this->getDoctrine()->getRepository('JCScopingBundle:Page')->findBy(['project' => null]);
Again, this works perfectly using app_dev.php (i.e. dev mode), but using app.php (i.e. prod mode) I keep getting the "unrecognized field" exception. What gives?
Update: I added a "weight" integer field to the same entity and that field is not recognized in prod mode either. This means I can't use prod mode, which means I can't upload my changes to the remote server. Really in a pickle here...
Well, low and behold, restarting the Apache service resolved the issue. Apparently that's the only way to truly clear the APCu metadata cache. I was inspired to try this based on this question/answer: Doctrine mapped field is not working
In my case I forgot to restart 'memcached' service.
Check metadata_cache_driver type. In my case:
doctrine:
orm:
metadata_cache_driver:
type: memcached
host: localhost
port: 11211
instance_class: Memcached
Because previous metadata was cached, after applying migration, doctrine used that old cached metadata, without knowing about added new field.

Using Symfony expression in 3rd party bundle configuration

I am trying to configure HWIOAuth bundle to use dynamic client id. I have a service that can figure out what variable value to use depending on some request conditions.
Here's an expression in my HWI configuration, but can't seem to get it work:
hwi_oauth:
firewall_names:
- main
resource_owners:
auth:
client_id: "#=service('host.configmgr').GetClientIdParameter()"
client_secret: '%client_secret%'
The issue us with #=service('host.configmgr').GetClientIdParameter(). Can that even execute evaluate? The service is properly executes an used by another class somewhere else with success.
The %client_secret% parameter replacement works fine.
For more context, this part of the configuration lives in a dedicated file that is included in config.yml via { resource: hwiconfig.yml }
After some research looks like expressions are only supported for service definitions. This functionality is not supported for configurations outside services like the HWI bundle config.

Payum Paypal Rest config_path

I am trying to implement paypal-rest payment with the payum bundle in symfony (3.1.4).
I need to get PayPal Plus running in my Symfony App.
Therefore I read this article
https://github.com/Payum/Payum/blob/master/docs/paypal/rest/get-it-started.md
Now - I can't figure out what the 'config_path' parameter is ment to be set to and what exactly has to be provides at this config_path.
Symfony states
'The config_path fields are required.'
My payum config looks like this atm
payum:
security:
token_storage:
AppBundle\Entity\PaymentToken: { doctrine: orm }
storages:
AppBundle\Entity\Payment: { doctrine: orm }
gateways:
paypal_express_payment:
factory: paypal_express_checkout
username: "%ppe_uname%"
password: "%ppe_pw%"
signature: "%ppe_signature%"
sandbox: false
paypal_rest_payment:
factory: paypal_rest
client_id: "%ppr_cid%"
client_secret: "%ppr_sec%"
sandbox: true
The paypal_express_payment part works fine.
If I add just a random config-path like 'my_config.txt' Symfony states
Request GetHumanStatus{model: ArrayObject} is not supported. Make sure the gateway supports the requests and there is an action which supports this request (The method returns true). There may be a bug, so look for a related issue on the issue tracker.
So - where and what is the config_path ment to be?
Any help or hints for more documentation that can lead into the right direction is very welcome.
It's meant to be sdk_config.ini from PayPal-PHP-SDK
gateways:
paypal_rest:
factory: paypal_rest
client_id: '%paypal_rest.client_id%'
client_secret: '%paypal_rest.client_secret%'
config_path: '%kernel.root_dir%/config/sdk_config.ini'
UPDATE: I don't think that Doctrine ORM storage is supported by Payum PaypalRest plugin.
PaypalRest\Action\CaptureAction requires the model (Payment) to be inherited from PayPal\Api\Payment and then it uses its create and execute methods for payment capture. I don't think it's a good idea to extend from PayPal\Api\Payment in the Doctrine entity.
I was able to eliminate this error by using Payum\Paypal\Rest\Model\PaymentDetails as a payment and filesystem as a storage:
payum:
storages:
Payum\Paypal\Rest\Model\PaymentDetails:
filesystem:
storage_dir: %kernel.root_dir%/Resources/payments
id_property: idStorage
Try to set it to default value like this:
paypal_rest_payment:
factory: paypal_rest
client_id: "%ppr_cid%"
client_secret: "%ppr_sec%"
sandbox: true
config_path: ~

LogicException: Missing default data in Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector

Getting this exception in Symfony 2.5.5 with Swiftmailer 5.3.0. I'm following the cookbook example exactly. The error is thrown when calling MessageDataCollector#getMessages():
// Check that an e-mail was sent
$this->assertEquals(1, $mailCollector->getMessageCount());
$collectedMessages = $mailCollector->getMessages();
$message = $collectedMessages[0];
The message count assertion is also failing with a value of zero.
As far as I can tell the collector is failing to do any actual collecting in the action. Any ideas?
I encountered the same problem after I applied kriswallsmith's test optimization trick. I could see the result of the mail sending in the web profiler when running the development version, but couldn't get the data in the testing environment.
After applying Kris' trick I noticed that the swiftmailer.mailer.default.plugin.messagelogger service was not registered with the container during the test, so the collect() method of the MessageDataCollector class did not log the data for the mail sending. This is why it wasn't possible to retrieve information from the swiftmailer collector.
The solution is either not to overrride the initializeContainer() method in AppKernel.php or to override it, but making sure messagelogger service is available for test cases that send mails.
#codeBetyar is right - problem occurs when swiftmailer.mailer.default.plugin.messagelogger is not registered in container.
But instead of getting rid of the optimization trick - you just need to update swiftmailer configuration for test environment
swiftmailer:
logging: true
The thing is logging config value by default equals to kernel.debug (https://github.com/symfony/swiftmailer-bundle/blob/master/DependencyInjection/Configuration.php#L121) which (thanks to the trick) is true for the first test request, and false - for all following requests.
Above config forces logger being registered.
In my case I had multiple mailers in the config.yml file and the same problem was due to a missing parameter in the getMessages() call.
My config.yml file:
swiftmailer:
default_mailer: default_mailer
mailers:
default_mailer:
# some configuration
another_mailer:
# some configuration
The correct call was:
$mailCollector = $this->client->getProfile()->getCollector('swiftmailer');
$collectedMessages = $mailCollector->getMessages('default_mailer'); // please note the 'default_mailer' argument
$messagesCount = $mailCollector->getMessageCount('default_mailer')
My problem was that apparently if there are no messages to retrieve (or perhaps no swiftmailer instantiation in the code being tested?), the call to getMessages() returns this obtuse error. So I bypassed the problem by testing for getMessageCount() first.

Resources