Skip to content

Options in DI extensions do not expect Statement instances #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dakujem opened this issue Jan 7, 2020 · 1 comment
Closed

Options in DI extensions do not expect Statement instances #228

dakujem opened this issue Jan 7, 2020 · 1 comment

Comments

@dakujem
Copy link

dakujem commented Jan 7, 2020

Version: 3.0.2

I'm struggling with a simple case where I'm loading environment variables and some other stuff into parameters and then using them with extensions, namely session, application, http, tracy, but there might be others as well. I'm not sure whether to file an issue to each of the packages or to this one.

I'm getting this kind of errors:

The option 'http > proxy' expects to be string or Nette\Schema\DynamicParameter, object Nette\DI\Definitions\Statement given.

Example:

parameters:
    system:
        http:
            proxy:                @env::getArray(TRUSTED_PROXIES_IP)

http:
    proxy: %system.http.proxy%

Using scalar values is not an option. I understand I could use "dynamic parameters" like so:

$configurator->addDynamicParameters([
	'system' => ['http' => ['proxy' => TODO ]]
]);

But then how would I call @env::getArray(TRUSTED_PROXIES_IP) instead of TODO?

Furthermore, how would I instead add dynamic parameters in a NEON config file so that I need not have params in 2 places (NEON config file(s) and PHP config file that instructs Configurator)?

I might be missing something. Thanks for help.

@dakujem
Copy link
Author

dakujem commented Jan 8, 2020

Thank you for fast response.

markoph added a commit to remp2020/crm-skeleton that referenced this issue Mar 31, 2022
Environment variable `CRM_LANG` was removed.

---

Problem:

- [Kdyby/Translation expects default language to be string type][1].
- From version 3.0, `Nette/DI` returns `Nette\DI\Definitions\Statement`
  instead of string (it used to evaluate method used in config; in our
  case `@environmentConfig::get('CRM_LANG')`).
- `Nette\DI` returns error

  ```
  Nette\DI\InvalidConfigurationException:
  The item 'translation › default' expects to be string, object
  Nette\DI\Definitions\Statement given.` is returned.
  ```

This worked in Nette 2.4 because `Nette/DI` resolved parameters (in this
case it called method to load environment variable) and it returned string
to extension DI compiler.

---

Solution: Removed loading of language from environment (variable
CRM_LANG was removed).

If you run different instances from one code base, it's better to have
different `config.*.neon` files. Which config is loaded is based on env
variable `CRM_ENV`. Check `Crm\ApplicationModule\Core::createContainer`.

---

Note: We checked alternative extension, but [Contributte/Translation also
expects string parameter][2].

---

Discussion:

- [Temporarily fixed, but reverted back][3]
- [Options in DI extensions do not expect Statement instances][4]

[1]: https://github.com/Kdyby/Translation/blob/4c4a02a22922b8d69961bb4cd17c104c451622a4/src/DI/TranslationExtension.php
[2]: https://github.com/contributte/translation/blob/e78977eb2ce0cc3104ce1fa880516521cdef228c/src/DI/TranslationExtension.php
[3]: nette/di#221 (comment)
[4]: nette/di#228

remp/crm#2144
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant