Symfony2: Multi-level parameters in YML - arrays

Here is what I want to do. I've got some yml file like...
My custom yml file :
# app/config/sv_parameters.yml
parameters:
sv_email:
debug: "debug#debug.com"
admin: "admin#admin.com"
...
The config.yml file, importing my custom params :
# app/config/config.yml
imports:
- { resource: sv_parameters.yml }
...
The config_dev.yml, importing the config.yml, and using a sub-parameter of my custom yml file :
# app/config/config_dev.yml
imports:
- { resource: config.yml }
swiftmailer:
delivery_address: "%sv_email.debug%"
But, when I clear:cache :
You have requested a non-existent parameter "sv_email.debug".
I know in PHP multi-level parameters are arrays. But does that mean we can access them in pure YML ?
I could write my sv_email parameters inline, but that's not as clean as multi levels..

This is not possible to achieve in YML.
You have to move this nested variable to the upper level and then - include it in both needed places.

Related

Can I specify cluster keys for Snowflake in DBT within my yaml file?

According to current DBT documentation for Snowflake, you can configure clustering in Snowflake by providing cluster_by into a models' config.
config(
materialized='table',
cluster_by=['col_1']
)
I would rather provide these values in the model's yml file, like so:
models:
- name: my_model
cluster_by: ['col_1']
Is this possible to do?
You should be able to do this using a config resource property in the .yml file.
e.g.
models:
- name: my_model
config:
cluster_by: ['col_1']
see https://docs.getdbt.com/reference/model-configs and https://docs.getdbt.com/reference/model-properties

Export module via Webpack

