How to use a different auth config in a bundle? - php

Is it possible to define a different Auth config for a bundle ? application/config/auth.php is default for bundles as well but I need to use different auth modules for different bundles of the system.
Also, creating a new one on the BUNDLE/config/ folder doesn't affect anything. So, it loads the default one in any case.

The short answer is that you cannot... Neither Auth nor Config were designed to be extended per bundle.
The long answer is that you could use your bundle's start.php file to override each config setting, for example
// bundles/my-bundle/start.php
Config::set('auth.driver', 'fluent');
Config::set('auth.table', 'my_users');

Related

Accessing the base config of ZF2 application

I have a base config of my ZF2 application, which is in the following structure of my ZF2 application:
/frontend
/config
/autoload -> (here I have config.php file - which is base config)
/brand -> (here I have config files for my vhosts)
When I need things from my vhosts config I simply do like this:
$this->config()['SomethingGoesHere']
My question here is, when I'm located in my vhost (www.sitename1.com). I would like to access the base config within my vhost, how can I do that guys??
If you want to set different configuration for different virtual-hosts I would not recommend to do it like this. You can set more advanced configuration differently, for example by using environmental variables. You can read more on this here in the documentation chapter: Advanced Configuration Tricks.
The correct solution also totally depends on what variables you are setting and what you want to use them for and where you want to use them. If you provide more details on what you are trying to do (what is in your "base config"?) it would be possible to give a more suitable answer for your needs.

Access to the base_path of a particular Asset directory from a controller

I want to access the base_path (base_url registered) of a specific Asset component directory from a controller in order to store my reports to a specific path preconfigured in config.yml.
I started changing my configuration, after upgrading to Symfony 2.7, like the following:
app/config/config.yml
framework:
assets:
version: 'v5'
version_format: '%%s?version=%%s'
base_path: ~
base_urls: ['http://cdn.example.com', 'https://secure.example.com']
packages:
reports:
base_path: bundles/mybundle
So, when I request a specific route, with the correct request parameters my controller generate the HTML from a particular Twig template and, at the end, it will be converted to PDF using KnpSnappyBundle.
At last, my purpose is to build a list of generated PDF reports accessible from a public assets directory.
$kernel->locateResource()
However, I can access the complete path using a workaround like the following:
$this->container->get('kernel')->locateResource('#MyBundle/Resources/public/reports')
Using parameters.yml
I have also asked for some hints and it seems legit to use the parameters.yml in order to manage the Asset component configuration. So, from the controller, they would be accessed using $this->getParameter() and, at the same time, as a configuration value for Asset.
The simplest way to deal with that is to define it as a parameter in parameters.yml, as you suggested yourself.
It's really easy to get it and it totally makes sense.
Update
I wanted to provide a bit more reasoning for my answer, so I will cite http://symfony.com/doc/current/best_practices/configuration.html as a reference.
Reading there, it seems that you should put into "parameters.yml" all infrastructure parameters which do not really change your application behaviours. I think this applies to your case as well: your application does not change its behaviour according to assets paths, it only needs to know where they are.
So, again, I'd say that putting them in parameters.yml not only provides you an easy solution but also it's a "good practice".

Symfony2: Extend php-sdk kit to custom bundle

Using Symfony2, Twig, and Prismic:
I have looked at the following resources, but I am still unclear how to extend certain methods in Symfony2
http://symfony.com/doc/current/cookbook/bundles/inheritance.html
http://symfony.com/doc/current/cookbook/bundles/override.html
There is a prismic folder in my vendors directory, which includes the following dirs:
vendors/prismic
php-sdk
prismic-bundle
For my application, I duplicated the prismic-bundle directory and moved it here:
src/VAP/Bundle/PrismicBundle
then changed the AppKernal.php to include this bundle:
// new Prismic\Bundle\PrismicBundle\PrismicBundle() ..removed the connection to the vendor dir
new VAP\Bundle\PrismicBundle\PrismicBundle() ..use this custom directory
which works fine.
However, there are methods in the php-sdk directory that are called from my custom PrismicBundle, which I need to extend or override. For instance, a twig template may call
var.getStructuredText('blog.body').asHtml(ctx.linkResolver)
which is located here:
vendor/prismic/php-sdk/src/Prismic/Fragment/StructuredText.php
How/where would I create a file that would extend/overwrite the above file?
I am also confused if php-sdk is a bundle, or is it part of the original PrismicBundle from the vendor directory?
First, you say that you duplicated the PrismicBundle in your src folder, why did you not use the bundle inheritence process ?
public function getParent()
{
return 'PrismicBundle';
}
For you question, you have to change the behavior of the prismic php-sdk, possible reasons:
1) This sdk is not well built
2) You do not use it correctly
3) You want a very custom behavior not supported by prismic
IMO, possible solutions are:
1) Fork the sdk to add compatibility to your need
2) Think about a different way to reach your need
3) Create a new service in your custom PrismicBundle that call prismic api as you want.
Faor your final question, afaik prismic/php-sdk is the api implementation in raw php, and prismic/prismic-bundle is a bridge between this raw php SDK and Symfony, implementing services and all comodities provided by Symfony.

Symfony2 config load order

I was wondering what order does Symfony use when loading config files, and I can't seem to find the answer. The config is later flattened using processConfiguration method from Extension class.
Symfony loads app/config/config.yml first;
config_{environment}.yml afterwards for it to be able to overwrite default settings;
afterwards all bundle configuration is loaded in the order of the bundles being registered in app/AppKernel.php.

Symfony custom config cascade

In Symfony 1.4, is it possible for one to define a custom config file (e.g. my_config.yml) that allows cascading; for instance, having a global custom config file and a module level analogue?
Yes.
Define a config handler in config_handlers.yml. It'll probably look like:
config/my_config.yml:
class: myConfigHandler
Write your config handler. You can look at many of the other config handlers in lib/config for examples. You'll likely want to extend sfYamlConfigHandler.
To access your config values:
sfContext::getInstance()->getConfigCache()->checkConfig('/config/my_config.yml');

Categories