{"action":"created","issue":{"url":"https://api.github.com/repos/auraphp/Aura.SqlSchema/issues/18","labels_url":"https://api.github.com/repos/auraphp/Aura.SqlSchema/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/auraphp/Aura.SqlSchema/issues/18/comments","events_url":"https://api.github.com/repos/auraphp/Aura.SqlSchema/issues/18/events","html_url":"https://github.com/auraphp/Aura.SqlSchema/pull/18","id":101243294,"number":18,"title":"Add SchemaFactory","user":{"login":"jakejohns","id":174708,"avatar_url":"https://avatars.githubusercontent.com/u/174708?v=3","gravatar_id":"","url":"https://api.github.com/users/jakejohns","html_url":"https://github.com/jakejohns","followers_url":"https://api.github.com/users/jakejohns/followers","following_url":"https://api.github.com/users/jakejohns/following{/other_user}","gists_url":"https://api.github.com/users/jakejohns/gists{/gist_id}","starred_url":"https://api.github.com/users/jakejohns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakejohns/subscriptions","organizations_url":"https://api.github.com/users/jakejohns/orgs","repos_url":"https://api.github.com/users/jakejohns/repos","events_url":"https://api.github.com/users/jakejohns/events{/privacy}","received_events_url":"https://api.github.com/users/jakejohns/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-16T08:40:45Z","updated_at":"2015-08-16T19:19:14Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/auraphp/Aura.SqlSchema/pulls/18","html_url":"https://github.com/auraphp/Aura.SqlSchema/pull/18","diff_url":"https://github.com/auraphp/Aura.SqlSchema/pull/18.diff","patch_url":"https://github.com/auraphp/Aura.SqlSchema/pull/18.patch"},"body":"I think this should allow us to create a schema object without needing to know the\r\ndriver type by getting the information from the `pdo` via\r\n`PDO::getAttribute(PDO::ATTR_DRIVER_NAME)`, or by passing a name.\r\n\r\nI think this makes it easier to get a schema object when the drive type is\r\ndefined in configuration. For example, defining a key in an `.env` file as\r\n`DB_DRIVER=sqlite`. \r\n\r\n```php\r\n\r\nfunction define(Container $di) {\r\n    $di->set(\r\n        'aura/schema:schema_factory',\r\n        $di->lazyNew('Aura\\SqlSchema\\SchemaFactory')\r\n    );\r\n\r\n    $di->set(\r\n        'schema',\r\n        $di->lazyGetCall(\r\n            'aura/schema:schema_factory',\r\n            'newSchema',\r\n            $di->lazyGet('pdo'),\r\n            $_ENV['DB_DRIVER']\r\n        )\r\n    );\r\n\r\n    // or, since I think we can just get this info from PDO:\r\n\r\n    $di->set(\r\n        'schema',\r\n        $di->lazyGetCall(\r\n            'aura/schema:schema_factory',\r\n            'newSchema',\r\n            $di->lazyGet('pdo')\r\n        )\r\n    );\r\n}\r\n\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/auraphp/Aura.SqlSchema/issues/comments/131609358","html_url":"https://github.com/auraphp/Aura.SqlSchema/pull/18#issuecomment-131609358","issue_url":"https://api.github.com/repos/auraphp/Aura.SqlSchema/issues/18","id":131609358,"user":{"login":"jakejohns","id":174708,"avatar_url":"https://avatars.githubusercontent.com/u/174708?v=3","gravatar_id":"","url":"https://api.github.com/users/jakejohns","html_url":"https://github.com/jakejohns","followers_url":"https://api.github.com/users/jakejohns/followers","following_url":"https://api.github.com/users/jakejohns/following{/other_user}","gists_url":"https://api.github.com/users/jakejohns/gists{/gist_id}","starred_url":"https://api.github.com/users/jakejohns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakejohns/subscriptions","organizations_url":"https://api.github.com/users/jakejohns/orgs","repos_url":"https://api.github.com/users/jakejohns/repos","events_url":"https://api.github.com/users/jakejohns/events{/privacy}","received_events_url":"https://api.github.com/users/jakejohns/received_events","type":"User","site_admin":false},"created_at":"2015-08-16T19:19:14Z","updated_at":"2015-08-16T19:19:14Z","body":"### re: factories and di\r\n\r\n> I am not in favor for Factory for the Di usage.\r\n\r\nReally? I'd love some further explanation on that.\r\n\r\nI initially found myself duplicating a lot of the config/Common code from the\r\naura components in my project and component configs, since the provided\r\nconfigs use the 2.x naming (Container, not ContainerConfig) (I guess I might be\r\nable to use class_alias or something instead).\r\n\r\nHowever, I thought using the factories and lazyGetCall, might be a **better**\r\nsolution, since it seems like my consuming code needs to know a little *too much*\r\nabout the internals of the aura packages to be able to configure them. For\r\nexample, if I'm using [aura/session](https://github.com/auraphp/Aura.Session/blob/2.x/config/Common.php)\r\nI dont think my project needs to know about `Randval` and `PhpFunc`. I thought\r\nit made more sense to use the API defined by the factory and session, and let\r\naura/session take care of itself. If some \"internal\" dependency changes in a\r\npackage, that doesn't break the public API, I shouldn't need to update my\r\nconfigs.\r\n\r\nAlso, I was under the impression, that the presence of the _Config/Common stuff\r\nwas going away in favor of a more \"factory oriented approach\". I figured this\r\napproach was more in line with the future.\r\n\r\n### re: knowing which object to create\r\n\r\nI could just do the translation of a string like \"sqlite\" to\r\n\"Aura\\SqlSchema\\SqliteSchema\" in the config. I think it seems a little\r\nclunkier every way I've written it. I end up with what seems an unnecessary\r\namount of logic in my config, and again, seem to need to know quite a bit about\r\nthe internals of the aura package.\r\n\r\n\r\n```php\r\n\r\n$drivers = [\r\n    'mysql' => 'Aura\\SqlSchema\\MysqlSchema',\r\n    'pgsql' => 'Aura\\SqlSchema\\PgsqlSchema',\r\n    'sqlite' => 'Aura\\SqlSchema\\SqliteSchema',\r\n    'sqlsrv' => 'Aura\\SqlSchema\\SqlsrvSchema'\r\n];\r\n\r\n$di->set('schema', $di->lazyNew($drivers[$_ENV['DB_DRIVER']]));\r\n\r\n// or maybe something like this? but this seems really convoluted\r\n\r\n$di->set('schema', $di->lazyValue('db_driver'));\r\n\r\n$di->values['db_driver'] = $di->lazy(\r\n    function () use ($di, $drivers) {\r\n        $driver = $di->get('pdo')->getAttribute(PDO::ATTR_DRIVER_NAME);\r\n        return $drivers[$driver];\r\n    }\r\n);\r\n\r\n```\r\n\r\nDo people think these types of solutions are preferable?\r\n\r\nThoughts?\r\n\r\n\r\n"}}