Skip to content
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

why di config/loader parsed result is not compatible to neon format? #134

Closed
andares opened this issue Dec 22, 2016 · 4 comments
Closed

why di config/loader parsed result is not compatible to neon format? #134

andares opened this issue Dec 22, 2016 · 4 comments

Comments

@andares
Copy link
Contributor

@andares andares commented Dec 22, 2016

I am improved the config class with neon, now it can be write like this:

services:
    - App\Play\Provider
    - App\Play\Sender
    - App\Play\Logger(dev.log)

prod < services:
    - App\Play\Logger(prod.log)

test < services:
    - App\Play\Logger(test.log)

it can merge config in every env, I'd like it :-P

but when I try to use addConfig() method to set di config to compiler, it was error, because Nette\Neon\Entity is not Nette\DI\Statement

could you make they to be same class? or compatible neon entity in Validator?

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Dec 22, 2016

Can you show you code?

@andares

This comment has been minimized.

Copy link
Contributor Author

@andares andares commented Dec 22, 2016

look, by the sample I can make di like this:

$class = $loader->load(function($compiler) {
    $path= combi()->app->path('src', 'config/services.neon');
    $compiler->loadConfig($path);
});

it's no problem.

now, I want to do something before config load, and I still use neon format. so I couldn't use loadConfig() method, I try to load and parse neon config by myself, and use addConfig() method to put config into compiler.

$class = $loader->load(function($compiler) {
    $config = combi()->app->config('services')->toArray(); // it return array like Neon::decode().
    $compiler->addConfig($config);
});

and will throw exception:

<b>Fatal error</b>:  Uncaught Nette\Utils\AssertionException: The item 'factory' in array expects to be callable or Nette\DI\Statement or null, object Nette\Neon\Entity given. in /home/andares/repos/combi/combi/vendor/nette/utils/src/Utils/Validators.php:90

because neon::decode() will return entity object, di system need di\statement, although they look very similar. I think it should be more compatible.

var_dump for my parsed config:

array(1) {
  ["services"]=>
  array(3) {
    [0]=>
    string(17) "App\Play\Provider"
    [1]=>
    string(15) "App\Play\Sender"
    [2]=>
    object(Nette\Neon\Entity)#11 (2) {
      ["value"]=>
      string(15) "App\Play\Logger"
      ["attributes"]=>
      array(1) {
        [0]=>
        string(7) "dev.log"
      }
    }
  }
}

=============================

you can see my config class in the links:

https://github.com/andares/combi-core/blob/master/src/classes/Core/Config.php
https://github.com/andares/combi-core/blob/master/tests/classes/Core/Config.php

It is bind to neon libs, I can add some code to trans neon\entity to di\statement, but it is low efficiency.

I will try to add neon\entity support to di libs tomorrow.

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Dec 22, 2016

$compiler->addConfig() accepts array, so it is (intentionally) independent from the source format, so it doesn't understand Nette\Neon\Entity. Conversion Entity -> Statement is done by Nette\DI\Config\Adapters\NeonAdapter::process(). I have changed visibility to public, so you can use now:

$compiler->addConfig((new Nette\DI\Config\Adapters\NeonAdapter)->process($config));
@dg dg closed this in 7481551 Dec 22, 2016
@andares

This comment has been minimized.

Copy link
Contributor Author

@andares andares commented Dec 23, 2016

got it, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.