I am working on a React app. In index.js am exporting some variables, e.g.
export const a="Hello";
export const b=[1,2,3];
In webpack.config.js:
...
output: {
...
library: "myApp",
libraryTarget: "window"
},
...
I know window.myApp is now a module which includes all the exported variables from index.js. What I do not know is how the above works. How this module is being created and why it includes only the exports from index.js and not other files as well? How, may I include exports from another specific file?
Your module is being created based on the entry configuration and the other modules and plugins that you configure and is converted to a build file based on the configuration provided in the output config of webpack.
library setup is tied to the entry configuration so if you specify the entry to be index.js, your exports from within the index.js are available within the build
In order to also expose exports from other files, you can import and export them from the index file like
export { default as SomeFunction} from 'some-function.js';
According to the webpack docs:
For
most libraries, specifying a single entry point is sufficient. While
multi-part libraries are possible, it is simpler to expose partial
exports through an index script that serves as a single entry point.
Using an array as an entry point for a library is not recommended.
libraryTarget specifies how the module is exposed. For instance in your case your module is exposed on the window object.
You can expose the library in the following ways:
Variable: as a global variable made available by a script tag (libraryTarget:'var').
This: available through the this object (libraryTarget:'this').
Window: available through the window object, in the browser (libraryTarget:'window').
UMD: available after AMD or CommonJS require (libraryTarget:'umd').
If library is set and libraryTarget is not, libraryTarget defaults to
var as specified in the output configuration documentation. See
output.libraryTarget there for a detailed list of all available
options.
You have two solution to include other files
First is to use multiple entries in your webpack module
module.exports = {
// mode: "development || "production",
entry: {
A: "./CompA",
B: "./CompB"
},
Second approach is use one entry like your solution, but need to add wrappere.js
wrapper.js
import * as a from './CompA.js'
import * as b from './CompB.js'
export a,b
And your wrapper become the single entry, where you can access later wrapper.a,wrapper.b
module.exports = {
// mode: "development || "production",
entry: {
app: "./wrapper.js",
},

Flow required module not found

Using Webpack 2, Flow 0.46.0
I have a pretty large app I am developing, so am using Webpack resolve modules to create alias import names e.g. '../../../../constants/ServiceURI' to 'constants/ServiceURI'
Everything works fine until I add flow. There must be a way to use mapper or resolve_dirname to fix this, but I cannot figure out how. No matter what I do it breaks flow.
I really want to use flow, but this is a blocker for me.
Project structure:
./flowconfig
./webpack.config.js
./src
/js
/constants
/actions
/...
/css
Webpack config looks like:
resolve: {
modules: [
path.resolve('./src/js'),
path.resolve('./src/js/constants'),
'node_modules'
],
extensions: ['.js', '.jsx']
Flow config looks like:
[ignore]
.*/node_modules/*
[include]
<PROJECT_ROOT>/src/js/
[libs]
[options]
esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable
esproposal.export_star_as=enable
esproposal.decorators=ignore
# Tried this
module.name_mapper='^constants$' -> '<PROJECT_ROOT>/src/js/constants'
# Tried using this too
module.system.node.resolve_dirname=./src/js
module.system=haste
munge_underscores=true
[version]
0.46.0
Flow Error:
rc/js/actions/ActionActivity.js:6
6: import { ACTIVITY_API } from 'constants/ServiceURI'
^^^^^^^^^^^^^^^^^^^^^^
constants/ServiceURI. Required module not found
The regular expression you're using in the module.name_mapper does not match constants/ServiceURI. It only matches exactly constants. You additionally need to match anything that comes after constants to be able to resolve all modules inside the constants directory.
module.name_mapper='^constants/\(.*\)$' -> '<PROJECT_ROOT>/src/js/constants/\1'
Where \( and \) create a capturing group (the slashes are required), which you can refer to as \1. For more information see module.name_mapper.

Config variable not being fetched as expected from application.yml

I have config variable(in application.yml) as:
xyz:
exception.emails: ['abc#gmail.com']
While fetching this in local works fine but after deploying war I am getting config variable as:
xyz: [
exception: [
emails[
0
]: abc#gmail.com
]
]
I am pulling this as:
def email = Holders.config.grails.xyz.exception.emails
I'm actually surprised this work at all, because I don't think that is proper yml syntax looking at the default application.yml they specify a list of userAgents like this:
grails:
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
Personally I like to use an application.groovy and use groovy syntax like this:
grails {
mime {
disable {
accept {
header {
userAgents:
['Gecko', 'WebKit', 'Presto', 'Trident']
}
}
}
It maybe a little out of date but here is an example of a application.yml converted to application.groovy:
https://github.com/virtualdogbert/Grails3Tutorial/blob/step_01_settings_yml_to_groovy/grails-app/conf/application.groovy
Also note in the past you could run code from application.groovy, however if you have any imports they won't work,because application.yml/groovy, is meant for the cli(pre runtime), so as a workaround you can also specify a runtime.groovy, where you can have imports. If you ever go the extra mile and write a plugin, you can specify a plugin.groovy, to set defaults.

Parsing application.yml in angularjs

I have a application.yml file in my application
spring:
profiles:
active: default,dev
app:
properties:
lucene:
indexInfoFile: ${spring.jpa.properties.hibernate.search.default.indexBase}/index.properties
reindex: false
storage:
home: ${user.home}/xxx
basePath: ${app.properties.storage.home}/uploads/
staticFilesPrefix: /files/
appUrl: /app/
spring:
profiles: dev
http:
multipart:
max-file-size: 3MB
max-request-Size: 3MB
Now in my controller, I am trying to get the data from yml file and the code for the same is
$http.get('/resources/application.yml').then(function (response) {
console.log('entire data is ', response.data);
console.log('basePath is ', response.data.basePath);
});
Entire Data is printing perfectly ( the whole yml file is getting printed) but when ever I am trying to print a particular property like basePath, max-file-size etc I am getting "undefined error".
My question is how to get a particular property to be printed on the console.
I would not recommend to access the yml file directly in Angular.
The format is difficult to parse (hence your question) and you sooner or later you may not want to expose all your confguration details.
Instead create a rest controller in spring mapped to something like /config
Let spring inject all the configuration values you need using #Value and return a Map or a simple PoJo with exactly the attributes you need.
Spring will convert this to JSON which you can easily be consumed in Angular.

Resources