Skip to content

Instantly share code, notes, and snippets.

@redboxmarcins
Created October 18, 2016 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redboxmarcins/aa2fb3ed5b6c8a193bdb4accdc2c0303 to your computer and use it in GitHub Desktop.
Save redboxmarcins/aa2fb3ed5b6c8a193bdb4accdc2c0303 to your computer and use it in GitHub Desktop.
Object manager
magento/framework/ObjectManager/Config/Compiled.php
/**
* Retrieve list of arguments per type
*
* @param string $type
* @return array
*/
public function getArguments($type)
{
if (isset($this->arguments[$type])) {
if (is_string($this->arguments[$type])) {
$this->arguments[$type] = unserialize($this->arguments[$type]);
}
return $this->arguments[$type];
} else {
return [['_i_' => 'Magento\Framework\ObjectManagerInterface']];
}
}
So if for any type arguments cannot be found it will return Object manager object
We use https://github.com/maxmind/MaxMind-DB-Reader-php for magento2 projects
so anywhere in the code we can use
\MaxMind\Db\ReaderFactory in a way
$readerFactory->create(['database' => 'path/to/file.mmdb');
above works on in default/develop mode
but in production mode - actual value of passed variable $database is Object manager, not string as required
@antonkril
Copy link

antonkril commented Oct 18, 2016

This happens because compiler does not read MaxMindDBReader directory, so it does not collect constructor signature information from it. So compiled class definition config does not know that DB\Reader has a $database argument.

It works like that because it is too expensive to compile vendor directory. But we plan to fix it in an efficient way.

Anyway, we always recommend to not depend on third-party libraries directly, and implement adapters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment