{"action":"reopened","issue":{"url":"https://api.github.com/repos/magento/magento2/issues/2529","repository_url":"https://api.github.com/repos/magento/magento2","labels_url":"https://api.github.com/repos/magento/magento2/issues/2529/labels{/name}","comments_url":"https://api.github.com/repos/magento/magento2/issues/2529/comments","events_url":"https://api.github.com/repos/magento/magento2/issues/2529/events","html_url":"https://github.com/magento/magento2/issues/2529","id":118941893,"number":2529,"title":"di.xml argument type=\"array\" and Monolog Handlers","user":{"login":"mttjohnson","id":50849,"avatar_url":"https://avatars.githubusercontent.com/u/50849?v=3","gravatar_id":"","url":"https://api.github.com/users/mttjohnson","html_url":"https://github.com/mttjohnson","followers_url":"https://api.github.com/users/mttjohnson/followers","following_url":"https://api.github.com/users/mttjohnson/following{/other_user}","gists_url":"https://api.github.com/users/mttjohnson/gists{/gist_id}","starred_url":"https://api.github.com/users/mttjohnson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mttjohnson/subscriptions","organizations_url":"https://api.github.com/users/mttjohnson/orgs","repos_url":"https://api.github.com/users/mttjohnson/repos","events_url":"https://api.github.com/users/mttjohnson/events{/privacy}","received_events_url":"https://api.github.com/users/mttjohnson/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/magento/magento2/labels/PS","name":"PS","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-11-25T23:36:18Z","updated_at":"2016-05-24T14:22:49Z","closed_at":null,"body":"I ran into an issue with a 3rd party package (Monolog) that is expecting a numerical array (list) of handlers, but the way they are specified in the di.xml for injecting into the constructor, ObjectManager ends up passing in an array with named keys.\r\n\r\n#### app/etc/di.xml\r\n```\r\n    <type name=\"Magento\\Framework\\Logger\\Monolog\">\r\n        <arguments>\r\n            <argument name=\"name\" xsi:type=\"string\">main</argument>\r\n            <argument name=\"handlers\"  xsi:type=\"array\">\r\n                <item name=\"system\" xsi:type=\"object\">Magento\\Framework\\Logger\\Handler\\System</item>\r\n                <item name=\"debug\" xsi:type=\"object\">Magento\\Framework\\Logger\\Handler\\Debug</item>\r\n            </argument>\r\n        </arguments>\r\n    </type>\r\n```\r\n\r\n#### [\\Monolog\\Logger::addRecord()](https://github.com/Seldaek/monolog/blob/419ca7ac2562fe43941692ec442ce6d0398dfe10/src/Monolog/Logger.php#L288) \r\n```\r\n        while (isset($this->handlers[$handlerKey]) &&\r\n            false === $this->handlers[$handlerKey]->handle($record)) {\r\n            $handlerKey++;\r\n        }\r\n```\r\n\r\nBasically the way this is currently behaving is that the array of handlers being passed into Monolog from Magento ends up processing the first handler that it found that `isHandling()` was true for, and fails to process any other handlers after that handler. It takes the key (`system`) from the handler in `$this->handlers` and tries to increment (`$handlerKey++`) the key (`systen`) to get the next handler in the list, but that fails.\r\n\r\nA potential workaround without modifying the Monolog code would be to use a sequential list of numbers on the item names in the di.xml file.\r\n```\r\n    <type name=\"Magento\\Framework\\Logger\\Monolog\">\r\n        <arguments>\r\n            <argument name=\"name\" xsi:type=\"string\">main</argument>\r\n            <argument name=\"handlers\"  xsi:type=\"array\">\r\n                <item name=\"0\" xsi:type=\"object\">Magento\\Framework\\Logger\\Handler\\System</item>\r\n                <item name=\"1\" xsi:type=\"object\">Magento\\Framework\\Logger\\Handler\\Debug</item>\r\n            </argument>\r\n        </arguments>\r\n    </type>\r\n```\r\n*Granted this example seems pointless, but if I'm adding my own custom logger, and multiple handlers it seems to be difficult to specify it the same way as Magento has implemented in the core using di.xml to inject the parameters.*\r\n\r\nThis doesn't seem like a real great solution and doesn't provide a way for additional handlers to be cleanly added to the array. If one extension tried adding a handler item with a name of \"2\" and some other extension also tried adding their own handler item with a name of \"2\" that wouldn't work too well.\r\n\r\nI'm not seeing any current way that I can specify the list of items for an argument that will just add an item to the array without a named element. If that was an option, it would provide a better workaround for this issue.\r\n\r\nUltimately I would have to blame the poor behavior and limitation on Monolog in how the handlers array is iterated over, and not allowing for the fact that PHP does not distinguish between indexed and associative arrays."}}
{"actor":{"display_login":"antonkril"}}