github=>git=>composer Packages 使用教程

2018年12月17日14:32:05

因为要做搜索,所以需要用分词工具php的分词不借助的第三方的真的很少,

目前选择的是 http://www.phpbone.com/phpanalysis/

但是这个插件没有放上github,虽然有些同学自己搬到了github上但是都有一些封装,但是不是原生直接搬过去的

1,先注册github

创建  Create a new repository   https://github.com/new 注意要是公开,注意不要使用下划线,中划线等非字母数字,防止后面读取composer.json 时候名字不一致,可能出现加载不了

举例: https://github.com/zh7314/phpanalysis 

 2,连接github项目关联本地代码项目

 参考:https://www.cnblogs.com/ttjsndx/p/7943444.html

在本机上设置你的github的邮箱和用户名

扫描二维码关注公众号,回复: 4556068 查看本文章

git config --global user.name "用户名"
git config --global user.email "邮箱"

ssh-keygen -t rsa -C "邮箱"

 根据提示,按三次回车键,最后会生成ssh key值,并告诉你key值存放的文件的位置,找到该文件并复制ssh key

记住你存放.ssh 的位置,找到找有 id_rsa.pub  可能因为系统原因这个文件名会不同

打开你的github主页。找到Settings,

打开你的github主页。找到Settings,选择SSH and GPG keys ,再选择new SSH key,title 随意填,key值就是刚刚生成的本机 SSH KEY

打开github主页,选择 new repository,打开新建项目页面。      在新建项目页面,输入项目名称,点击下一步,复制生成项目后的项目SSH   2.打开本地仓库的git bash页面。输入 git remote add origin "项目SSH"    3.先同步github上master分支的代码,再指定上传的默认分支 git pull origin master git push -u origin master   第三步设置了本地仓库对应的是github账户上的哪一个项目,并且设置了代码上传的分支。注意github上的项目名称与本地仓库名称同级,也就是说,从github上同步代码时,只会更新项目名称下的各个文件到本地仓库中。

3,登录https://packagist.org/ 用github账号登录,然后直接点 submit  填写github的url 例如 https://github.com/zh7314/phpanalysis.git  这个是我刚弄好的

如果你github有更新代码请 update 更新

到了具体包的页面例如 https://packagist.org/packages/zh7314/phpanalysis

composer require zh7314/phpanalysis dev-master   就可以直接下载包,注意包的版本,我这边写 dev

 官方文档: https://git-scm.com/book/zh/v2

git常用命令

代码里面需要创建 新的代码包里面 composer.json,这个是必须

例:

{
    "name": "zh7314/phpanalysis",   //这个是  Packages的名称注意,这个不是repository   的名称,最好一直
    "description": "phpanalysis中文分词",
    "type": "library",
    "licence": "MIT",
    "require": {
        "php": ">=5.6.5" //php版本
    },
    "autoload": {
        "psr-4": {
            "zh7314\\": "./"  目录全部加载,也可以指定某个目录的源码
        },
        "files": [
        ]
    },
    "minimum-stability": "dev" //最小稳定版本
}

最好放一个autoloader自动加载

<?php

namespace phpspider;

/**
 * autoloader.
 */
class autoloader
{
    /**
     * Autoload root path.
     *
     * @var string
     */
    protected static $_autoload_root_path = '';

    /**
     * Set autoload root path.
     *
     * @param string $root_path
     * @return void
     */
    public static function set_root_path($root_path)
    {
        self::$_autoload_root_path = $root_path;
    }

    /**
     * Load files by namespace.
     *
     * @param string $name
     * @return boolean
     */
    public static function load_by_namespace($name)
    {
        $class_path = str_replace('\\', DIRECTORY_SEPARATOR, $name);

        if (strpos($name, 'zh7314\\') === 0) 
        {
            $class_file = __DIR__ . substr($class_path, strlen('zh7314')) . '.php';
        }
        else 
        {
            if (self::$_autoload_root_path) 
            {
                $class_file = self::$_autoload_root_path . DIRECTORY_SEPARATOR . $class_path . '.php';
            }
            if (empty($class_file) || !is_file($class_file)) 
            {
                $class_file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . "$class_path.php";
            }
        }

        if (is_file($class_file)) 
        {
            require_once($class_file);
            if (class_exists($name, false)) 
            {
                return true;
            }
        }
        return false;
    }
}

spl_autoload_register('\zh7314\autoloader::load_by_namespace');

猜你喜欢

转载自www.cnblogs.com/zx-admin/p/10131365.html