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

Merge array #20

Closed
fcaldarelli opened this issue Jan 11, 2019 · 11 comments
Closed

Merge array #20

fcaldarelli opened this issue Jan 11, 2019 · 11 comments

Comments

@fcaldarelli
Copy link

fcaldarelli commented Jan 11, 2019

In yii-console we have a problem with array merge.

This is the order of reading configs, that it is right:

  'tests' => 
  array (
    0 => '$console',
    1 => $baseDir . '/vendor/yiisoft/yii-core/config/tests.php',
    2 => '$web',
    3 => $baseDir . '/vendor/yiisoft/view/config/tests.php',
    4 => $baseDir . '/vendor/yiisoft/db-mysql/config/tests.php',
    5 => '$common',
    6 => $baseDir . '/vendor/yiisoft/db-sqlite/config/tests.php',
    7 => $baseDir . '/config/console.php',
  ),

the content of last config yii-console\config\console.php contains:

    'response' => [
        '__class' => \yii\console\Response::class,
    ],

The final output is:

  'response' => 
  array (
    '__class' => 'yii\\console\\Response',
    'formatters' => 
    array (
      'html' => 
      array (
        '__class' => 'yii\\web\\formatters\\HtmlResponseFormatter',
      ),
      'xml' => 
      array (
        '__class' => 'yii\\web\\formatters\\XmlResponseFormatter',
      ),
      'json' => 
      array (
        '__class' => 'yii\\web\\formatters\\JsonResponseFormatter',
      ),
      'jsonp' => 
      array (
        '__class' => 'yii\\web\\formatters\\JsonResponseFormatter',
        'useJsonp' => true,
      ),
    ),
  ),

because is the merge of'/vendor/yiisoft/view/config/tests.php' andyii-console\config\console.php`.

The problem is that \yii\console\Response class has not 'formatters' property, and when $config is loaded inside that object, it returns an error.

I thought 2 solutions:

  1. Tell to composer-config-plugin to skip some array key; but anyway, there could be other keys that could not be found in class;
  2. Tell to composer-config-plugin that should consider only specified config;
    So, if I had an "onlythis" prefix:
        "config-plugin": {
            "tests": "onlythis-config/console.php"
        }

this should consider only config/console.php for tests and nothing else.

@hiqsol
Copy link
Member

hiqsol commented Jan 11, 2019

First of all I think we don't need yii-web in yii-console. Please check this direction.

Another idea: add formatters property to base Response.
I mean console Response can be formatted too: plain text, json, html, yaml, why not?

@fcaldarelli
Copy link
Author

fcaldarelli commented Jan 11, 2019

We need yii-web or yii-console to satisfy some dependencies, I think.

Then, I'd try to solve the issue, because now we could force \yii\console\Response object adding (unuseful for me) formatters, but it could not be possible in other cases.

Finally, I should be sure that ascendant config json don't add properties that not exist in the class, so I should be able to avoid merge.

@machour
Copy link
Contributor

machour commented Jan 11, 2019

If I'm reading and understanding the report right, and considering this simple structure:

class Root 
{
}

class Fork1 extends Root
{
     public $foo;
}

class Fork2 extends Root
{
}

having a package configuring Fork1, then my application configuring Fork2 as DI instances of Root would result in $foo trying to be set on Fork2 ?

@hiqsol
Copy link
Member

hiqsol commented Jan 11, 2019

@FabrizioCaldarelli I agree with what you say.
But first of all yii-web should not be needed in yii-console, we need to find those dependencies and solve it somehow without yii-web.

I don't have general solution at the moment. Need to think some more.

@fcaldarelli
Copy link
Author

fcaldarelli commented Jan 11, 2019

What about this:

        "config-plugin": {
            "tests": "ONLYTHIS-config/console.php"
        }

We need to fix this as soon as possible, it is a big issue.

@hiqsol
Copy link
Member

hiqsol commented Jan 11, 2019

I thought about adding - option to exclude files like:

        "config-plugin-dev": {
            "tests": "-vendor/yiisoft/yii-web/config/web.php"
        }

But the problem is: the package has its configuration and the package may NOT work without its configuration. So it's a bit doubtful.

@fcaldarelli
Copy link
Author

I thought about adding - option to exclude files like:

Instead excluding files (I have to know what files to exclude and in the future this list could change), I'd prefer to specify what is the just one file to include.

@hiqsol
Copy link
Member

hiqsol commented Jan 11, 2019

I'm trying to tell that this will solve formatters problem but may create others. Because if we use yii-web package we need it's config too.

@fcaldarelli
Copy link
Author

What other problems?

@hiqsol
Copy link
Member

hiqsol commented Jan 11, 2019

That there is no configuration which is need for some yii-web classes to work.
Maybe not right now but eventually.

@hiqsol hiqsol closed this as completed in 9f61a78 Jan 11, 2019
xepozz pushed a commit to xepozz/hiqdev-fork-composer-config-plugin that referenced this issue Apr 17, 2020
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

3 participants