Avoid Symfony to override parameters between bundles - symfony

I'm using YML parameters inside each bundle to use them as data fixtures as follows:
AppBundle\Resources\config\datafixtures.yml
parameters:
datafixtures:
defaultusers:
0:
name: john
email: john#company1.lol
1:
name: steve
email: steve#company1.lol
GeolocationBundle\Resources\config\datafixtures.yml
parameters:
datafixtures:
cities:
0:
external_service_area: Cantabria
company_area: Santander
1:
external_service_area: Gipuzkoa
company_area: San Sebastian
The problem comes when I import the files in the app config.yml file.
imports:
- { resource: '#AppBundle/Resources/config/datafixtures.yml' }
- { resource: '#GeolocationBundle/Resources/config/datafixtures.yml' }
Instead of merging the trees, it overrides them. Is there a way to make them merge?

Bassically the tree form makes them override each other, so the best way to avoid it is to define each node with a single complete name:
AppBundle\Resources\config\datafixtures.yml
parameters:
datafixtures.defaultusers:
GeolocationBundle\Resources\config\datafixtures.yml
parameters:
datafixtures.cities:

Related

Symfony parameters variable in variable

I work on a symfony project and I want to do something like this in my app/config/parameters.yml
dev.google.api.key: foo
google: %%kernel.environment%.google%
It not works.
I explain : I want to have the variable google to have values depending my environment (env or prod).
So I defined two variable :
dev.google.api.key: foo
prod.google.api.key: bar
I want to have my variable google to be filled with content depending on the environment. The environment is in the variable
%kernel.environment%
So if I do :
google: %kernel.environment%.google
Google is equal to "dev.google" but I want to this string to be evaluated like this %dev.google%. But %%kernel.environment%.google% not works.
An idea ?
Thanks
You can try something like this:
in your config_dev.yml:
parameters:
google.api.key: foo
in your config_prod.yml:
parameters:
google.api.key: bar
in your config.yml:
google: %google.api.key%
Or
Create paramater_dev.yml with
parameters:
google.api.key: foo
Create paramater_prod.yml with
parameters:
google.api.key: bar
in your config_dev.yml:
imports:
- { resource: paramater_dev.yml }
- { resource: config.yml }
in your config_prod.yml:
imports:
- { resource: paramater_prod.yml }
- { resource: config.yml }
in your config.yml:
google: %google.api.key%

Having problems setting up AWS S3/Cloudfront with Symfony and LiipImagineBundle

