github.com/symfony-cli/symfony-cli@v0.0.0-20240514161054-ece2df437dfa/local/php/composer_windows.go (about) 1 /* 2 * Copyright (c) 2021-present Fabien Potencier <fabien@symfony.com> 3 * 4 * This file is part of Symfony CLI project 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Affero General Public License as 8 * published by the Free Software Foundation, either version 3 of the 9 * License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Affero General Public License for more details. 15 * 16 * You should have received a copy of the GNU Affero General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package php 21 22 import ( 23 "github.com/mitchellh/go-homedir" 24 "os" 25 "os/exec" 26 "path/filepath" 27 ) 28 29 func findComposerSystemSpecific(extraBin string) string { 30 // Special Support for Scoop 31 scoopPaths := []string{} 32 33 if scoopPath, err := exec.LookPath("scoop"); err == nil { 34 scoopPaths = append(scoopPaths, filepath.Dir(filepath.Dir(scoopPath))) 35 } 36 37 if scoopPath := os.Getenv("SCOOP"); scoopPath == "" { 38 if homedir, err := homedir.Dir(); err != nil { 39 scoopPaths = append(scoopPaths, filepath.Join(homedir, "scoop")) 40 } 41 } 42 43 if scoopGlobalPath := os.Getenv("SCOOP_GLOBAL"); scoopGlobalPath == "" { 44 if programData := os.Getenv("PROGRAMDATA"); programData != "" { 45 scoopPaths = append(scoopPaths, filepath.Join(programData, "scoop")) 46 } 47 } 48 49 for _, path := range scoopPaths { 50 pharPath := filepath.Join(path, "apps", "composer", "current", "composer.phar") 51 d, err := os.Stat(pharPath) 52 if err != nil { 53 continue 54 } 55 if m := d.Mode(); !m.IsDir() { 56 // Yep! 57 return pharPath 58 } 59 } 60 61 return "" 62 }