I have mapped my entity with yaml and I'm using the assert to add some constraint for certain field.
So I follow the documentation and put my validation in this file:
# src/AppBundle/Resources/config/validation.yml
it works...
But I want to separate my validation. I need one file for one entity.
So I did it that way:
# src/AppBundle/Resources/config/validation/DeliveryAddress
# src/AppBundle/Resources/config/validation/BillingAddress
But it does not seem to work that way.
Here one of my file:
# src/AppBundle/Resources/config/validation/DeliveryAddress.yml
AppBundle\Entity\DeliveryAddress:
properties:
address:
- NotBlank: ~
zipCode:
- NotBlank: ~
- Regex:
pattern: '/^[0-9]{5}$/'
match: false
message: 'Le code postal que vous avez saisi n’est pas valide'
town:
- NotBlank: ~
firstName:
- NotBlank: ~
lastName:
- NotBlank: ~
How can I do that?
This works natively since symfony 2.7
https://github.com/symfony/symfony/pull/13855
The problem was because match was to false
zipCode:
- NotBlank: ~
- Regex:
pattern: '/^[0-9]{5}$/'
match: false
Related
I have a query with hardcoded dates used in the parameters section.Instead I want to pass them as environment variables.Any suggestions on how to parameterize the QueryString parameter?
service: service-name
frameworkVersion: '2'
provider:
name: aws
runtime: go1.x
lambdaHashingVersion: 20201221
stage: ${opt:stage, self:custom.defaultStage}
region: us-east-1
tags: ${self:custom.tagsObject}
logRetentionInDays: 1
timeout: 10
deploymentBucket: lambda-repository
memorySize: 128
tracing:
lambda: true
plugins:
- serverless-step-functions
configValidationMode: error
stepFunctions:
stateMachines:
callAthena:
name: datasorting-dev
type: STANDARD
role: ${self:custom.datasorting.${self:provider.stage}.iam}
definition:
Comment: "Data Refersh"
StartAt: Refresh Data
States:
Refresh Data:
Type: Task
Resource: arn:aws:states:::athena:startQueryExecution.sync
Parameters:
QueryString: >-
ALTER TABLE table.raw_data ADD IF NOT EXISTS
PARTITION (YEAR=2021, MONTH=02, DAY=15, hour=00)
WorkGroup: primary
ResultConfiguration:
OutputLocation: s3://output/location
End: true
you can replace any value in your serverless.yml enclosed in ${} brackets,
Serverless Framework Guide to Variables:
https://www.serverless.com/framework/docs/providers/aws/guide/variables/
for example, you can create a custom: section looking for environment variables, and if they are not present, you can have default values:
service: service-name
frameworkVersion: '2'
custom:
year: ${env:YEAR, 'default-year'}
month: ${env:MONTH, 'default-month'}
day: ${env:DAY, 'default-day'}
hour: ${env:HOUR, 'default-hour'}
stepFunctions:
stateMachines:
callAthena:
...
Parameters:
QueryString: >-
ALTER TABLE table.raw_data ADD IF NOT EXISTS
PARTITION (YEAR=${self:custom.year}, MONTH=${self:custom.month}, DAY=${self:custom.day}, hour=${self:custom.hour})
...
I am trying to write a HOT template for Openstack volume, and need to have the volume_type as a parameter. I also need to support a case when the parameter is not given, and default to the Cinder default volume type.
First attempt was to pass null to the volume_type , hoping it would give the default volume type. However no matter what I pass (null, ~, default, "" ) , seems there is no way to get the default volume type.
type: OS::Cinder::Volume
properties:
name: test
size: 1
volume_type: { if: ["voltype_given" , {get_param:[typename]} , null] }
Is there any way to get the default volume type , when you have the "volume_type" property defined?
Alternatively, is there any way to have the "volume_type" property itself behind a conditional? I tried several ways, but no luck. Something like:
type: OS::Cinder::Volume
properties:
if: ["voltype_given" , [ volume_type: {get_param:[typename]} ] , ""]
name: test
size: 1
ERROR: TypeError: : resources.kk-test-vol: : 'If' object is not iterable
Could you do something like this?
---
parameters:
typename:
type: string
conditions:
use_default_type: {equals: [{get_param: typename}, '']}
resources:
MyVolumeWithDefault:
condition: use_default_type
type: OS::Cinder::Volume
properties:
name: test
size: 1
MyVolumeWithExplicit:
condition: {not: use_default_type}
type: OS::Cinder::Volume
properties:
name: test
size: 1
volume_type: {get_param: typename}
# e.g. if you need to refer to the volume from another resource
MyVolumeAttachment:
type: OS::Cinder::VolumeAttachment
properties:
instance_uid: some-instance-uuid
volume_id:
if:
- use_default_type
- get_resource: MyVolumeWithDefault
- get_resource: MyVolumeWithExplicit
I'm trying to replace accent mark so I can search properly at my rss:
TVDB name: Cómo vender drogas online (a toda pastilla)
RSS title name: Como vender drogas online (a toda pastilla)
and I want to match this so it can be replaced, but isn't working
manipulate:
- title:
replace:
regexp: 'á'
format: 'a'
- title:
replace:
regexp: 'é'
format: 'e'
- title:
replace:
regexp: 'í'
format: 'i'
- title:
replace:
regexp: 'ó'
format: 'o'
- title:
replace:
regexp: 'ú'
format: 'u'
My config.yml:
tv:
thetvdb_lookup:
language: es
configure_series:
from:
thetvdb_list:
username: '{? TvDB.username ?}'
account_id: '{? TvDB.account_id ?}'
api_key: '{? TvDB.api_key ?}'
strip_dates: yes
set:
path: {? path.externaldrive ?}
I want to replace accent mark like this:
á = a
So I can search properly
I have this dictionary:
MyClouds:
Devwatt:
ExternalNetwork: PublicRSC
Flavors:
- Flavor_1cpu_1gb: Devwatt_1cpu_1gb
- Flavor_1cpu_2gb: Devwatt_1cpu_2gb
- Flavor_1cpu_4gb: Devwatt_1cpu_4gb
Fuga:
ExternalNetwork: Internet
Flavors:
- Flavor_1cpu_1gb: Fuga_1cpu_1gb
- Flavor_1cpu_2gb: Fuga_1cpu_2gb
- Flavor_1cpu_4gb: Fuga_1cpu_4gb
- Flavor_1cpu_8gb: Fuga_1cpu_8gb
I have to migrate from one Openstack cloud to another, and one of my problem is to find correspondances between flavors.
I want to find which flavor (key) has the value "Devwatt_1cpu_2gb" in "Devwatt", and after get the value of the same key in "Fuga"
I tried a lot of solution (with-dict, when, jija filters, json_query) but I can't find a way to do that.
Please, may you help me ?
Inspired by Eric's answer and this usefull resource, I, finally, used this solution:
I changed a little bit my data structure and put it in a file matrice.yml:
MyClouds:
Devwatt:
ExternalNetwork: PublicRSC
Flavors:
- name: Flavor_1cpu_1gb
FlavorName: Devwatt_1cpu_1gb
- name: Flavor_2cpu_1gb
FlavorName: Devwatt_2cpu_1gb
- name: Flavor_1cpu_2gb
FlavorName: Devwatt_1cpu_2gb
Fuga:
ExternalNetwork: Internet
Flavors:
- name: Flavor_1cpu_1gb
FlavorName: Fuga_1cpu_1gb
- name: Flavor_2cpu_1gb
FlavorName: Fuga_2cpu_1gb
- name: Flavor_1cpu_2gb
FlavorName: Fuga_1cpu_2gb
then I used these filters in my playbook:
---
- hosts: localhost
connection: local
gather_facts: false
vars:
SourceFlavorName: "Devwatt_2cpu_1gb"
tasks:
- name: get flavors matrice
include_vars:
file: matrice.yml
- name: Get generic name from flavor name of source cloud
debug:
msg: "{{ MyClouds.Devwatt.Flavors | selectattr('FlavorName','search','^'+ SourceFlavorName +'$') |map (attribute='name') | list }}"
register: result
- name: Get flavor name for target cloud from generic name
debug:
msg: "{{ MyClouds.Fuga.Flavors | selectattr('name','search','^'+ result.msg[0] +'$') |map (attribute='FlavorName') | list }}"
With this solution I can have any number of clouds and find easily correspondances between flavor from one source cloud to target cloud.
Why not using a simple mapping using a dict where keys are "Devwatt" flavors and values are "Fuga" flavors, like this :
---
- hosts: localhost
vars:
FlavorsMapping:
Devwatt_1cpu_1gb: Fuga_1cpu_1gb
Devwatt_1cpu_2gb: Fuga_1cpu_2gb
Devwatt_1cpu_4gb: Fuga_1cpu_4gb
tasks:
- debug:
var: FlavorsMapping['Devwatt_1cpu_2gb']
Receiving the following error message when trying to run my project.
Fatal error: Uncaught exception 'Doctrine\ODM\PHPCR\Translation\MissingTranslationException' with message 'The locale 'en' is not present in the list of available locales' in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
Doctrine\ODM\PHPCR\Translation\MissingTranslationException: The locale 'en' is not present in the list of available locales in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
And the following stack trace:
# Time Memory Function Location
1 0.0040 240752 {main}( ) ../app.php:0
2 0.0299 643576 Symfony\Component\HttpKernel\HttpCache\HttpCache->handle( ) ../app.php:20
3 0.0309 657488 Symfony\Component\HttpKernel\HttpCache\HttpCache->lookup( ) ../HttpCache.php:193
4 0.0316 659008 Symfony\Component\HttpKernel\HttpCache\HttpCache->fetch( ) ../HttpCache.php:329
5 0.0317 665184 Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache->forward( ) ../HttpCache.php:429
6 0.4876 9740256 Symfony\Component\HttpKernel\HttpCache\HttpCache->forward( ) ../HttpCache.php:60
7 0.4877 9742120 Symfony\Component\HttpKernel\Kernel->handle( ) ../HttpCache.php:466
8 0.4957 9838264 Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle( ) ../Kernel.php:187
That is all what I am getting as error report.
What could be going wrong?
edit:
Here is a part my config.yml;
framework:
#esi: ~
translator: { fallback: en }
secret: %secret%
router: { resource: "%kernel.root_dir%/config/routing.yml" }
form: true
csrf_protection: true
templating: { engines: ['twig'] } #assets_version: SomeVersionScheme
default_locale: %locale%
session: ~
edit 2:
After configuring config.yml;
Warning: filemtime(): stat failed for /var/www/sources/piccolo-standard/app/config/config.yml in /var/www/sources/piccolo-standard/vendor/symfony/symfony/src/Symfony/Component/Config/Resource/FileResource.php on line 68
Fatal error: Uncaught exception 'Doctrine\ODM\PHPCR\Translation\MissingTranslationException' with message 'The locale 'en' is not present in the list of available locales' in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
Doctrine\ODM\PHPCR\Translation\MissingTranslationException: The locale 'en' is not present in the list of available locales in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
Edit 3: Solution
The problem was a combining of two issues. The first one was the config.yml. Make sure that the 'doctrine_phpcr.odm.locales' section is set as followed (or something a like, considering what languages you support):
locales:
en: [de, fr]
de: [en, fr]
fr: [en, de]
And the second problem was the absence of database connection configured in 'parameters.yml'. Without connection to my database, the server most likely tried to load an English object (perhaps a DateTime) and failed to load.
This is may be stupid, but have you tried to quote your language value ?
like this :
Translator : { fallback : 'en' }
in all of our symfony project we use the locale variable instead of an hard value
Translator : { fallback : "%locale%" }
according to this source code :
https://github.com/doctrine/phpcr-odm/blob/master/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php
the language definition should be quoted ( line 37 )
/**
* locale fallback list indexed by source locale
*
* example:
* array(
* 'en' => array('en', 'de', 'fr'),
* 'fr' => array('fr', 'de', 'en'),
* 'de' => array('de', 'fr', 'en'),
* )
*/
protected $localePreference;
hope that will help you
EDIT : Did you correctly setup you php-cr parameters ?
here is an example from symfony.com
doctrine_phpcr:
odm:
# ...
locales:
en: [de, fr]
de: [en, fr]
fr: [en, de]
locale_fallback: hardcoded
http://symfony.com/doc/current/cmf/bundles/phpcr_odm/multilang.html