{"action":"created","comment":{"url":"https://api.github.com/repos/robmorgan/phinx/pulls/comments/22761304","id":22761304,"diff_hunk":"@@ -0,0 +1,178 @@\n+.. index::\r\n+   single: Phinx via Code\r\n+\r\n+Calling Phinx via Code\r\n+===================================\r\n+\r\n+Phinx is primarily a command line tool, however Phinx does support code-based calls.\r\n+\r\n+.. warning::\r\n+\r\n+    Not all terminal commands are available to be used within code yet.\r\n+\r\n+Initial Setup\r\n+--------------\r\n+\r\n+.. note::\r\n+\r\n+    For Phinx via Code to work at all, you need to ensure that Phinx is accessible via autoloading,\r\n+    the best way to manage this would be to ``require \"vendor/autoload.php\";`` the composer autoloader.\r\n+\r\n+Phinx will require instantiating, which can be achieved by the following.\r\n+\r\n+.. code-block:: php\r\n+\r\n+    $app = new \\Phinx\\Console\\PhinxApplication($version);\r\n+    $phinx = new \\Phinx\\Wrapper\\TextWrapper($app);\r\n+\r\n+Where ``$version`` is the version number of Phinx (eg. '0.4.1').\r\n+``$phinx`` now contains our Phinx object which will expose to us the commands.\r\n+\r\n+\r\n+\r\n+Custom Options\r\n+---------------\r\n+\r\n+Phinx comes with some sensible options set for us, however these are not always appropriate and may need changing.\r\n+\r\n+There are two ways an option value can be set.\r\n+\r\n+The first way is instead of the ``$phinx`` declaration above, we can pass through a second parameter ``$options`` as an array of options.\r\n+\r\n+.. code-block:: php\r\n+\r\n+    $phinx = \\Phinx\\Wrapper\\TextWrapper($app, array(\r\n+        'option_name' => 'option_value',\r\n+    ));\r\n+\r\n+To set multiple options and values, simply add more key value pairs to the ``$options`` array.\r\n+\r\n+The second way uses the original ``$phinx`` object and uses the ``setOption($option, $value)`` method.\r\n+\r\n+This method can be invoked multiple times, and either chained together or with each invokation done separately.\r\n+\r\n+.. code-block:: php\r\n+\r\n+    $phinx->setOption('option_name', 'option_value');\r\n+\r\n+The three options we can alter are:\r\n+\r\n+1. Environment name\r\n+2. Configuration File Location\r\n+3. Parser Information\r\n+\r\n+.. note::\r\n+\r\n+    There is no need to define these options if they are the same as the defaults.\r\n+\r\n+Configuring Environment Name\r\n+-----------------------------\r\n+\r\n+Setting the Environment Name is done using the option name ``environment``.\r\n+The value you assign should match the config file environment declared (eg. ``development``)\r\n+\r\n+.. code-block:: php\r\n+\r\n+    $phinx->setOption('environment', 'development');\r\n+\r\n+The default value if left blank is: ``development``.\r\n+\r\n+Configuring Configuration File Location\r\n+----------------------------------------\r\n+\r\n+Setting the Configuration File Location is done using the option name ``configuration``.\r\n+The value you assign should match the relative or absolute path to the phinx.yml (or alternative) file.\r\n+\r\n+.. code-block:: php\r\n+\r\n+    $phinx->setOption('configuration', '/var/www/phinx.yml');\r\n+\r\n+.. note::\r\n+\r\n+    The location may be relative to the webroot if you use an MVC framework.\r\n+    Using ``__DIR__`` for relative paths or an absolute path is recommended.\r\n+\r\n+The default value if left blank is: ``./phinx.yml``.\r\n+\r\n+Configuring Parser Information\r\n+-------------------------------\r\n+\r\n+Setting the Parser Information is done using the option name ``parser``.\r\n+The value you assign should match the file format of the Configuration File.\r\n+\r\n+Possible values are:\r\n+\r\n+* yaml (.yml files)\r\n+* php (.php files)\r\n+* json (.json files)\r\n+\r\n+.. code-block:: php\r\n+\r\n+    $phinx->setOption('parser', 'yaml');\r\n+\r\n+.. note::\r\n+\r\n+    If left blank, the value is assumed based on the Configuration File's file extension as per the list above.\r\n+\r\n+Migrating\r\n+----------\r\n+\r\n+This command will run the same command as ``phinx migrate``.\r\n+\r\n+.. code-block:: php\r\n+\r\n+    $phinx->getMigrate($env, $target);\r","path":"docs/code-usage.rst","position":124,"original_position":124,"commit_id":"e6edf7e91a5ed1271a7c0eb9ca6874c89f067a6f","original_commit_id":"ec6075004c08fcea2a41a921d2a6af44b82e4fcb","user":{"login":"alexbowers","id":842974,"avatar_url":"https://avatars.githubusercontent.com/u/842974?v=3","gravatar_id":"","url":"https://api.github.com/users/alexbowers","html_url":"https://github.com/alexbowers","followers_url":"https://api.github.com/users/alexbowers/followers","following_url":"https://api.github.com/users/alexbowers/following{/other_user}","gists_url":"https://api.github.com/users/alexbowers/gists{/gist_id}","starred_url":"https://api.github.com/users/alexbowers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexbowers/subscriptions","organizations_url":"https://api.github.com/users/alexbowers/orgs","repos_url":"https://api.github.com/users/alexbowers/repos","events_url":"https://api.github.com/users/alexbowers/events{/privacy}","received_events_url":"https://api.github.com/users/alexbowers/received_events","type":"User","site_admin":false},"body":"I haven't had chance to start yet. If you can make it a branch I may have time to contribute a bit to it tonight, but i've started on a PoC for the company I work for.","created_at":"2015-01-10T19:19:54Z","updated_at":"2015-01-10T19:19:54Z","html_url":"https://github.com/robmorgan/phinx/pull/440#discussion_r22761304","pull_request_url":"https://api.github.com/repos/robmorgan/phinx/pulls/440","_links":{"self":{"href":"https://api.github.com/repos/robmorgan/phinx/pulls/comments/22761304"},"html":{"href":"https://github.com/robmorgan/phinx/pull/440#discussion_r22761304"},"pull_request":{"href":"https://api.github.com/repos/robmorgan/phinx/pulls/440"}}},"pull_request":{"url":"https://api.github.com/repos/robmorgan/phinx/pulls/440","id":27067362,"html_url":"https://github.com/robmorgan/phinx/pull/440","diff_url":"https://github.com/robmorgan/phinx/pull/440.diff","patch_url":"https://github.com/robmorgan/phinx/pull/440.patch","issue_url":"https://api.github.com/repos/robmorgan/phinx/issues/440","number":440,"state":"open","locked":false,"title":"Documentation for Phinx via Code added","user":{"login":"alexbowers","id":842974,"avatar_url":"https://avatars.githubusercontent.com/u/842974?v=3","gravatar_id":"","url":"https://api.github.com/users/alexbowers","html_url":"https://github.com/alexbowers","followers_url":"https://api.github.com/users/alexbowers/followers","following_url":"https://api.github.com/users/alexbowers/following{/other_user}","gists_url":"https://api.github.com/users/alexbowers/gists{/gist_id}","starred_url":"https://api.github.com/users/alexbowers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexbowers/subscriptions","organizations_url":"https://api.github.com/users/alexbowers/orgs","repos_url":"https://api.github.com/users/alexbowers/repos","events_url":"https://api.github.com/users/alexbowers/events{/privacy}","received_events_url":"https://api.github.com/users/alexbowers/received_events","type":"User","site_admin":false},"body":"Documentation Added for calling Phinx via code.","created_at":"2015-01-08T22:59:11Z","updated_at":"2015-01-10T19:19:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"65314dd0505bb8a65cd82568503f5f0eb75d04f9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/robmorgan/phinx/pulls/440/commits","review_comments_url":"https://api.github.com/repos/robmorgan/phinx/pulls/440/comments","review_comment_url":"https://api.github.com/repos/robmorgan/phinx/pulls/comments/{number}","comments_url":"https://api.github.com/repos/robmorgan/phinx/issues/440/comments","statuses_url":"https://api.github.com/repos/robmorgan/phinx/statuses/e6edf7e91a5ed1271a7c0eb9ca6874c89f067a6f","head":{"label":"alexbowers:0.4.x-dev","ref":"0.4.x-dev","sha":"e6edf7e91a5ed1271a7c0eb9ca6874c89f067a6f","user":{"login":"alexbowers","id":842974,"avatar_url":"https://avatars.githubusercontent.com/u/842974?v=3","gravatar_id":"","url":"https://api.github.com/users/alexbowers","html_url":"https://github.com/alexbowers","followers_url":"https://api.github.com/users/alexbowers/followers","following_url":"https://api.github.com/users/alexbowers/following{/other_user}","gists_url":"https://api.github.com/users/alexbowers/gists{/gist_id}","starred_url":"https://api.github.com/users/alexbowers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexbowers/subscriptions","organizations_url":"https://api.github.com/users/alexbowers/orgs","repos_url":"https://api.github.com/users/alexbowers/repos","events_url":"https://api.github.com/users/alexbowers/events{/privacy}","received_events_url":"https://api.github.com/users/alexbowers/received_events","type":"User","site_admin":false},"repo":{"id":28990285,"name":"phinx","full_name":"alexbowers/phinx","owner":{"login":"alexbowers","id":842974,"avatar_url":"https://avatars.githubusercontent.com/u/842974?v=3","gravatar_id":"","url":"https://api.github.com/users/alexbowers","html_url":"https://github.com/alexbowers","followers_url":"https://api.github.com/users/alexbowers/followers","following_url":"https://api.github.com/users/alexbowers/following{/other_user}","gists_url":"https://api.github.com/users/alexbowers/gists{/gist_id}","starred_url":"https://api.github.com/users/alexbowers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexbowers/subscriptions","organizations_url":"https://api.github.com/users/alexbowers/orgs","repos_url":"https://api.github.com/users/alexbowers/repos","events_url":"https://api.github.com/users/alexbowers/events{/privacy}","received_events_url":"https://api.github.com/users/alexbowers/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alexbowers/phinx","description":"PHP Database Migrations for Everyone","fork":true,"url":"https://api.github.com/repos/alexbowers/phinx","forks_url":"https://api.github.com/repos/alexbowers/phinx/forks","keys_url":"https://api.github.com/repos/alexbowers/phinx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alexbowers/phinx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alexbowers/phinx/teams","hooks_url":"https://api.github.com/repos/alexbowers/phinx/hooks","issue_events_url":"https://api.github.com/repos/alexbowers/phinx/issues/events{/number}","events_url":"https://api.github.com/repos/alexbowers/phinx/events","assignees_url":"https://api.github.com/repos/alexbowers/phinx/assignees{/user}","branches_url":"https://api.github.com/repos/alexbowers/phinx/branches{/branch}","tags_url":"https://api.github.com/repos/alexbowers/phinx/tags","blobs_url":"https://api.github.com/repos/alexbowers/phinx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alexbowers/phinx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alexbowers/phinx/git/refs{/sha}","trees_url":"https://api.github.com/repos/alexbowers/phinx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alexbowers/phinx/statuses/{sha}","languages_url":"https://api.github.com/repos/alexbowers/phinx/languages","stargazers_url":"https://api.github.com/repos/alexbowers/phinx/stargazers","contributors_url":"https://api.github.com/repos/alexbowers/phinx/contributors","subscribers_url":"https://api.github.com/repos/alexbowers/phinx/subscribers","subscription_url":"https://api.github.com/repos/alexbowers/phinx/subscription","commits_url":"https://api.github.com/repos/alexbowers/phinx/commits{/sha}","git_commits_url":"https://api.github.com/repos/alexbowers/phinx/git/commits{/sha}","comments_url":"https://api.github.com/repos/alexbowers/phinx/comments{/number}","issue_comment_url":"https://api.github.com/repos/alexbowers/phinx/issues/comments/{number}","contents_url":"https://api.github.com/repos/alexbowers/phinx/contents/{+path}","compare_url":"https://api.github.com/repos/alexbowers/phinx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alexbowers/phinx/merges","archive_url":"https://api.github.com/repos/alexbowers/phinx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alexbowers/phinx/downloads","issues_url":"https://api.github.com/repos/alexbowers/phinx/issues{/number}","pulls_url":"https://api.github.com/repos/alexbowers/phinx/pulls{/number}","milestones_url":"https://api.github.com/repos/alexbowers/phinx/milestones{/number}","notifications_url":"https://api.github.com/repos/alexbowers/phinx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alexbowers/phinx/labels{/name}","releases_url":"https://api.github.com/repos/alexbowers/phinx/releases{/id}","created_at":"2015-01-08T22:54:48Z","updated_at":"2015-01-09T00:07:24Z","pushed_at":"2015-01-09T22:01:13Z","git_url":"git://github.com/alexbowers/phinx.git","ssh_url":"git@github.com:alexbowers/phinx.git","clone_url":"https://github.com/alexbowers/phinx.git","svn_url":"https://github.com/alexbowers/phinx","homepage":"https://phinx.org","size":6314,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"0.4.x-dev"}},"base":{"label":"robmorgan:0.4.x-dev","ref":"0.4.x-dev","sha":"9d30b9045be31cb1fde66b19237275238ced77b6","user":{"login":"robmorgan","id":178939,"avatar_url":"https://avatars.githubusercontent.com/u/178939?v=3","gravatar_id":"","url":"https://api.github.com/users/robmorgan","html_url":"https://github.com/robmorgan","followers_url":"https://api.github.com/users/robmorgan/followers","following_url":"https://api.github.com/users/robmorgan/following{/other_user}","gists_url":"https://api.github.com/users/robmorgan/gists{/gist_id}","starred_url":"https://api.github.com/users/robmorgan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robmorgan/subscriptions","organizations_url":"https://api.github.com/users/robmorgan/orgs","repos_url":"https://api.github.com/users/robmorgan/repos","events_url":"https://api.github.com/users/robmorgan/events{/privacy}","received_events_url":"https://api.github.com/users/robmorgan/received_events","type":"User","site_admin":false},"repo":{"id":3055234,"name":"phinx","full_name":"robmorgan/phinx","owner":{"login":"robmorgan","id":178939,"avatar_url":"https://avatars.githubusercontent.com/u/178939?v=3","gravatar_id":"","url":"https://api.github.com/users/robmorgan","html_url":"https://github.com/robmorgan","followers_url":"https://api.github.com/users/robmorgan/followers","following_url":"https://api.github.com/users/robmorgan/following{/other_user}","gists_url":"https://api.github.com/users/robmorgan/gists{/gist_id}","starred_url":"https://api.github.com/users/robmorgan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robmorgan/subscriptions","organizations_url":"https://api.github.com/users/robmorgan/orgs","repos_url":"https://api.github.com/users/robmorgan/repos","events_url":"https://api.github.com/users/robmorgan/events{/privacy}","received_events_url":"https://api.github.com/users/robmorgan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/robmorgan/phinx","description":"PHP Database Migrations for Everyone","fork":false,"url":"https://api.github.com/repos/robmorgan/phinx","forks_url":"https://api.github.com/repos/robmorgan/phinx/forks","keys_url":"https://api.github.com/repos/robmorgan/phinx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/robmorgan/phinx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/robmorgan/phinx/teams","hooks_url":"https://api.github.com/repos/robmorgan/phinx/hooks","issue_events_url":"https://api.github.com/repos/robmorgan/phinx/issues/events{/number}","events_url":"https://api.github.com/repos/robmorgan/phinx/events","assignees_url":"https://api.github.com/repos/robmorgan/phinx/assignees{/user}","branches_url":"https://api.github.com/repos/robmorgan/phinx/branches{/branch}","tags_url":"https://api.github.com/repos/robmorgan/phinx/tags","blobs_url":"https://api.github.com/repos/robmorgan/phinx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/robmorgan/phinx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/robmorgan/phinx/git/refs{/sha}","trees_url":"https://api.github.com/repos/robmorgan/phinx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/robmorgan/phinx/statuses/{sha}","languages_url":"https://api.github.com/repos/robmorgan/phinx/languages","stargazers_url":"https://api.github.com/repos/robmorgan/phinx/stargazers","contributors_url":"https://api.github.com/repos/robmorgan/phinx/contributors","subscribers_url":"https://api.github.com/repos/robmorgan/phinx/subscribers","subscription_url":"https://api.github.com/repos/robmorgan/phinx/subscription","commits_url":"https://api.github.com/repos/robmorgan/phinx/commits{/sha}","git_commits_url":"https://api.github.com/repos/robmorgan/phinx/git/commits{/sha}","comments_url":"https://api.github.com/repos/robmorgan/phinx/comments{/number}","issue_comment_url":"https://api.github.com/repos/robmorgan/phinx/issues/comments/{number}","contents_url":"https://api.github.com/repos/robmorgan/phinx/contents/{+path}","compare_url":"https://api.github.com/repos/robmorgan/phinx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/robmorgan/phinx/merges","archive_url":"https://api.github.com/repos/robmorgan/phinx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/robmorgan/phinx/downloads","issues_url":"https://api.github.com/repos/robmorgan/phinx/issues{/number}","pulls_url":"https://api.github.com/repos/robmorgan/phinx/pulls{/number}","milestones_url":"https://api.github.com/repos/robmorgan/phinx/milestones{/number}","notifications_url":"https://api.github.com/repos/robmorgan/phinx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/robmorgan/phinx/labels{/name}","releases_url":"https://api.github.com/repos/robmorgan/phinx/releases{/id}","created_at":"2011-12-27T06:49:45Z","updated_at":"2015-01-10T17:46:12Z","pushed_at":"2015-01-10T17:46:10Z","git_url":"git://github.com/robmorgan/phinx.git","ssh_url":"git@github.com:robmorgan/phinx.git","clone_url":"https://github.com/robmorgan/phinx.git","svn_url":"https://github.com/robmorgan/phinx","homepage":"https://phinx.org","size":6314,"stargazers_count":1151,"watchers_count":1151,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":259,"mirror_url":null,"open_issues_count":102,"forks":259,"open_issues":102,"watchers":1151,"default_branch":"0.4.x-dev"}},"_links":{"self":{"href":"https://api.github.com/repos/robmorgan/phinx/pulls/440"},"html":{"href":"https://github.com/robmorgan/phinx/pull/440"},"issue":{"href":"https://api.github.com/repos/robmorgan/phinx/issues/440"},"comments":{"href":"https://api.github.com/repos/robmorgan/phinx/issues/440/comments"},"review_comments":{"href":"https://api.github.com/repos/robmorgan/phinx/pulls/440/comments"},"review_comment":{"href":"https://api.github.com/repos/robmorgan/phinx/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/robmorgan/phinx/pulls/440/commits"},"statuses":{"href":"https://api.github.com/repos/robmorgan/phinx/statuses/e6edf7e91a5ed1271a7c0eb9ca6874c89f067a6f"}}}}