Introducing the PR process record of a composer package

藏色散人
Release: 2021-01-20 15:56:15
forward
1859 people have browsed it

下面由composer教程栏目带大家介绍pr一个composer包过程记录 ,希望对需要的朋友有所帮助!

Introducing the PR process record of a composer package

看到一位朋友的 enum包,感觉还不错。

因为在实际开发中 我们使用 BenSampo/laravel-enum(https://github.com/BenSampo/laravel-enum)这个包去管理枚举。

在标准化项目中(比如国际化)其实这个包挺好的。但是在小项目中,先添加枚举类,再去enums.php 中添加翻译,让人感觉很繁琐

像这样子:
Introducing the PR process record of a composer package
所以对这个注解读取“翻译”的这个包,我很感兴趣。

但是问题来了,这个包里面只能读取枚举翻译,如果我需要一个数组呢?

像这样:

AppStatus::toSelectArray()
Copy after login

我想用这个包,但是我又想用到toArray,我满足这两个条件,我在小项目中就可以操刀就干,而又不失优雅。

所以,我决定fork一份自己改一下,添加toArray 的方法

fork好了之后,在项目根目录中添加 一个packages的文件夹,在这个文件夹中,git clone github.com/liaoshengping/x-phalcon...

composer.json 中添加,本地目录

"repositories": [ { "type": "path", "url": "packages\\x-phalcon-enum" } ]
Copy after login

接下来

composer require limingxinleo/x-phalcon-enum dev-master

在vendor 会生成一份 和packages一样的 文件。这时已经映射到了 packages ,只需要修改其中的文件就可以了。

在 Enum.php 添加一个toArray 的静态方法。

public static function toArray(){ $ref = new ReflectionClass(static::class); $properties = $ref->getDefaultProperties(); $_adapter = new ReflectionAdapter(static::class); $arr = $_adapter->getAnnotationsByName('Message', $properties); return $arr; }
Copy after login

push 到 自己的master 上,创建一个 Pull Request,如图:

Introducing the PR process record of a composer package

等大佬检查代码,如果通过则合并。

这样就完成了我第一个pr
Introducing the PR process record of a composer package

The above is the detailed content of Introducing the PR process record of a composer package. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!