1

For my AppBundle (THE APPLICATION ITSELF, NOT A REUSABLE BUNDLE) I have a configuration parameter that is a path. I'd like to be sure the path ends with a /.

In this moment I have a method in the entity that uses this path (yes is an entity and not a controller) adjust the configuration parameter with a code like this:

public function buildLogoFolder($folder)
{
    // Replace the placeholder with the current Entity's URL
    $folder = str_replace('{entity_domain}', $this->getDomain()->getCanonical(), $folder);

    $folder = rtrim(ltrim($folder, '/'), '/') . '/';

    return $folder;
}

As the $folder parameter comes from the config.yml file I'd like to move outside of the entity this adjustment.

I think I should use a solution similar to the one suggested here, that is the use of the DependencyInjection component.

I think the process is very similar to the loading of a configuration file for a new bundle as explained in the Symfony's documentation but I'm not sure on how to proceed.

Is there someone who can put me on the right way?

I'd like to automate the process. I want read the folder configuration parameter value and then adjust it with the method I wrote above.

I want to be sure that the folder parameter configured ever ends with a trailing slash, also if the developer didn't write it in the configuration.

So, If the developer write something like path/to/folder the resulting configuration parameter is automatically adjusted to path/to/folder/.

12
  • You want to override the config file if the developer write the path folder without /? Commented Jan 4, 2016 at 16:07
  • Not all the config file, but only the value of the folder parameter (question updated to be more precise) Commented Jan 4, 2016 at 16:12
  • How do you actually load that config option right now? Is it just a container parameter? Do you have a container extension? Commented Jan 4, 2016 at 16:24
  • 2
    You could use a compiler pass to clean it up: symfony.com/doc/current/cookbook/service_container/…. But honestly, just doc the correct format and go with it. Trying to anticipate and correct these sorts of error seems to be an exercise in futility. Commented Jan 4, 2016 at 17:17
  • 2
    What about creating a utility class where that duplicated code was in a static function call that you could invoke from anywhere, or in a service, or a trait that your classes implement? Commented Jan 4, 2016 at 18:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.