Trying out the fosUserBundle module. Nowhere in the documentation I can see the meaning of the tilda ~ while configuring fosUserBundle in Symfony.
app/config/config.yml
framework:
translator: ~
A tidle means null in Yaml (see http://symfony.com/doc/current/components/yaml/yaml_format#nulls).
In Symfony, setting an option that can be enabled to null or true means: Enable it with the default options. This means:
framework:
translator: ~
# or
# translator: true
# is a shortcut for
framework:
translator:
enabled: true
In this particular case, the full framework.translation config is:
framework:
translator:
enabled: false
fallbacks: [en]
logging: "%kernel.debug%"
paths: []
So framework.translator: ~ in this case means enabling translation features of Symfony using en as fallback locale, the %kernel.debug% parameter to indicate if logging should be enabled and no paths configured.
Related
Im creating a config in my symfony 3.4 that allow to access multiple database
I have set default to automapping to 1 database
then i would like to create 1 orm setting to only 1 entity, not 1 bundle, is that possible?
currently it look like this:
connectionName:
connection: connName
mappings:
IpSaBundle: ~
naming_strategy: doctrine.orm.naming_strategy.underscore
When I did the above, I got an error, because in that bundle I have another entity that belongs to default orm setting
Yes it's possible.
Check here: https://symfony.com/doc/3.4/reference/configuration/doctrine.html#mapping-entities-outside-of-a-bundle
# ...
orm:
# ...
mappings:
# ...
SomeEntityNamespace:
type: annotation
dir: '%kernel.project_dir%/src/Entity'
is_bundle: false
prefix: App\Entity
alias: App
Hi I would like to version my API. So I would like t prefix my roote with a version. like that?
# config/routes/annotations.yaml
controllers:
resource: ../../src/Controller/
type: annotation
prefix:
name: '{version}'
It works bit I would like to add a requirement to check the version.
Like:
requirements:
version: v1|v2
I don't find any documentation talking about that. Is there a good way to do it?
In the FOSRestBundle there is a complete chapter about versioning.
https://symfony.com/doc/master/bundles/FOSRestBundle/versioning.html
The FOSBundle has an option for versioning.
#app/config/config.yml
fos_rest:
versioning:
enabled: true
resolvers:
query: true # Query parameter: /users?version=v1
custom_header: true # X-Accept-Version header
media_type: # Accept header
enabled: true
regex: '/(v|version)=(?P<version>[0-9\.]+)/'
I have multiple managers and configuration of one of them is like this
doctrine:
orm:
entity_managers:
support:
connection: support
mappings:
APIBundle: ~
But there are tens of entities in APIBundle and I need only some of them in this manager. What a correct configuration should be in such case?
I can't find anything in the doctrine documentation which match with what you're asking.
But by reading the mapping part, we can imagine a little trick to pass through that :
Define your entities in two distinct folders :
APIBundle
|
--- Em1Entity
|
--- SupportEntity
Then in your config, specify the dir configuration :
doctrine:
orm:
entity_managers:
support:
connection: support
mappings:
Support:
mapping: true
type: ~
dir: APIBundle\SupportEntity
alias: ~
prefix: ~
is_bundle: ~
It's just a guess, I didn't personnaly tested this hack.
In Symfony's cookbook, there is a page entitled How to Simulate Authentication with a Token in a Functional Test. In it, it is said that:
The technique described in How to Simulate HTTP Authentication in a Functional Test is cleaner and therefore the preferred way.
Also, on the page that the quotation above links to, the documentation says:
The trick is to include the http_basic key in your firewall, along with the form_login key
This tells me that it is all right to have the form_login key, along with the http_basic key, and somehow http_basic should take precedence.
Here is my config_test.yml configuration file:
imports:
- { resource: config_dev.yml }
framework:
test: ~
session:
storage_id: session.storage.mock_file
profiler:
collect: false
web_profiler:
toolbar: false
intercept_redirects: false
swiftmailer:
disable_delivery: true
liip_functional_test:
cache_sqlite_db: true
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.db
security:
firewalls:
default:
http_basic: ~
However, when I open my application in the test environment, I still get redirected to the login_form URL.
Why isn't setting the http_basic acting like the documentation says it should, namely it getting activated rather than form_login?
As commented here, having the code I pasted in my original question works just fine. The reason it is loading the login form is because I am not logging in via http_basic. In other words, when I have both form_login and http_basic enabled, I can login both by providing the PHP_AUTH_USER/PHP_AUTH_PASSWORD, and by logging in through the form. In effect, I don't need different security_*.yml files; I just need to add http_basic: ~ to the already-defined firewall.
Just split security.yml to security_test.yml and security_prod.yml.
In security_test.yml put default security configuration (as delivered with Symfony) or other one, which doesn't have firewall restrictions.
Create a specific config file for test environment, like config_test.yml with
imports:
- { resource: config.yml }
- { resource: security_test.yml }
note here config.yml itself doesn't have any security imports, because You will receive some Exception about overriding security directive or smth.
Create a separate config_prod.yml with
imports:
- { resource: config.yml }
- { resource: security_prod.yml }
Now You have separate security for test and prod environments.
If Your environment naming is good, then Kernel will pick config_test.yml only when tests are executed. For development environment Your should use config_dev.yml instead of config_test.yml
I am using JMSPaymentCoreBundle and JMSPaymentPaypalBundle.
It worked well before,but now I have to change my config.yml for new Bundle(FOSMessageBundle)
I have to stop using 'auto_mapping' and use 'entity_managers' instead
doctrine:
dbal:
orm:
auto_generate_proxy_classes: %kernel.debug%
# auto_mapping: true
entity_managers:
FOSUserBundle: ~
FOSMessageBundle: ~
However after this changes .
The service "payment.plugin_controller" has a dependency on a non-existent service "doctrine.orm.default_entity_manager"
this error happens.
I think changes in config.yml causes this trouble.
How can I solve this problem?
According to the error, you need to define an entity manager named default. In your case, the overall syntax is just wrong, see my example.
In config.yml:
doctrine:
orm:
entity_managers:
default: # that's the name of the entity manager
connection: default # you need to define the default connection
mappings:
FOSUserBundle: ~
FOSMessageBundle: ~
I'd advise you to read the documentations about "Databases and Doctrine" and "How to work with Multiple Entity Managers and Connections"