1.在github中创建自己的仓库,然后本地clone,初始化composer init ,在composer.json中增加autoload
"autoload": { "psr-4": { "hubo123\\test\\": "src" } }
,hubo123/test目下创建src目录,增加Hello.php文件。
<?php
namespace Hubo123\Demo;
class Hello { private $name; public function __construct( $name = 'World' ) { $this->name = $name; } public function getName() { return $this->name; } public function hello() { return 'Hello '.$this->name.'!'; } }
,然后提交到远程仓库.
2. 进入packagist官网,进行submit验证,填写仓库的地址进行check.
3.点击进入仓库,点击settings->Integrations&services->add service 搜索packagist,然后填写用户名,以及token(此处的token是packagist上的profile菜单下)。
4.项目根目录创建test.php文件,
require_once "vendor/autoload.php";
$hello = new Hubo123\Demo\Hello(); echo $hello->hello(); echo "\n"; $hiGirl = new Hubo123\Demo\Hello('My Goddess'); echo $hiGirl->hello();