{"action":"created","comment":{"url":"https://api.github.com/repos/laravel/spark-installer/pulls/comments/48447660","id":48447660,"diff_hunk":"@@ -57,4 +69,130 @@ private function findComposer()\n \n         return 'composer';\n     }\n+\n+    /**\n+     * Get the version that should be downloaded.\n+     *\n+     * @param  \\Symfony\\Component\\Console\\Input\\InputInterface\n+     * @return string\n+     */\n+    protected function getVersion($input)\n+    {\n+        if ($input->getOption('dev')) {\n+            return 'dev-master';\n+        }\n+\n+        // no specific version, composer will get latest stable\n+        return '';\n+    }\n+\n+    /**\n+     * Check if SparkServiceProvider is already in the framework providers array\n+     *\n+     * @param $appConfig\n+     * @return bool\n+     */\n+    protected function sparkServiceProviderAlreadyExists($appConfig)\n+    {\n+        $provider = 'Laravel\\Spark\\Providers\\SparkServiceProvider';\n+\n+        return (isset($appConfig['providers']) && in_array($provider, $appConfig['providers']));\n+    }\n+\n+    /**\n+     * Update the existing app config source code with the Spark service provider source code\n+     *\n+     * @param $afterArrayItem\n+     * @return bool\n+     */\n+    protected function addSparkServiceProviderToAppConfig($afterArrayItem)\n+    {\n+        $appConfigFilePath = getcwd().'/config/app.php';\n+\n+        $appConfigString = file_get_contents($appConfigFilePath);\n+\n+        // determine the location to split the file string\n+        $splitPosition = $this->findEndOfSourceCodeArrayContaining($appConfigString, $afterArrayItem);\n+\n+        // split the file, so we can inset the spark service provider\n+        $startOfConfigFile = substr($appConfigString, 0, $splitPosition);\n+        $endOfConfigFile  = substr($appConfigString, $splitPosition);\n+\n+        // make sure the current last element has a comma\n+        if(strpos(substr($startOfConfigFile, strpos($startOfConfigFile, $afterArrayItem)), ',') === false)\n+        {\n+            $startOfConfigFile = rtrim($startOfConfigFile) . \", \\n\";\n+        }\n+\n+        $sparkProviderSource = $this->sourcecodeToInsert();\n+\n+        $finalConfigFileSource = $startOfConfigFile . $sparkProviderSource . $endOfConfigFile;\n+\n+        return (bool) file_put_contents($appConfigFilePath, $finalConfigFileSource);\n+    }\n+\n+    /**\n+     * Find the location of the character in the source code string which\n+     * is before the close of the array containing the search item.\n+     *\n+     * This search will work no matter how the source code is spaced or\n+     * where new lines are placed, provided it is still considered\n+     * valid and parsable by the php interpreter\n+     *\n+     * @param $appConfigString\n+     * @param $searchItem\n+     * @return bool|int\n+     */\n+    protected function findEndOfSourceCodeArrayContaining(&$appConfigString, $searchItem)\n+    {\n+        $appConfigStrings = explode(\"\\n\", $appConfigString);\n+\n+        // find the line with the item we are looking for, then append the found line\n+        // and all lines until the close of the array is found (inclusive)\n+        // to an array\n+        $checkNextLines = false;\n+        $lineContentAfterFoundItems = [];\n+        foreach($appConfigStrings as &$appConfigLine)\n+        {\n+            if (strpos($appConfigLine, $searchItem) !== false) {\n+                $checkNextLines = true;\n+            }\n+\n+            if($checkNextLines)\n+            {\n+                $lineContentAfterFoundItems[] = $appConfigLine;\n+                if (strpos($appConfigLine, ']') !== false) {\n+                    break;\n+                }\n+            }\n+        }\n+\n+        // check the last item in the array contains the closing ] of an array\n+        $closingOfArrayLine = array_pop($lineContentAfterFoundItems);\n+        if (($arrayClosePos = strpos($closingOfArrayLine, ']')) !== false)\n+        {\n+            $closingOfArrayLine = substr($closingOfArrayLine, 0, $arrayClosePos);\n+            $lineContentAfterFoundItems[] = rtrim($closingOfArrayLine, \" \\t\");\n+        }\n+\n+        $stringToFind = implode(\"\\n\", $lineContentAfterFoundItems);\n+\n+        return strpos($appConfigString, $stringToFind) + strlen($stringToFind);\n+    }\n+\n+    /**\n+     * The raw sourcecode string to inset into the app config file\n+     *\n+     * @return string\n+     */\n+    protected function sourcecodeToInsert()\n+    {\n+        $sparkProviderSource = PHP_EOL;","path":"src/Console/InstallCommand.php","position":166,"original_position":166,"commit_id":"03145fd9376dfb32e4e784adca3c578cf4461291","original_commit_id":"03145fd9376dfb32e4e784adca3c578cf4461291","user":{"login":"GrahamCampbell","id":2829600,"avatar_url":"https://avatars.githubusercontent.com/u/2829600?v=3","gravatar_id":"","url":"https://api.github.com/users/GrahamCampbell","html_url":"https://github.com/GrahamCampbell","followers_url":"https://api.github.com/users/GrahamCampbell/followers","following_url":"https://api.github.com/users/GrahamCampbell/following{/other_user}","gists_url":"https://api.github.com/users/GrahamCampbell/gists{/gist_id}","starred_url":"https://api.github.com/users/GrahamCampbell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GrahamCampbell/subscriptions","organizations_url":"https://api.github.com/users/GrahamCampbell/orgs","repos_url":"https://api.github.com/users/GrahamCampbell/repos","events_url":"https://api.github.com/users/GrahamCampbell/events{/privacy}","received_events_url":"https://api.github.com/users/GrahamCampbell/received_events","type":"User","site_admin":false},"body":"You should use `\\n`.","created_at":"2015-12-26T15:03:14Z","updated_at":"2015-12-26T15:03:14Z","html_url":"https://github.com/laravel/spark-installer/pull/5#discussion_r48447660","pull_request_url":"https://api.github.com/repos/laravel/spark-installer/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/laravel/spark-installer/pulls/comments/48447660"},"html":{"href":"https://github.com/laravel/spark-installer/pull/5#discussion_r48447660"},"pull_request":{"href":"https://api.github.com/repos/laravel/spark-installer/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/laravel/spark-installer/pulls/5","id":54598700,"html_url":"https://github.com/laravel/spark-installer/pull/5","diff_url":"https://github.com/laravel/spark-installer/pull/5.diff","patch_url":"https://github.com/laravel/spark-installer/pull/5.patch","issue_url":"https://api.github.com/repos/laravel/spark-installer/issues/5","number":5,"state":"open","locked":false,"title":"Remove the need to include a copy of the default app config to add a provider","user":{"login":"Lidbetter","id":6525616,"avatar_url":"https://avatars.githubusercontent.com/u/6525616?v=3","gravatar_id":"","url":"https://api.github.com/users/Lidbetter","html_url":"https://github.com/Lidbetter","followers_url":"https://api.github.com/users/Lidbetter/followers","following_url":"https://api.github.com/users/Lidbetter/following{/other_user}","gists_url":"https://api.github.com/users/Lidbetter/gists{/gist_id}","starred_url":"https://api.github.com/users/Lidbetter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lidbetter/subscriptions","organizations_url":"https://api.github.com/users/Lidbetter/orgs","repos_url":"https://api.github.com/users/Lidbetter/repos","events_url":"https://api.github.com/users/Lidbetter/events{/privacy}","received_events_url":"https://api.github.com/users/Lidbetter/received_events","type":"User","site_admin":false},"body":"This is an attempt at inserting the new providers into the providers array (in app config) rather than replace the whole thing.\r\n\r\nThis method of inserting providers into the config file should work (with some minor tweaking) for any laravel package which includes an install command.\r\n\r\nGeneral flow is as follows:\r\n1) get the interpreted config array\r\n2) check the provider needs to be added\r\n3) using the interpreted array, get the last key of the providers array\r\n4) get the file contents of the config file, and insert the new provider after the existing last key of the provider array\r\n\r\nCurrently it relies on finding the end of the array using short array syntax (but should be easy to support `array();`, if desired).\r\n\r\n___\r\n__Why?__\r\n\r\n1) People update their app config files, installing spark should not undo that!\r\n2) The spark installer does not need a version bump if the framework app config changes which providers are loaded by default","created_at":"2015-12-26T07:48:14Z","updated_at":"2015-12-26T15:03:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b42cb569ea8fcea6f57d38f9d4b48497bad8582d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/laravel/spark-installer/pulls/5/commits","review_comments_url":"https://api.github.com/repos/laravel/spark-installer/pulls/5/comments","review_comment_url":"https://api.github.com/repos/laravel/spark-installer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/laravel/spark-installer/issues/5/comments","statuses_url":"https://api.github.com/repos/laravel/spark-installer/statuses/03145fd9376dfb32e4e784adca3c578cf4461291","head":{"label":"Lidbetter:master","ref":"master","sha":"03145fd9376dfb32e4e784adca3c578cf4461291","user":{"login":"Lidbetter","id":6525616,"avatar_url":"https://avatars.githubusercontent.com/u/6525616?v=3","gravatar_id":"","url":"https://api.github.com/users/Lidbetter","html_url":"https://github.com/Lidbetter","followers_url":"https://api.github.com/users/Lidbetter/followers","following_url":"https://api.github.com/users/Lidbetter/following{/other_user}","gists_url":"https://api.github.com/users/Lidbetter/gists{/gist_id}","starred_url":"https://api.github.com/users/Lidbetter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lidbetter/subscriptions","organizations_url":"https://api.github.com/users/Lidbetter/orgs","repos_url":"https://api.github.com/users/Lidbetter/repos","events_url":"https://api.github.com/users/Lidbetter/events{/privacy}","received_events_url":"https://api.github.com/users/Lidbetter/received_events","type":"User","site_admin":false},"repo":{"id":48602616,"name":"spark-installer","full_name":"Lidbetter/spark-installer","owner":{"login":"Lidbetter","id":6525616,"avatar_url":"https://avatars.githubusercontent.com/u/6525616?v=3","gravatar_id":"","url":"https://api.github.com/users/Lidbetter","html_url":"https://github.com/Lidbetter","followers_url":"https://api.github.com/users/Lidbetter/followers","following_url":"https://api.github.com/users/Lidbetter/following{/other_user}","gists_url":"https://api.github.com/users/Lidbetter/gists{/gist_id}","starred_url":"https://api.github.com/users/Lidbetter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lidbetter/subscriptions","organizations_url":"https://api.github.com/users/Lidbetter/orgs","repos_url":"https://api.github.com/users/Lidbetter/repos","events_url":"https://api.github.com/users/Lidbetter/events{/privacy}","received_events_url":"https://api.github.com/users/Lidbetter/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Lidbetter/spark-installer","description":"","fork":true,"url":"https://api.github.com/repos/Lidbetter/spark-installer","forks_url":"https://api.github.com/repos/Lidbetter/spark-installer/forks","keys_url":"https://api.github.com/repos/Lidbetter/spark-installer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Lidbetter/spark-installer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Lidbetter/spark-installer/teams","hooks_url":"https://api.github.com/repos/Lidbetter/spark-installer/hooks","issue_events_url":"https://api.github.com/repos/Lidbetter/spark-installer/issues/events{/number}","events_url":"https://api.github.com/repos/Lidbetter/spark-installer/events","assignees_url":"https://api.github.com/repos/Lidbetter/spark-installer/assignees{/user}","branches_url":"https://api.github.com/repos/Lidbetter/spark-installer/branches{/branch}","tags_url":"https://api.github.com/repos/Lidbetter/spark-installer/tags","blobs_url":"https://api.github.com/repos/Lidbetter/spark-installer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Lidbetter/spark-installer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Lidbetter/spark-installer/git/refs{/sha}","trees_url":"https://api.github.com/repos/Lidbetter/spark-installer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Lidbetter/spark-installer/statuses/{sha}","languages_url":"https://api.github.com/repos/Lidbetter/spark-installer/languages","stargazers_url":"https://api.github.com/repos/Lidbetter/spark-installer/stargazers","contributors_url":"https://api.github.com/repos/Lidbetter/spark-installer/contributors","subscribers_url":"https://api.github.com/repos/Lidbetter/spark-installer/subscribers","subscription_url":"https://api.github.com/repos/Lidbetter/spark-installer/subscription","commits_url":"https://api.github.com/repos/Lidbetter/spark-installer/commits{/sha}","git_commits_url":"https://api.github.com/repos/Lidbetter/spark-installer/git/commits{/sha}","comments_url":"https://api.github.com/repos/Lidbetter/spark-installer/comments{/number}","issue_comment_url":"https://api.github.com/repos/Lidbetter/spark-installer/issues/comments{/number}","contents_url":"https://api.github.com/repos/Lidbetter/spark-installer/contents/{+path}","compare_url":"https://api.github.com/repos/Lidbetter/spark-installer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Lidbetter/spark-installer/merges","archive_url":"https://api.github.com/repos/Lidbetter/spark-installer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Lidbetter/spark-installer/downloads","issues_url":"https://api.github.com/repos/Lidbetter/spark-installer/issues{/number}","pulls_url":"https://api.github.com/repos/Lidbetter/spark-installer/pulls{/number}","milestones_url":"https://api.github.com/repos/Lidbetter/spark-installer/milestones{/number}","notifications_url":"https://api.github.com/repos/Lidbetter/spark-installer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Lidbetter/spark-installer/labels{/name}","releases_url":"https://api.github.com/repos/Lidbetter/spark-installer/releases{/id}","created_at":"2015-12-26T07:08:24Z","updated_at":"2015-12-26T07:08:26Z","pushed_at":"2015-12-26T07:19:50Z","git_url":"git://github.com/Lidbetter/spark-installer.git","ssh_url":"git@github.com:Lidbetter/spark-installer.git","clone_url":"https://github.com/Lidbetter/spark-installer.git","svn_url":"https://github.com/Lidbetter/spark-installer","homepage":null,"size":12,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"laravel:master","ref":"master","sha":"bdf3bff816bc240a08a1ec6b73df31c4f05fd792","user":{"login":"laravel","id":958072,"avatar_url":"https://avatars.githubusercontent.com/u/958072?v=3","gravatar_id":"","url":"https://api.github.com/users/laravel","html_url":"https://github.com/laravel","followers_url":"https://api.github.com/users/laravel/followers","following_url":"https://api.github.com/users/laravel/following{/other_user}","gists_url":"https://api.github.com/users/laravel/gists{/gist_id}","starred_url":"https://api.github.com/users/laravel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laravel/subscriptions","organizations_url":"https://api.github.com/users/laravel/orgs","repos_url":"https://api.github.com/users/laravel/repos","events_url":"https://api.github.com/users/laravel/events{/privacy}","received_events_url":"https://api.github.com/users/laravel/received_events","type":"Organization","site_admin":false},"repo":{"id":42457701,"name":"spark-installer","full_name":"laravel/spark-installer","owner":{"login":"laravel","id":958072,"avatar_url":"https://avatars.githubusercontent.com/u/958072?v=3","gravatar_id":"","url":"https://api.github.com/users/laravel","html_url":"https://github.com/laravel","followers_url":"https://api.github.com/users/laravel/followers","following_url":"https://api.github.com/users/laravel/following{/other_user}","gists_url":"https://api.github.com/users/laravel/gists{/gist_id}","starred_url":"https://api.github.com/users/laravel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laravel/subscriptions","organizations_url":"https://api.github.com/users/laravel/orgs","repos_url":"https://api.github.com/users/laravel/repos","events_url":"https://api.github.com/users/laravel/events{/privacy}","received_events_url":"https://api.github.com/users/laravel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/laravel/spark-installer","description":"","fork":false,"url":"https://api.github.com/repos/laravel/spark-installer","forks_url":"https://api.github.com/repos/laravel/spark-installer/forks","keys_url":"https://api.github.com/repos/laravel/spark-installer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/laravel/spark-installer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/laravel/spark-installer/teams","hooks_url":"https://api.github.com/repos/laravel/spark-installer/hooks","issue_events_url":"https://api.github.com/repos/laravel/spark-installer/issues/events{/number}","events_url":"https://api.github.com/repos/laravel/spark-installer/events","assignees_url":"https://api.github.com/repos/laravel/spark-installer/assignees{/user}","branches_url":"https://api.github.com/repos/laravel/spark-installer/branches{/branch}","tags_url":"https://api.github.com/repos/laravel/spark-installer/tags","blobs_url":"https://api.github.com/repos/laravel/spark-installer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/laravel/spark-installer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/laravel/spark-installer/git/refs{/sha}","trees_url":"https://api.github.com/repos/laravel/spark-installer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/laravel/spark-installer/statuses/{sha}","languages_url":"https://api.github.com/repos/laravel/spark-installer/languages","stargazers_url":"https://api.github.com/repos/laravel/spark-installer/stargazers","contributors_url":"https://api.github.com/repos/laravel/spark-installer/contributors","subscribers_url":"https://api.github.com/repos/laravel/spark-installer/subscribers","subscription_url":"https://api.github.com/repos/laravel/spark-installer/subscription","commits_url":"https://api.github.com/repos/laravel/spark-installer/commits{/sha}","git_commits_url":"https://api.github.com/repos/laravel/spark-installer/git/commits{/sha}","comments_url":"https://api.github.com/repos/laravel/spark-installer/comments{/number}","issue_comment_url":"https://api.github.com/repos/laravel/spark-installer/issues/comments{/number}","contents_url":"https://api.github.com/repos/laravel/spark-installer/contents/{+path}","compare_url":"https://api.github.com/repos/laravel/spark-installer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/laravel/spark-installer/merges","archive_url":"https://api.github.com/repos/laravel/spark-installer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/laravel/spark-installer/downloads","issues_url":"https://api.github.com/repos/laravel/spark-installer/issues{/number}","pulls_url":"https://api.github.com/repos/laravel/spark-installer/pulls{/number}","milestones_url":"https://api.github.com/repos/laravel/spark-installer/milestones{/number}","notifications_url":"https://api.github.com/repos/laravel/spark-installer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/laravel/spark-installer/labels{/name}","releases_url":"https://api.github.com/repos/laravel/spark-installer/releases{/id}","created_at":"2015-09-14T15:34:24Z","updated_at":"2015-11-28T05:41:15Z","pushed_at":"2015-12-26T07:48:14Z","git_url":"git://github.com/laravel/spark-installer.git","ssh_url":"git@github.com:laravel/spark-installer.git","clone_url":"https://github.com/laravel/spark-installer.git","svn_url":"https://github.com/laravel/spark-installer","homepage":null,"size":9,"stargazers_count":6,"watchers_count":6,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":1,"forks":12,"open_issues":1,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/laravel/spark-installer/pulls/5"},"html":{"href":"https://github.com/laravel/spark-installer/pull/5"},"issue":{"href":"https://api.github.com/repos/laravel/spark-installer/issues/5"},"comments":{"href":"https://api.github.com/repos/laravel/spark-installer/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/laravel/spark-installer/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/laravel/spark-installer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/laravel/spark-installer/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/laravel/spark-installer/statuses/03145fd9376dfb32e4e784adca3c578cf4461291"}}}}