I'm trying to set up AWS S3/Cloudfront to work with liipimaginebundle in Symfony, but I really have no idea what I'm doing.
So far I have tried the following documented here http://symfony.com/doc/current/bundles/LiipImagineBundle/cache-resolver/aws_s3.html:
Installed aws-sdk-php:
"require": {
"aws/aws-sdk-php": "^3.28",
}
Set up my parameters (with the correct values not this dummy data):
amazon.s3.key: "your-aws-key"
amazon.s3.secret: "your-aws-secret"
amazon.s3.bucket: "your-bucket.example.com"
amazon.s3.region: "your-bucket-region"
Set up a resolver (although I'm not sure what that even means).
"%amazon.s3.cache_bucket%" is in the documentation but the parameter doesn't exist so I used "%amazon.s3.bucket%" instead:
liip_imagine:
cache: profile_photos
resolvers:
profile_photos:
aws_s3:
client_config:
credentials:
key: "%amazon.s3.key%"
secret: "%amazon.s3.secret%"
region: "%amazon.s3.region%"
bucket: "%amazon.s3.bucket%"
get_options:
Scheme: https
put_options:
CacheControl: "max-age=86400"
Added these lines to create the services:
services:
acme.amazon_s3:
class: Aws\S3\S3Client
factory: Aws\S3\S3Client
arguments:
-
credentials: { key: "%amazon.s3.key%", secret: "%amazon.s3.secret%" }
region: "%amazon.s3.region%"
acme.imagine.cache.resolver.amazon_s3:
class: Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver
arguments:
- "#acme.amazon_s3"
- "%amazon.s3.bucket%"
tags:
- { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }
I'm currently getting this error when I run php bin/console server:run:
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\UndefinedFunctionException: Attempted to call function "S3Client" from namespace "Aws\S3". in /var/www/swing-polls/var/cache/dev/appDevDebugProjectContainer.php:360
I've tried half a dozen other configs/tutorials to no avail. If someone can point me in the right direction I'd be incredibly grateful.
Using the code provided at Simple S3 Symfony Service with a few tweaks, I've been able to get my images to upload to my s3 bucket, but I just don't know how to get liipimaginebundle work with them.
In vendor/liip/imagine-bundle/DependencyInjection/Compiler/ResolversCompilerPass.php you can see the CompilerPass is getting the value from "resolver" attribute of the tag and is using it to create a Reference object. This means the resolver should contain the id of a service.
Try replacing
tags:
- { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }
with
tags:
- { name: "liip_imagine.cache.resolver", resolver: "acme.amazon_s3" }

Alice Faker library choose random from array

I am trying to generate a dummy data using AliceBundle for Symfony Framework. Everything seems to be working fine except I am looking for a way to randomly assign data from an array to a property called type. Looking at the faker library I can see that I can generate that using randomElement($array = array ('a','b','c'))
I am trying to convert that into YML and I think that is equivalent of
<randomElement(['a','b','c'])>
But this produces an error
[Nelmio\Alice\Throwable\Exception\FixtureBuilder\ExpressionLanguage\LexException]
Could not lex the value "['a'".
This is my complete yml
AppBundle\Entity\Job:
job{1..5}:
title: <jobTitle()>
description: <paragraph(3)>
length: "3_months_full_time"
type: <randomElement(['a','b','c'])>
bonus: <paragraph(3)>
expired_at: "2016-12-21"
job_user: "#emp*"
This works for me:
parameters:
profileArray: ['PUBLIC', 'PRIVATE', 'AUTHENTICATED']
JobPlatform\AppBundle\Entity\Profile:
profiles_{1..100}:
user: '#user_<current()>'
visibility: <randomElement($profileArray)>
I ended up creating a custom provider
namespace AppBundle\DataFixtures\Faker\Provider;
class JobTypeProvider
{
public static function jobType()
{
$types = array("paid", "unpaid", "contract");
$typeIndex = array_rand($types);
return $types[$typeIndex];
}
}
Add that to services.yml
app.data_fixtures_faker_provider.job_type_provider:
class: AppBundle\DataFixtures\Faker\Provider\JobTypeProvider
tags: [ { name: nelmio_alice.faker.provider } ]
And then use it in yml file
AppBundle\Entity\Job:
job{1..50}:
title: <jobTitle()>
description: <paragraph(3)>
length: <jobLength()>
job_industry: "#title*"
type: <jobType()>
bonus: <paragraph(3)>
expired_at: "2016-12-21"
job_user: "#emp*"
Notice type: , this is being generated from service now.

Openstack Heat - separate templates

I am looking for the best way of creating a stack, in a number of separate steps.
I would like in the first template, to only get up the compute nodes and the network configuration.
In the second template, I would like to create the storage nodes and attach them to the already existing compute nodes.
What do you think is the best way to do this?
Following is one possible approach.
1) Define first template for your compute nodes and network configuration. But define outputs in your first template to expose your compute node IDs. For example, if you create a OS::Nova::Server with name mynode1, you can expose its ID as the output for that template as follows:
outputs:
mynode1_id:
description: ID of mynode1
value: {getattr: [mynode1, id]}
Once you instantiate a heat stack, say mystack1, with this first template, then you can access the ID of mynode1 as follows:
heat output-show mystack1 mynode1_id
2) Create your second template for storage with IDs of your compute nodes from step1 as input parameters. For example:
parameters:
mynode1_id:
type: string
description: ID for mynode1
Then you can use that in your "resources:" section as follows:
resources:
...
...
my_volume_attach:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid: {get_param: mynode1_id}
...
3) Invoke your second heat stack creation as follows:
heat stack-create -f second-template.yaml -P mynode1_id=`heat output-show mystack1 mynode1_id` mystack2
You might also want to define dependencies between your resources, using the depends_on attribute.
From your description it doesn't seem like using several templates is the correct solution.
for example - if you want objects 3,4 created after objects 1,2, you can define a template as follows:
heat_template_version: '2015-10-15'
parameters:
param1:
type: string
description: just an example of parameter
resources:
object1:
type: OS::Neutron::XXX
properties:
property: XXX
description: object1
object2:
type: OS::Neutron::XXX
properties:
property: XXX
description: object2
object3:
type: OS::Nova::XXX
properties:
property: XXX
description: object3
depends_on: object1
object4:
type: OS::Nova::XXX
properties:
property: XXX
description: object4
depends_on: object1

Sonata Admin custom action seems not using the custom controller

I'm trying to make a custom action but I'm gettin this error:
Controller "Sonata\AdminBundle\Controller\CRUDController::editarDistribucionAction" for URI "/admin/test/tarifas/distribucionperiodos/6/distribucion/editar" is not callable.
I have reviewed the code many times but I can't find the mistake:
This is my custom controller:
class CustomActionsController extends CRUDController
{
public function editarDistribucionAction(){
//$id = $request->get($this->admin->getIdParameter());
//TODO:
}
}
And this is my services.yml
sonata.admin.editarDistribucion:
class: Test\TarifasBundle\Admin\DistribucionPeriodosTablaAdmin
tags:
- name: sonata.admin
manager_type: orm
group: "Tarifas"
label: "DistribuciĆ³n de periodos"
arguments: [ null, Test\TarifasBundle\Entity\DistribucionPeriodosTabla, TarifasBundle:CustomActions ]
I have tried to put wrong parameters on services.yml expecting a different error, but i get exacly the same, so it seems that is ignoring this piece of services.yml
Thanks in advance!!
It was a concept mistake. I followed the official doc step by step but y was mixing different admin clases. The configureRoutes code was in one class and I was trying to edit another one.

Resources