Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
pifeifei committed Sep 2, 2022
0 parents commit a25380f
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.yml]
indent_size = 2
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
.idea/
.vscode/
21 changes: 21 additions & 0 deletions LICENSES
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Pi Fei-fei

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Brew PHP ln

[中文文档](README_zh.md)
[English](README.md)

Brew PHP ln is a simple script for creating soft connections.

## Caveats

For users of OSX only who have installed PHP via Homebrew and for PHP version 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0 and 8.1 only.

## Install

```shell
curl -o brew-php-ln https://github.com/pifeifei/brew-php-ln/raw/main/phpln.sh && chmod +x brew-php-ln
curl -o brew-php-ln https://gitee.com/pifeifei/brew-php-ln/raw/main/phpln.sh && chmod +x brew-php-ln
# git clone https://github.com/pifeifei/brew-php-ln.git

# brew install(TODO)
brew install brew-php-ln
```

Where 8.0 exists, please replace with syntax of 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0 or 8.1 depending on which version is required.

```shell
brew-php-ln 8.0 # php80 and other
php80 -v
composer80 -V

# major version
brew-php-ln 8.0 -m # php8 and other
php8 -v
composer8 -V
```

Note: There is no need to recreate soft link for minor version upgrade.
35 changes: 35 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Brew PHP ln

[中文文档](README_zh.md)
[English](README.md)

Brew PHP ln 是一个创建软连接的简单脚本。

## 警告(暂定)

仅适用于通过 Homebrew 安装 PHP 的 OSX 用户,并且仅适用于 PHP 版本 5.6、7.0、7.1、7.2、7.3、7.4、 8.0 和 8.1。

## 安装

```shell
curl -o brew-php-ln https://github.com/pifeifei/brew-php-ln/raw/main/phpln.sh && chmod +x brew-php-ln
curl -o brew-php-ln https://gitee.com/pifeifei/brew-php-ln/raw/main/phpln.sh && chmod +x brew-php-ln
# git clone https://github.com/pifeifei/brew-php-ln.git

# brew 安装(TODO)
brew install brew-php-ln
```

如果存在 5.6,请根据所需的版本,替换为 5.6、7.0、7.1、7.2、7.3、7.4、 8.0 和 8.1 的语法。

```shell
brew-php-ln 8.0 # php80 及其相关
php80 -v
composer80 -V

brew-php-ln 8.0 -m # php8 及其相关
php8 -v
composer8 -V
```

PS: 小版本升级不用重新创建软连接。
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
87 changes: 87 additions & 0 deletions phpln.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
# Creator: Pi Feifei
# Email: [email protected]
# weibo: @kis龍

# brew_prefix=$(brew --prefix | sed 's#/#\\\/#g')
brew_prefix=$(brew --prefix)

brew_array=("5.6" "7.0" "7.1" "7.2" "7.3" "7.4" "8.0" "8.1")
php_array=("[email protected]" "[email protected]" "[email protected]" "[email protected]" "[email protected]" "[email protected]" "[email protected]" "[email protected]")
php_installed_array=()
php_opt_path="$brew_prefix/opt/"
php_version="php@$1"
php_major=0

# Has the user submitted a version required
if [[ -z "$1" ]]; then
echo "usage: brew-php-ln version [-m]"
echo
echo " version one of:" ${brew_array[@]}
echo " -m|major major version php8, or php81"
echo
exit
fi

# Check for skip & change flag
while [[ $# -gt 0 ]]; do
key="$1"
case "$key" in
# This is a flag type option. Will catch either -s or --skip
-m | -major)
if [[ "${1#*=}" == "-m" ]]; then
php_major=1
fi
;;

esac
# Shift after checking all the cases to get the next option
shift
done

# What versions of php are installed via brew
for i in ${php_array[*]}; do
if [[ -n "$(brew ls --versions "$i")" ]]; then
php_installed_array+=("$i")
if [[ $1 == ${i:4:3} ]]; then
php_major=1
fi
fi
done

if [[ 1 == $php_major ]]; then
ln_version=${php_version:4:1}
else
ln_version="${php_version:4:1}${php_version:6:1}"
fi

# Check that the requested version is supported
if [[ " ${php_array[*]} " == *"$php_version"* ]]; then
# Check that the requested version is installed
if [[ " ${php_installed_array[*]} " == *"$php_version"* ]]; then
echo "ln to $php_version"
echo "ln your shell"

ln -sf "$php_opt_path$php_version/bin/php" "$brew_prefix/bin/php${ln_version}"
ln -sf "$php_opt_path$php_version/bin/php-cgi" "$brew_prefix/bin/php-cgi${ln_version}"
ln -sf "$php_opt_path$php_version/bin/php-config" "$brew_prefix/bin/php-config${ln_version}"
ln -sf "$php_opt_path$php_version/bin/phpdbg" "$brew_prefix/bin/phpdbg${ln_version}"
ln -sf "$php_opt_path$php_version/bin/phpize" "$brew_prefix/bin/phpize${ln_version}"
# composer
cat <<EOF >"$brew_prefix/bin/composer${ln_version}"
#!/bin/bash
$brew_prefix/bin/php${ln_version} $php_opt_path/composer/bin/composer \$*
EOF
chmod +x "$brew_prefix/bin/composer${ln_version}"

echo
echo " php${ln_version} -v"
echo " php-config${ln_version} --php-binary"
echo " composer${ln_version} -V"
echo
fi

echo "All done!"
else
echo "Unknown version of PHP. PHP Switcher can only handle arguments of:" ${brew_array[@]}
fi

0 comments on commit a25380f

Please sign in to comment.